Nightwatch 页面对象持久化

Nightwatch Page Object persistence

使用 Nightwatch 的页面对象功能,我定义了页面的所有元素及其 URL。导航到页面后(例如,page.navigate()),代码等待其中一个元素可见,然后在单击离开页面的另一个元素之前记录几个元素的值。我想通过等待同一个元素不再显示来确保页面不再显示,但是第二次等待总是超时,我不得不寻找一个不在该页面上的元素来验证我已经离开这一页。例如,

module.exports.command = function (settings) 
{   var page = this.page.settings()
    page.navigate()
        .waitForElementVisible('@firstName',3000)
        .getValue('@firstName',     function(r) {settings.firstName = r.value})
        .getValue('@lastName',      function(r) {settings.lastName = r.value})
        .waitForElementVisible('@firstName',3000)
        .click('@dashboard')
        .waitForElementNotVisible('@firstName',3000) // this times out
    this.verify.visible('#AvailableProcedures')      // but this works
}

我的问题是:页面不再显示后,页面对象是否失效?

'Leaves the page',这是否意味着导航到另一个 url?如果是,您应该检查元素是 'present or not',而不是 'visible or not'

    module.exports.command = function (settings) 
{   var page = this.page.settings()
    page.navigate()
        .waitForElementVisible('@firstName',3000)
        .getValue('@firstName',     function(r) {settings.firstName = r.value})
        .getValue('@lastName',      function(r) {settings.lastName = r.value})
        .waitForElementVisible('@firstName',3000)
        .click('@dashboard')
        .waitForElementNotPresent('@firstName',3000,false,
           function(),'Element is not there');
}

例如,当我尝试登录时:

loginPage = client.page.login();
loginPage
   .navigate()
   .waitForElementVisible('@username',5000,false)
   .setValue('@username',username)
   .setValue('@password',password)
   .click('@submit')
   .waitForElementNotPresent('@username,5000,false)