2013-08-21 58 views
1

我正在用selenium webdriver爲單頁webapp開發一個框架,使用以下模式:PageObject,SlowLoadableComponent(責任鏈),PageFactory,HaveExpectedControls(每一頁都知道哪些元素它應該包含並通過.getExpectedControls歸還)具有層次結構的頁面的PageObjects的體系結構/設計:menu-items/menu-sub-items/menu-sub-items-tabs

所以我創建和使用我的網頁,如:

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時可以做的所有「修改」。

一切都很容易,直到我到達的頁面,這是在我的web應用程序層次結構「更深」 ......

我的頁面可以如下

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

問題: 如何設計:

  • 我的類層次結構的所有網頁?

  • 我可以在我的測試中衝浪他們的方式?(尤其是包括特殊情況下,我可以通過幾個環節得到一些頁)

回答

0

我認爲有以下將是一個簡單而有效的解決方案,

  1. 班主頁與方法來瀏覽(或點擊)其他菜單項並註銷。
  2. 每個菜單項的類別與子菜單項的方法,擴展主頁面類