2015-09-11 34 views
2

所以基本上我已經開始使用PageObjects,並且遇到了一些問題。如何在Nightwatch.js的部分中使用命令?

  1. 我想直接在某些部分執行命令。例如 - 我想.waitForElementVisible直接在部分(不在元素)。它甚至有可能嗎?我已經嘗試了很多組合,例如:

    browser.page.topMenu()section.loginBox.section.unauthenticated.waitForElementVisible( '@ loginTooltip',10000)

所以。看起來像這樣:topMenu()是我的pageObject文件,然後有loginBox節包含 - >unauthenticated節包含 - >loginTooltip部分。我想在最後一節中提供.waitForElementVisible。這個怎麼做?我知道我可以毫無限制地組合我的部分,但以後如何處理它們?

  1. [會說這個問題是獎金,因爲它與標題中的問題沒有關係] 我在對節中的節進行斷言時遇到問題。這個怎麼做?我已經嘗試了很多辦法,其中之一是以下:

browser.page.topMenu().expect.section('@loginBox').to.be.visible - 這工作 - 因爲它是唯一一個部分

browser.page.topMenu().expect.section('@loginBox').section('@unauthenticated').to.be.visible - 不行 - 我要檢查,如果節unauthenticated這在loginBox裏面是可見的。這個怎麼做?

在此先感謝所有的答案,我試圖自己弄清楚這一點,但沒有任何成功。

回答

1

OK首先讓我們來打破它,所以這將是更具可讀性:

var topMenu = browser.page.topMenu(); // Declare the page object. 
var loginBox = topMenu.section.loginBox; // Declare the first section. 
var unauthenticated = loginBox.section.unauthenticated // Declare the second section. 

等等...

一旦要執行的命令,你可以這樣做:

loginBox.waitForElementVisible('@unauthenticated'); 

請注意,部分選擇器應聲明:

sections: { 
    unauthenticated: { 
     selector: '.unauthenticated_title', 
     elements: { 
     sectionElements: '.selector_selector' 
     } 
    }, 
    anotherSection: { 
     ... 
    } 
} 

第二個問題是類似的。

loginBox.expect.element('@ unauthenticated').to.be.visible;