1

I am working with Selenium WebDriver + Java and following the POM design pattern to create automated tests, one of which involves verifying successful logout of a user account from a webapp.

Does it make more sense for this verification method to be part of the page class where the logout method was called, or the page class of the new page that is navigated to? To provide more detail:

Currently, I have a homePage class where I am calling both logout() and verifyLogout(). After logout() is called, the driver navigates to a new page, and verifyLogout() works by searching the page source for the presence of a certain string. My intuition is to instead create a separate page class for this new page and call verifyLogout() from that instead, but considering that this page is not used for anything else, does this still make sense?

  • 2
    Short answer: yes, I would consider that not only a best practice, but the only practice. Each physical page should be its own page object. – Bill Hileman Oct 24 '18 at 19:29
  • Thank you for the response - this is what I figured, but just wanted some confirmation. – A. K Oct 24 '18 at 19:48
2

You are right: Upon success you go to another page, therefore, another page object.

But be careful to not add business logic on the page object. Page object are strictly to perform action and query information. The business logic, in this case, the visibility of certain objects, should be on the test - so, upon reading it, one can know what determines if the login was a success.

You would have something like this:

  • Home page:

    public HomePage logout() { this.logoutButton.click(); return new LoginPage(); }

  • Login page:

    public String getURL() {return this.driver.url();}

    public String isUserNameFormVisible() { return this.userNameForm.isVisible();}

    public String isPasswordFormVisible() { return this.passwordForm.isVisible();}

  • Test

    LoginPage loginPage = homepage.logout();

    assertEquals(loginPage.getURL(), "www....");

    assertTrue(loginPage.isUserNameFormVisible());

    assertTrue(loginPage.isPasswordFormVisible());

For other tests you can use an abstraction of the forms as a component, but the logout test should be explicit, for more precise debugging.

Sorry for the formatting, something is wrong with the multi-line code sample.

  • Thank you for the response! I will make sure to refactor my code so that the business logic resides in the test instead – A. K Oct 26 '18 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.