For now we will use Nightwatch.js for end-to-end testing.
I will use Visual Studio Code as code editor and Ubuntu system.
Create a directory for the project, initialize the node project in the directory:
npm init -y
Then install nightwatch.js:
npm install nightwatch chromedriver --save-dev
First nightwatch run without arguments to generate nightwatch.conf.js file:
npx nightwatch
Create a directory for tests and write its location to the config file:
Create a test file with the same test as in Visual Studio Code, Selenium, Firefox, JavaScript and Mocha with Chai article.
module.exports = { "assert title": browser => { browser.url("https://automation-playground.blogspot.com"); browser .assert.title("Automation Playground"); } }
To run the test execute:
npx nightwatch -e chrome
The test passed!
Nightwatch.js allows us to use BDD style.
Let's use describe(), before(), test() and after() to better structure our test; you can copy/paste the example:
describe('Testing Automation Playground blog', () => { before(browser => { browser .url("https://automation-playground.blogspot.com"); }); test("Verify the blog title", browser => { browser .assert.title("Automation Playground"); }); after(browser => { browser .end(); }); });
npx nightwatch -e chrome
The following test scenario will be executed again:
- run Chrome browser
- go to https://automation-playground.blogspot.com
- verify the blog's title
- close Chrome browser
The test passed!
No comments:
Post a Comment