admin管理员组文章数量:1289635
I'm using nightwatch "0.8.6". Per the documentation on pages, I've created a pages/login.js
file and add the directory to the config file with:
module.exports = {
url: function() {
return this.launchUrl;
}
};
The documentation mentions this.api
, but thats not a property of the client / browser. this.launchUrl
apparently is available, however.
I changed an existing test to use it:
module.exports = {
'Login page has a login button' : function (browser) {
browser
.url(browser.page.login().url())
.waitForElementVisible('body', 10000)
.assert.containsText('button', 'SIGN IN')
.end();
}
}
The test now fails. .url tries to open selenium with data:,
, instead of the value of this.launchUrl, which is localhost:3000.
The page object is apparently evaluated in the context of the login test, so this in the page object should have this.launchUrl. Diving into the source I see there are also page wrapper objects in the mix, somehow.
How can I use correctly create and use a page object in 0.8.6?
I'm using nightwatch "0.8.6". Per the documentation on pages, I've created a pages/login.js
file and add the directory to the config file with:
module.exports = {
url: function() {
return this.launchUrl;
}
};
The documentation mentions this.api
, but thats not a property of the client / browser. this.launchUrl
apparently is available, however.
I changed an existing test to use it:
module.exports = {
'Login page has a login button' : function (browser) {
browser
.url(browser.page.login().url())
.waitForElementVisible('body', 10000)
.assert.containsText('button', 'SIGN IN')
.end();
}
}
The test now fails. .url tries to open selenium with data:,
, instead of the value of this.launchUrl, which is localhost:3000.
The page object is apparently evaluated in the context of the login test, so this in the page object should have this.launchUrl. Diving into the source I see there are also page wrapper objects in the mix, somehow.
How can I use correctly create and use a page object in 0.8.6?
Share Improve this question edited Nov 4, 2015 at 20:10 Allyl Isocyanate asked Nov 3, 2015 at 0:15 Allyl IsocyanateAllyl Isocyanate 13.6k17 gold badges84 silver badges132 bronze badges2 Answers
Reset to default 6I think you can try to add one var to call the login.js page. like this:
module.exports = {
'Login page has a login button' : function (browser) {
var LoginPage = browser.page.login();
LoginPage.navigate();
LoginPage
.waitForElementVisible('body', 10000)
.assert.containsText('button', 'SIGN IN')
.end();
}
}
So according to the docs you have to:
- "Each page object should be located in a separate file, located in a designated folder. Nightwatch reads the page objects from the folder (or folders) specified in the page_objects_path
configuration property."
Have you configured your page_objects_path
directory?
Once you have done this you can create a js file in that folder, such as:
module.exports = function(client) {
return {
gotoUrl: function() {
return client
.url(client.launchUrl);
},
};
};
And then you can write your test like:
module.exports = {
'Login page has a login button': (browser) => {
browser.page.pagescriptname()
.gotoUrl()
.waitForElementVisible('body', 10000)
.assert.containsText('button', 'SIGN IN')
.end();
}
}
Make sure that you have configured launch_url
in your nightwatch.js file (or this can be changed dynamically (which I have done for my project) via the nightwatch.conf.js
file.
本文标签: javascriptUsing pages object in Nightwatch JSStack Overflow
版权声明:本文标题:javascript - Using pages object in Nightwatch JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741431853a2378407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论