4

I started playing around with Serenity BDD and the screenplay pattern in Java. While I get the basic idea I have some trouble with applying the key concepts. Here is what I'd like to do...

My first attempt is to automate the login of a user into the application. This consists of the following:

  1. Open a specific URL.
  2. Enter user credentials and hit the submit button.
  3. Check that the user is on the "Welcome page".

I successfully implemented items 1 and 2 but I'm struggling with the check at 3.

The JUnit Test

@Test
public void shouldBeAbleToLogin() {
    user.whoCan(BrowseTheWeb.with(browser));
    user.wasAbleTo(OpenTheApplication.onTheLoginPage());
    user.attemptsTo(SubmitUserCredentials.withValues("test", "test"));
    user.should(???);
}

After having submitted the credentials the user gets redirected to the welcome page. The ??? shall indicate that I don't have a solid idea how to implement this check.

  1. Check that the new URL matches that of the welcome page.
  2. Check that a certain text is visible on the welcome page.
  3. Check that a certain element is visible on the welcome page.

I know that I would need to implement some class of Question but that's it. Could you provide me with some hint how you would do that?

Robert Strauch
  • 12,055
  • 24
  • 120
  • 192

3 Answers3

2

In the Serenity BDD you can write a Question class that:

import static net.thucydides.core.webdriver.ThucydidesWebDriverSupport.getDriver;

implements Question < Boolean >

in it would be the method:

@Override
public Boolean answeredBy(Actor actor) {

and in it you can:

    WebDriver driver = getDriver();
    String currentUrl = driver.getCurrentUrl();

and in my case I had a loop to do few more checks in case the URL gets changed.

mrGe.org
  • 25
  • 5
1

In this case, serenity-ensure could help

Ensure.thatTheCurrentPage().currentUrl()

return URL as StringEnsure that we can use build-in String method like equals, contains.. to check.

Hope this helps!

Huy Hóm Hỉnh
  • 597
  • 7
  • 18
0

you can also use waitForTextToAppear() method or waitFor(xpath) method to verify welcome page