Nightwatch.js, based on Node.js, is an End-to-End (E2E) testing solution for browser and web app. Use the power of API Selenium WebDriver to perform commands and assertions on the elements of the DOM.

nightwatchjs site
PhantomJS is a scriptable headless WebKit with API JavaScript. Fast, native to various Web standards: DOM handling, CSS selectors, JSON, Canvas, and SVG.

phantomjs site

nightwatchjs_project

 

 

 

 

An example of step_definition.js ->

module.exports = function() {

    this.Given(/^I open site_example's page$/, function() {
        this
        	.resizeWindow(1024, 768)
            .url("http://www.site-example.it")
            .waitForElementVisible("body", 1000);
    });

    this.When(/^I search for iPhone$/, function() {
        this
        	.useXpath()
        	.waitForElementVisible("//input[@id='short_gsa_search_box']", 1000)
        	.setValue("//input[@id='short_gsa_search_box']", "iphone")
        	.click("//*[@id='gsa_menu_box']/a");
    });

    this.Then(/^the page title is as expected$/, function() {
        this.assert.containsText("//*[@id='c118109']/div[2]/div/span[1]", "Hai cercato: iphone");
    });
    
};

 

nightwatch.conf.js ->

module.exports = {
    "src_folders" : [require('nightwatch-cucumber')()],
    "output_folder" : "reports",
    "custom_commands_path" : "",
    "custom_assertions_path" : "",
    "globals_path" : "",
    "live_output" : false,
    "parallel_process_delay" : 10,
    "disable_colors": false,
    "test_workers" : false,

    "selenium" : {
        "start_process" : false,
        "server_path" : "lib/selenium-server-standalone-2.52.0.jar",
        "log_path" : "logs",
        "host" : "10.60.236.49",
        "port" : 6666,
        "cli_args" : {
            "webdriver.chrome.driver" : "",
            "webdriver.firefox.profile" : ""
        }
    },

    "test_settings" : {
        "default" : {
            "launch_url" : "http://ip_nightwatch_pc",
            "selenium_host" : "ip_nightwatch_pc",
            "selenium_port" : 6666,
            "silent" : true,
            "disable_colors": true,
            "screenshots" : {
                "enabled" : false,
                "path" : ""
            },
			"desiredCapabilities" : {
				"browserName" : "phantomjs",
				"phantomjs.cli.args" : ["--ignore-ssl-errors=true"],
  				"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36",
  				"phantomjs.binary.path" : "/Users/jenkins/Desktop/nightwatchjs_job_jenkins/phantomjs-2.1.1-macosx/bin/phantomjs",
  				"javascriptEnabled" : true,
  				"acceptSslCerts" : true
			}
    	}
 	}
}

 

package.json ->

{
  "name": "nightwatchjs",
  "version": "1.0.0",
  "description": "",
  "main": "nightwatch.conf.js",
  "dependencies": {
    "cucumber": "^0.9.5"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

 

feature_example.feature ->

Feature: Homepage Search

Scenario: Searching Homepage

    Given I open example_site's page
    When I search for iPhone
    Then the page title is as expected

 

Job Jenkins Nightwatch.js on Excute Command bash

  • export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
  • cd /Users/jenkins/workspace/PhantomJS\ Cucumber-Nightwatchjs\ Tests
  • /Users/jenkins/workspace/PhantomJS\ Cucumber-Nightwatchjs\ Tests/node_modules/nightwatch/bin/nightwatch

 

Happy Testing with Ghosts! XD

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Print this page