Skip to content

Instantly share code, notes, and snippets.

@appsparkler
Forked from posva/Nightwatch starter.md
Created February 20, 2017 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appsparkler/bb321b696edf9748012b040a7e170b6f to your computer and use it in GitHub Desktop.
Save appsparkler/bb321b696edf9748012b040a7e170b6f to your computer and use it in GitHub Desktop.

Install the needed packages

npm i --save-dev nightwatch selenium-server chromedriver

Create a e2e-tests dir:

mkdir e2e-tests

Create a config file nightwatch.json:

{
  "src_folders" : ["e2e-tests"],
  "output_folder": "coverage",

  "selenium" : {
    "start_process" : true,
    "server_path" : "node_modules/selenium-server/lib/runner/selenium-server-standalone-2.48.2.jar",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "node_modules/chromedriver/lib/chromedriver/chromedriver"
    }
  },

  "test_settings" : {
    "default" : {
      "selenium_port": 4444,
      "selenium_host": "localhost",
      "silent": true
    },

    "chrome" : {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

Create a sample test google.js

'use strict';
module.exports = {
  'Demo test Google': function(browser) {
    browser.url('http://www.google.com')
      .waitForElementVisible('body', 1000)
      .expect.element('input[type=text]')
      .to.be.visible;
    browser.setValue('input[type=text]', 'rembrandt van rijn')
      .click('button[name=btnG]')
      .expect.element('ol#rso a:first-child')
      .to.be.visible.after(2000)
      .and.text.to.contain('Rembrandt');
    browser.end();
  }
};

Launch nightwatch!

./node_modules/.bin/nightwatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment