在Geb
和WATIR
中,我们使用某些关键字来访问我们在网页类中指定的page_url
。例如。 to
中的Geb
关键字和visit
中的WATIR
关键字。
我们可以在nightwatch.js
中使用什么类似的内容。这是我尝试过的,但它给出了错误:
我试过了:
module.exports = {
url: function () {
return this.api.globals.launchUrl + "/goto/desiredPage.html";
},
commands: [pageCommands],
elements: {}
};
在页面类中,我将它用作:
desiredPage
.url()
.foo()
.bar();
client.end();
但它提供错误.url is not a function
。
答案 0 :(得分:0)
You can see the nightwatch examples inside the nightwatch folder for example:
[page-objects/home.js]
var searchCommands = {
submit: function() {
this.waitForElementVisible('@submitButton', 3000)
.click('@submitButton')
.api.pause(1000);
return this; // Return page object for chaining
}
};
module.exports = {
url: 'http://google.com',
commands: [searchCommands],
elements: {
searchBar: { selector: 'input[name=q]' },
submitButton: { selector: 'button[type=submit]' }
}
};
and then in the test:
/* jshint expr: true */
module.exports = {
'Demo Google search test using page objects' : function (client) {
var homePage = client.page.home();
homePage.navigate();
homePage.expect.element('@searchBar').to.be.enabled;
homePage
.setValue('@searchBar', 'Nightwatch.js')
.submit();
var resultsPage = client.page.searchResults();
resultsPage.expect.element('@results').to.be.present.after(2000);
resultsPage.expect.element('@results').to.contain.text('Nightwatch.js');
resultsPage.expect.section('@menu').to.be.visible;
var menuSection = resultsPage.section.menu;
menuSection.expect.element('@web').to.be.visible;
menuSection.expect.element('@video').to.be.visible;
menuSection.expect.element('@images').to.be.visible;
menuSection.expect.element('@shopping').to.be.visible;
menuSection.productIsSelected('@web', function(result) {
this.assert.ok(result, 'Web results are shown by default on search results page');
});
client.end();
}
};
so "url()" command in pages does not exist you need to define the url in te page and the use "navigate()" instead.