Which Page Class (POM) to verify successful actions from?



  • 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?



  • 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.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2