User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 2 of 2
  1. #1
    New Member
    Join Date
    Dec 2014
    Post Thanks / Like
    0 Post(s)
    0 Thread(s)
    Total Downloaded

    Page object design: How should test classes correlated with page objects?

    I'm conflicted whether to have a test class per page (view) object or per feature which would consistent of multiple page (view) objects.

    For example, a deleted user is expected to be added to deleted view while removed from normal view within User Management. To verify the user was deleted I need an assert for both views (normal and deleted view).

    If I were to write a test class per page (view) object then how would you organize my test cases for this example? Should I just break this test case into two test cases (one test case for each test class corresponding to each view)?


    Seems a bit redundant.

  2. #2
    SQA Knight
    Join Date
    May 2006
    Playa Del Rey, California, United States
    Post Thanks / Like
    17 Post(s)
    1 Thread(s)
    Total Downloaded
    page object is meant to promote reusability.

    So you want to have 1 page object per screen, and optionally per pane if you want to break things down further for reuseable pieces such as navbars and recurring sets of elements.

    You might have page object that looks something like, (excuse the code, i use to code in Java and now work in a c# shop, so I get the syntax confused)

    class ManageUserPage {
      IWebDriver _driver;
      // constructor yadda yadda yadda...
      public void AddUser(string username) {
        //code to click buttons and fill out forms.
      public void DeleteUser(string username) {
        IWebElement userRow = _FindUserRow(username);
      public bool DoesUserExist(string username) {
        try {
          return true;
        } catch(Exception e) {
          return false;
      private void _FindUserRow(string username) {
        try {
          return _driver.findElement(By.XPath("//tr/td[.='" + username + "']/..");
        } catch (NoSuchElementException) {
          throw Exception("user not found");
    Then in your tests,
    public class UserManagementPageTests {
      public void setup() {
        //code to navigate to page
      public void teardown() {
        // close the browser and clean up.
      public void TestAddingNewUser() {
        ManageUserPage manageUserPage = PageFactory.init<ManageUserPage>(driver);
      public void TesDeleteNewUser() {
        ManageUserPage manageUserPage = PageFactory.init<ManageUserPage>(driver);
    At first this seems very redundant. Why did I just create an entire class just to reuse 2 lines of code in _FindUserRow in this case?

    Imagine you have a more complex page with more sharing going on. So say that simple FindUserRow operation could be shared in some new actions such as, "Edit User", "Lock User", "Disable User", "Move User" etc... Then later some dev decides to change the ID of the user row container and move the pane over to the right side under a different column.

    In this page object model, you can just modify that _FindUserRow instead of having to modify each test.

    So the Key take away is, you're probably writing about 5x more code up front, but in the long run you'll have lower maintenance and readability. Notice how the tests I have read at a very high level. It's almost like I don't even need a BDD layer like cucumber to make the tests readable.
    David Lai
    SDET / Consultant
    LinkedIn profile



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.11%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 10:08 AM.

Copyright BetaSoft Inc.