【问题标题】:Architecture/Design of PageObjects for Pages with hierarchy: menu-items/menu-sub-items/menu-sub-items-tabs具有层次结构的页面的 PageObjects 的体系结构/设计:menu-items/menu-sub-items/menu-sub-items-tabs
【发布时间】:2013-08-21 07:46:22
【问题描述】:

我正在为带有 selenium webdriver 的单页 webapp 开发一个 Java 框架,使用以下模式:PageObject、SlowLoadableComponent(责任链)、PageFactory、HaveExpectedControls(每个页面都知道它应该包含哪些元素并通过 . getExpectedControls)

所以我创建和使用我的页面:

LoginPage loginPage = new LoginPage(driver, "http://mywebapp.com");
mainPage MainPage = new MainPage(driver, loginPage, "password"); 
mainPage.get();  //this method checks whether page .isLoaded(), if not - calls its .load() method and finally assert it .isLoaded()
for (WebElement element: mainPage.getExpectedControls()) {
    assertTrue(element.isDisplayed);
}

我目前的目标是:测试用户在浏览我的网络应用时可以执行的所有“路径”。

在我到达网页之前一切都很简单,在我的 webapp 层次结构中“更深”...

我的页面可以如下表示

------------
|Login Page|
------------
->
|------------------------------
|LogoutLink
|---------------------------------
|mode: _ standart _ expert|  __________________
|-------------------------| |SystemSettingsTab1|SystemSettingsTab2|SystemSettingsTab3
|*MainPage menu item      | |                   ----------------------------------------
|*SomeOther menu item     | |                                                           |
|...                      | |                                                           |
|*System menu item      >->
|** Settings sub item    >-> 
|...                      | |
|** OneMore sub item      | |

这里有一些“规则”可以进一步解释:

First you get Login Page
  Then (if loged in) you allways get 'MainPage menu item' (and 'standard' mode checked)
    You allways see (so can click only what you see):
      - only that sub-menu-items that are inside 'current' menu item page
      - only that sub-menu-items-tabs that are:
        - inside current sub-menu-item
        - is correspondent to the current mode ('expert' mode allows more tabs)
    Once clicked on any 'item' you allways get its first 'child item'
    Then whatever you do you can:
      - logout
      - switch to any 'item' which you can see (check correspondent section above):
        i.e.: 
        - switch to any other menu-item page by clicking on it
        - switch to any of sub-menu-items of the current menu-item:
            there is a special case for 'the first sub-menu-item':
              you can get it by:
                - clicking on its sub-menu-item link
                - on its parent menu-item 
        - switch to any of sub-menu-item-tabs of current sub-menu-item
            there is a special case for 'the first sub-menu-item-tab':
              you can get it by:
                - clicking on its sub-menu-item-tab link
                - on its parent sub-menu-item
                - on its parent menu-item 

问题: 如何设计:

  • 我的所有页面的类层次结构?

  • 我可以在我的测试中浏览它们的方式?(尤其包括特殊情况,我可以通过多个链接获取某些页面)

【问题讨论】:

    标签: java selenium architecture webdriver pageobjects


    【解决方案1】:

    我认为以下将是一个简单有效的解决方案,

    1. 具有导航(或单击)其他菜单项和注销方法的主页类。
    2. 每个菜单项的类以及子菜单项的方法,扩展主页面类

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 1970-01-01
      • 2018-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多