2015-09-11 17 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;