I am looking to create reusable components within my nightwatch.js
tests.
ie. login to the web app, logout of the web app
What is the best method / pattern for creating these steps in a reusable way?
To execute tests in multiple browsers, you need to add the desired capabilities of the browsers and Test_worker configurations in nightwatch. json file. For example if you want to execute tests in three browsers parallely - Chrome, Firefox and Opera, your nightwatch. json should something like this.
A new parameter --testcase has been added to run a specified testcase. Show activity on this post. Test 2 and Test 3 will be executed. Separate each test function is mandatory because Nightwatch handled with filematcher each file.
js, Nightwatch. js is an open-source automated testing framework that aims at providing complete E2E (end to end) solutions to automate testing with Selenium Javascript for web-based applications, browser applications, and websites. Nightwatch.
Nightwatch. js framework is a Selenium-based test automation framework, written in Node. js and uses the W3C WebDriver API (formerly Selenium WebDriver).
You can create custom commands for that: http://nightwatchjs.org/guide#writing-custom-commands
exports.command = function(username, password) {
this
.waitForElementVisible('#password', 4000)
.setValue('#password', password)
.waitForElementVisible('#username', 1000)
.setValue('#username', username)
.waitForElementVisible('#sign_in', 1000)
.click('#sign_in')
.waitForElementVisible('h1.folder-title', 10000)
return this;
};
.login("your_username", "your_password")
This is typically done with page objects. http://nightwatchjs.org/guide#page-objects
Then you can just
var myPage = client.page.myPage();
myPage.navigate()
.assert.title('MyPage')
.login('foo', 'bar)
.assert.displayName('foo');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With