Giter VIP home page Giter VIP logo

nightwatchjs-example's Introduction

Nightwatch

UI automated testing framework powered by Node.js. It uses the Selenium WebDriver API.


Selenium WebDriver standalone server

Nightwatch works with the Selenium standalone server so the first thing you need to do is download the selenium server jar file selenium-server-standalone-2.x.x.jar from the Selenium releases page: https://selenium-release.storage.googleapis.com/index.html


Step 1: Installing Selenium standalone server.

Nightwatch works with the Selenium standalone server so at first we need to download the selenium standalone server. Prerequisite: make sure you have JDK installed.

$ npm install selenium-standalone@latest -g

To run selenium standalone server

$ selenium-standalone start

Step 2: Installing Chrome driver / geckodriver

We want to run our test on Chrome, Safari, and Firefox, so we must also install their respective drivers and this driver will be used by Selenium to control the browsers.

$ brew install geckodriver

or

$ npm install chromedriver --save-dev

Step 3: Installing Nightwatch

Nightwatch.js is an easier way to write tests that running them using Selenium. To install it, cd into your project, and then install the module from npm to your dev-dependencies:

$ git clone https://github.com/nightwatchjs/nightwatch.git
$ cd nightwatch
$ npm install

Step 4: Adding Configuration file into nightwatch project

The test runner of expects a configuration file to be passed and the basic Nightwatch configuration happens through a json configuration file — nightwatch.json. Let’s create a nightwatch.json file, and fill it with:

{
  “src_folders” : [“tests”],
  “output_folder” : “reports”,
  
  “selenium” : {
      “start_process” : true,
      “server_path” : “./bin/selenium-server-standalone-3.3.1.jar”,
      “log_path” : “”,
      “port” : 4444,
      “cli_args” : {
          “webdriver.chrome.driver” : “./bin/chromedriver”
       }
   },
  “test_settings” : {
      “default” : {
      “launch_url” : “http://localhost",
      “selenium_port” : 4444,
      “selenium_host” : “localhost”,
      “desiredCapabilities”: {
            “browserName”: “chrome”,
            “javascriptEnabled”: true,
            “acceptSslCerts”: true
      }
    }
  }
}

Step 5: Writing test

We have now installed Nightwatch, standalone Selenium server, and also driver for browsers. With all of these steps, now we are ready with all the tools to create end-to-end tests.

Let’s add a new file in the tests folder, called sample.js.

module.exports = {
  'Searching nightwatch in youtube': function (browser) {
    browser
      .url("http://www.youtube.com/")
      .pause(2000)
      .setValue('#search' , "Nightwatch js")
      .pause(2000)
      .keys(browser.Keys.ENTER)
      .pause(2000)
  },
  after: function (browser) {
    browser
      .end();
  }
};

Step 6: Running the test

To run your test, in your terminal do the command which will run the test file sample.js.

$ nightwatch -t tests/sample.js

Setup Guides

Specific WebDriver setup guides can be found on the Docs website. Legacy Selenium drivers setup guides along with debugging instructions can be found on the Wiki.

nightwatchjs-example's People

Contributors

sabitaneupane avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.