3/07/2021

Visual Studio Code, Nightwatch.js, JavaScript and Chrome

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. 

We will verify the blog title.

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

Visual Studio Code, WebdriverIO, JavaScript and Chrome - cucumber html test report

 Apart Allure test report  we can use Cucumber test report in html format. We will follow this instructions . 1. Install  wdio-cucumberjs-js...