Nightwatch Page Object persistence

匿名 (未验证) 提交于 2019-12-03 01:35:01

问题:

Using Nightwatch's Page Object capability, I have all the elements of a page defined as well as its URL. After navigating to the page (e.g., page.navigate()), the code waits for the one of the elements to be visible and then records the values of several elements before clicking on another element that leaves the page. I want to ensure that the page is no longer displayed by waiting for that same element to not be displayed, but that second wait always times out and I'm forced to look for an element that's not on that page to verify I've left the page. For example,

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 }

My question is: does a page object become invalid once the page is no longer displayed?

回答1:

'Leaves the page',does that mean navigate to another url ? If yes,you should check the element is 'present or not', instead of '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'); }

E.g , when i try to login:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!