GithubHelp home page GithubHelp logo

dwyl / learn-nightwatch Goto Github PK

View Code? Open in Web Editor NEW
584.0 123.0 215.0 1.27 MB

:last_quarter_moon_with_face: Learn how to use Nightwatch.js to easily & automatically test your web apps in *real* web browsers.

JavaScript 74.67% HTML 25.33%

learn-nightwatch's Introduction

Learn Nightwatch: Complete Beginners Tutorial

Automate your acceptance tests and run them in real browsers!

nightwatch-logo-with-slogan

Codeship Build Status Dependency Status devDependency Status HitCount

Why?

Testing what the people using your application/website will see and their ability interact with the product is (probably) the most important part of building a web app/site. You can have amazing code, a super-fast backend and gorgeous UI, but none of that matters if people are unable to use it because of a basic bug!

dilbert-internet-full

User Acceptance Testing (UAT) with a tool like Nightwatch (Selenium) lets you to run real-world scenarios in your Web App which will give you confidence that the app works in the chosen device(s)/browser(s).

What?

Automated Acceptance Testing using Real Browsers.

Nightwatch is quick to setup and the tests/scenarios are easy to write.

We exhaustively read through all the tutorials, blog posts and documentation for Nightwatch (including the mailing list & StackOverflow Q&A) and have condensed our findings into this step-by-step guide. We hope you find it useful and decide to use it for your web app/site! Please give us feedback and if you get stuck, tell us!

Background Links

Who?

Who should learn/use Nightwatch?

  • Developers - People writing code, building web apps needing to check that everything works as expected.
  • QA - Quality Assurance people who have to manually "click-test" apps/sites.
  • "Testers" - Many organisations still have people who's job is to write tests for software. If you describe yourself as a "Tester" and want an easier/faster way to write your acceptance tests, read on!

How?

Quick Start (5mins)

Try it on your local machine in 5 mins by following these 3 easy steps:

1. Clone

Clone the repository by copy-pasting the following command into your terminal (replace cp with copy if you're on Windows):

git clone https://github.com/dwyl/learn-nightwatch.git && cd learn-nightwatch && cp sample.env .env

Note: if you're curious what that last part is, see: https://github.com/dwyl/env2

2. Install1

Make sure you cd learn-nightwatch so that you're in the correct directory and then install the required dependencies including Selenium Server and chromedriver:

npm install

3. Run (tests)2

Run the Nightwatch tests:

npm test

You should expect to see: learn-nightwatch-console-output-success

Once you see the tests pass you are well on your way to testing with Nightwatch!

1This assumes you have node.js installed. If not, https://nodejs.org/en/download/ 2Selenium Requires Java/JDK see: Java Installation section below. (don't worry, you'll be up-and-running shortly...!) Once you have Java installed re-run the Nightwatch tests (npm test).

Step-by-Step Tutorial to end to end test on your OWN PROJECT

Now that you have had a taste for running tests with Nightwatch, let's walk through each of the steps to get this working in your project.

Installation (in detail)

1) Make sure you have Java(Runtime Environment JRE) installed

While we prefer not to run Java on our machines for security reasons Selenium is still the best way of running tests in real browsers.

You can check by typing java -version into your terminal and you should see your version number if you have Java installed.

How do I install Java? https://www.java.com/en/download/help/download_options.xml pick your Operating System and follow the instructions

#####ย Mac OSX? (use homebrew)

If you haven't updated brew in a while, do that first:

brew update

That will install cask which is now part of Homebrew.

Now you can install Java:

brew cask install java

You should see something like this: install-java-with-homebrew-cask

See: https://stackoverflow.com/questions/24342886/how-to-install-java-8-on-mac

2) cd into your project

3) Install nightwatch

First install the nightwatch node.js module from NPM:

npm install nightwatch --save-dev

Note: while the Nightwatch docs instruct to install globally (-g), we prefer to always install devDependencies locally to the project and list them explicitly in package.json so it's clear to everyone viewing/using the project exactly which version is required to run the tests.

4) Install selenium-server and chromedriver

In order to run Browser tests Nightwatch uses Selenium. We prefer to automate the installation of Selenium using selenium-server which ensures that everyone on our team always has the latest version.

npm install selenium-server chromedriver --save-dev

5) Configuration

Once you've installed nightwatch, you will need to create a configuration file. Some Nightwatch tutorials use a nightwatch.json file; this is good for the most basic cases but if you want to use variables in your configuration we recommend using a .js file; specifically called nightwatch.conf.js. Save this file to your project directory.

You can copy over our basic configuration saved in nightwatch.conf.BASIC.js: nightwatch.conf.BASIC.js

Or copy the following into a file called nightwatch.conf.BASIC.js

require('env2')('.env'); // optionally store your Evironment Variables in .env
const seleniumServer = require("selenium-server");
const chromedriver = require("chromedriver");
const SCREENSHOT_PATH = "./screenshots/";

// we use a nightwatch.conf.js file so we can include comments and helper functions
module.exports = {
  "src_folders": [
    "test/e2e"// Where you are storing your Nightwatch e2e tests
  ],
  "output_folder": "./reports", // reports (test outcome) output by nightwatch
  "selenium": {
    "start_process": true, // tells nightwatch to start/stop the selenium process
    "server_path": seleniumServer.path,
    "host": "127.0.0.1",
    "port": 4444, // standard selenium port
    "cli_args": {
      "webdriver.chrome.driver" : chromedriver.path
    }
  },
  "test_settings": {
    "default": {
      "screenshots": {
        "enabled": true, // if you want to keep screenshots
        "path": SCREENSHOT_PATH // save screenshots here
      },
      "globals": {
        "waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
      },
      "desiredCapabilities": { // use Chrome as the default browser for tests
        "browserName": "chrome",
        // uncomment the lines to run Chrome in headless mode
        // "chromeOptions" : {
        //    "args" : ["headless"]
        // }
        "chromeOptions": {
          "args" : ["--no-sandbox"],
          "w3c": false
        }
      }
    },
    "chrome": {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true // turn off to test progressive enhancement
      }
    }
  }
}

function padLeft (count) { // theregister.co.uk/2016/03/23/npm_left_pad_chaos/
  return count < 10 ? '0' + count : count.toString();
}

var FILECOUNT = 0; // "global" screenshot file count
/**
 * The default is to save screenshots to the root of your project even though
 * there is a screenshots path in the config object above! ... so we need a
 * function that returns the correct path for storing our screenshots.
 * While we're at it, we are adding some meta-data to the filename, specifically
 * the Platform/Browser where the test was run and the test (file) name.
 */
function imgpath (browser) {
  var a = browser.options.desiredCapabilities;
  var meta = [a.platform];
  meta.push(a.browserName ? a.browserName : 'any');
  meta.push(a.version ? a.version : 'any');
  meta.push(a.name); // this is the test filename so always exists.
  var metadata = meta.join('~').toLowerCase().replace(/ /g, '');
  return SCREENSHOT_PATH + metadata + '_' + padLeft(FILECOUNT++) + '_';
}

module.exports.imgpath = imgpath;
module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH;

One of our favourite things about using a .js file is the ability to add comments in the file. This makes it much easier for new people to understand what's going on. We have a slightly more evolved nightwatch.conf.js (with Saucelabs) see: github.com/dwyl/learn-nightwatch/nightwatch.conf.js

6) Running config file

You will need to run the config file you created to download the Selenium driver.

node nightwatch.conf.BASIC.js

7) Create Your Nightwatch Test

Nightwatch "looks" for tests in the /test folder of your project by default; you can change this to whatever you prefer. We keep our Nightwatch tests in test/e2e.

This is the simplest test you can write for Nightwatch.

Assuming you're using the same folder structure as we are (tests in test/e2e), create a file named guineaPig.js inside that folder, containing the following code:

var config = require('../../nightwatch.conf.BASIC.js');

module.exports = { // adapted from: https://git.io/vodU0
  'Guinea Pig Assert Title': function(browser) {
    browser
      .url('https://saucelabs.com/test/guinea-pig')
      .waitForElementVisible('body')
      .assert.title('I am a page title - Sauce Labs')
      .saveScreenshot('guinea-pig-test.png')
      .end();
  }
};

See: github.com/dwyl/learn-nightwatch/test/e2e

8) Run your Test

Depending on what you named your configuration file, run it with a command resembling the following:

node_modules/.bin/nightwatch --config nightwatch.conf.BASIC.js

The camelCase filename ("guineaPig") is used to display the test's name in the console as in:

Running: Guinea Pig Assert Title

We add an entry in our package.json "scripts" section to not have to type all that each time. e.g:

"scripts": {
  "e2e": "nightwatch --config nightwatch.conf.BASIC.js"
}

Then run your tests as:

npm run e2e

If you called your config file nightwatch.conf.js you can run your tests without specifying the config file, i.e.

node_modules/.bin/nightwatch

If you see the following message while trying to run the tests: learn-nightwatch-java-not-installed

Then return to step 2 to install Java

Optional (Level Up)

Saucelabs

Most people building web apps/sites don't have easy access to several devices/browsers to test their output, if you need to test in a range of browsers/devices Saucelabs is a great option.

browser logos

In our nightwatch.conf.js we have defined saucelabs as our "default" setting.

We run our tests on saucelabs by running the following npm script/command:

npm run sauce

Which corresponds to the following complete command:

./node_modules/.bin/nightwatch -e chrome,ie11,android_s4_emulator,iphone_6_simulator

This just means "Run Nightwatch using the default configuration (Saucelabs in our case) and execute all tests in this list of browsers."

Note: you will need to have the following environment variables exported for Saucelabs to run your test:

export SAUCE_USERNAME=your-username
export SAUCE_ACCESS_KEY=your-key

If you're new to Saucelabs, checkout: github.com/dwyl/learn-saucelabs

Upload Screenshots to S3

If you decide to use Saucelabs to run your tests (in several devices/browsers), it will take screenshots for you and keep them inside Saucelabs. That's nice for people who are used to using Saucelabs, but what about the other stakeholders?

We decided to upload our screenshots to S3 and created a super-simple .html file which shows a slideshow of the images.

Example: https://isearch-ui.s3-eu-west-1.amazonaws.com/1.0.21/index.html

If you want the screenshots of tests to be uploaded to S3, you will need to have the following environment variables declared:

export AWS_S3_BUCKET=yourbucket
export AWS_REGION=eu-west-1
export AWS_ACCESS_KEY_ID=IDHERE
export AWS_SECRET_ACCESS_KEY=YOURKEY

The script we wrote to perform the uploading is: github.com/dwyl/learn-nightwatch/test/e2e/upload_screenshots_to_s3.js

The screenshots taken on Saucelabs browsers/devices are saved locally and uploaded to S3 when tests succeed.


Running your Nightwatch tests on your application being served locally

  • Before the test can run you have to set up sauce connect, there are many way to do this docs here. The simplest way I have found is to use Sauce Connect launcher, which is an addon for firefox.
  • Sauce Connect is sets up a tunnel to allow Sauce labs access to your local host, this means you can test whatever is being served from your local.
  • To run the tests you must make sure the application is being served in one terminal and that the tunnel is open(this can be checked from the saucelabs dashboard), you then run your e2e test command in another terminal window.

Running your Nightwatch tests on your Continuous Integration (CI)

Running your Nightwatch tests on CI is easy on CodeShip.

We usually set the required (minimum) node version in our package.json e.g:

"engines": {
  "node": "4.4.6"
},

Once you have the desired version of node installed.

Setup Commands:

# install dependencies:
npm install

Test Command:

# run tests
npm test

That's it.

Running your Nightwatch tests on Travis-CI with sauce connect

Since we are testing on the localhost we have to make sure that the server is started before the tests are run and closes after the tests finish. So we need to boot up a server to serve our content. Travis makes this easy enough via a before_script task. In the task we will just start a python simple server and give it a few seconds to boot. The ampersand at the end of the python line tells travis to run the process in the background instead of blocking the execution thread, allowing us to run tasks at the same time.

language: node_js
before_script:
  - python -m SimpleHTTPServer &
  - sleep 2
node_js:
    - "6.0"

One other way to run a server before running a test is to use the before and after methods present in nightwatch.

module.exports = {
  before: function (browser, done) {
  	server = require('../server')(done) // done is a callback that executes when the server is started
  },

  after: function () {
  	server.close()
  },

  'Demo test': function (browser) {
    browser
      .url('localhost:3000')   // visit the local url
      .waitForElementVisible('body'); // wait for the body to be rendered

    browser
      .assert.containsText('body','hello') // assert contains
      .saveScreenshot(conf.imgpath(browser) + 'dwyl.png')
      .end()
  }
}

The server.js can be a simple express server.

function makeServer(done) {
  var express = require('express');
  var path = require('path');
  var app = express();

  app.get('/', function (req, res) {
  	res.status(200).sendFile(`index.html`, {root: path.resolve()});
  });
  var server = app.listen(3000, function () {
  	var port = server.address().port;
  	done()
  });
  return server;
}
module.exports = makeServer;

Note : In the above example you can see that the port is fixed. It will run fine if you are running tests on a single device. If you are running tests on multiple devices on saucelabs, this will give you an error that the port is already in use, as all the devices try to start the server on the same port (in our current approach). So we need to dynamically allot available ports to prevent this error. You can use get-port for this.

This is all we need to run a test on browser/s. Now we have set up saucelabs on travis.

To run the test on Travis-CI and use sauce connect you need to add a addon to your .travis.yml

addons:
  sauce_connect: true

The username and access_key can be optionally stored in .travis.yml or can be stored on travis-ci website as environment variables. There are various methods of storing the username and access_key of saucelabs and you can read more about them here. In our case we have preferred to save it on travis website so that our .travis.yml is simple.

Now you have to make some changes in nightwatch.conf.js

const TRAVIS_JOB_NUMBER = process.env.TRAVIS_JOB_NUMBER;
// in test_settings.default:
default: {
  launch_url: 'http://ondemand.saucelabs.com:80',

  username : process.env.SAUCE_USERNAME,
  access_key : process.env.SAUCE_ACCESS_KEY,
  ...
  desiredCapabilities: {
    build: `build-${TRAVIS_JOB_NUMBER}`,
    'tunnel-identifier': TRAVIS_JOB_NUMBER,
  },
}

See the modified final config here You can run multiple test commands i.e.

- npm run test:unit; npm run test:e2e

You can see the working code here and the corresponding test on travis here

Note-1: Tests on the PRs of forked repos will fail as the secured environment variables are not accessible to them on travis. You will receive authentication error in that case.

Note-2: Running tests on IE still seems tricky. Will have to explore more. Any help is appreciated.

Note-3: If you are receiving timeout error, maybe you are running tests on many devices. Try to adjust the time or decrease the number of devices.

Running your Nightwatch tests on CircleCi.

To run the test on circle ci you need to make some adjustments to your circle.yml Here is an Example from the circle ci docs

dependencies:
  post:
    - wget https://saucelabs.com/downloads/sc-latest-linux.tar.gz
    - tar -xzf sc-latest-linux.tar.gz

test:
  override:
    - cd sc-*-linux && ./bin/sc --user $SAUCE_USERNAME --api-key $SAUCE_ACCESS_KEY --readyfile ~/sauce_is_ready:
        background: true
    #Wait for tunnel to be ready
    - while [ ! -e ~/sauce_is_ready ]; do sleep 1; done
    - npm start
        background: true
    # Wait for app to be ready
    - curl --retry 10 --retry-delay 2 -v http://localhost:5000
    # Run selenium tests
    - npm run test:e2e
  post:
    - killall --wait sc  # wait for Sauce Connect to close the tunnel

The test override starts the selenium server for you. Once it is ready the application is started in the background. Finally when ready, the tests are started. You can run multiple test commands i.e.

- npm run test:unit; npm run test:e2e

just like in the package.json



Running a single nightwatch test

Nightwatch tests can be quite time-consuming so sometimes you may just want to run one test at a time

This can be done by giving each test a tag by adding tags: [ 'tagname' ] to the beginning of your exported test scenario. You can then run the individual test (in this case with tag 'test1') with the script: "node_modules/.bin/nightwatch --tag test1"

If you want to dynamically choose which test to run using the command line, you could create another script in your package.json e.g. "e2etag": "./node_modules/.bin/nightwatch --env local --tag"

and then in your command line you can just run npm run e2etag -- test1

tl;dr

More detail than you will probably need ... but we're keeping for completeness.

Background

Why Nightwatch instead of xyz...?

We first looked at NightmareJS, and even though it looks really good (fast), we saw the reaction non-technical people had when we mentioned it and did not want to have to explain the name to people/clients every time, so instead opted for nightwatch. If nightmare ever change their name, we could re-consider it.

Research


Setup (Detail)

Manual Selenium Install

If you prefer to install it manually that's an option.

Visit: https://www.seleniumhq.org/download/ and download the latest version.

When downloading the selenium-server-standalone-2.53.0.jar you may see a warning in your browser: download-selenium-chrome-warning Click on "keep" to save the file. Once you have it, put it in the bin directory of your project and re-name it to selenium.jar (without the version number).

StackOverflow Questions

Remind me to Respond to these:

Cons (of using Nightwatch)

  • Selenium is not the fastest way to run tests.

learn-nightwatch's People

Contributors

alainpilon avatar alexandrebonneau avatar amilajack avatar arhell avatar cepm-nate avatar conorc1000 avatar dcangulo avatar dependabot[bot] avatar emersonmellado avatar eritikass avatar germain-gg avatar iteles avatar jonathan-soifer avatar karinakozarova avatar kot-lex avatar larrylutw avatar markhu avatar mgd722 avatar naazy avatar nelsonic avatar orzelius avatar p2635 avatar raudseppsiim avatar rchovatiya88 avatar ritz078 avatar tryenc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learn-nightwatch's Issues

Can we speed up our Nightwatch tests by running them in PhantomJS ?

On a reasonably "mature" project, e.g: https://github.com/TheScienceMuseum/collectionsonline we are running several end-to-end test scenarios: https://github.com/TheScienceMuseum/collectionsonline/tree/master/test/client
Running all of these tests takes 3 Minutes on localhost and 4.28 minutes on Travis-CI e.g: https://travis-ci.org/TheScienceMuseum/collectionsonline/builds/172018586#L3263

Can we investigate using PhantomJS instead of Chrome to reduce the amount of time that it takes to run our tests?

Starting point: https://github.com/nightwatchjs/nightwatch/wiki/Running-tests-in-PhantomJS

do what you love - not found on github

e2e/github   โœ– Testing if element <body> contains text: "do what you love".  - expected "do what you love" but got: "Skip to content ...

Did you change the page, I don't see the expected text and your test errors

Error retrieving a new session from the selenium server

Everything was going well on my "work" laptop, and then I tried to git clone, npm install, npm test on my "home" machine and got:
selenium-issue-on-home-mac

Error retrieving a new session from the selenium server

Connection refused! Is selenium server started?
{ state: 'unhandled error',
  sessionId: null,
  hCode: 1104154379,
  value:
   { localizedMessage: 'The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html',
     cause: null,
     suppressed: [],
     message: 'The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html',
     hCode: 807916486,
     class: 'java.lang.IllegalStateException',
     screen: null },
  class: 'org.openqa.selenium.remote.Response',
  status: 13 }

Think this might help debug it: https://groups.google.com/forum/#!msg/nightwatchjs/vSmIXUxU5qQ/f_kWtX1n_0YJ

Unable to reach localhost:8080 after upgrading Node to 8.1.4

Hello everyone,

Our development group is starting a new React project and I have been trying to use Nightwatch + Selenium to do the e2e testing. I got it to work when running everything using NodeJS 6.9.4. Now we have been forced to upgrade NodeJS to 8.1.4 and I'm facing an issue that is stopping me to proceed with testing. When using Selenium with Chrome as browser, I keep getting a 'This site can't be reached' message (but the page can be accessed if I open manually a Chrome window. Any idea what can be going on? Here you have the test result log and my nightwatch.conf.js

Test Result:

log.txt

Nightwatch Conf

nightwatch.conf.txt

Thanks for your help.

David

Sorry for having the files attached instead of expanded on the comment but I'm new in GitHub

Cold selenium-download fails

Running the basic nightwatch config on a fresh install, where the selenium jar doesn't yet exist, fails with "Error: Unable to access jarfile ./node_modules/nightwatch/bin/selenium.jar".

I believe it attempts to start downloading the selenium jar, but nightwatch looks for it and kills its process before it can finish. Adding the selenium jar manually fixes it, but that kind of defeats the purpose of using selenium-download.

Am I doing something wrong here or does this really not work?

A bit confused by readme

In this section we are told to add some code to the nightwatch.conf.js

Download Selenium (Web Driver) Standalone Server (Script)

Once you've downloaded the the selenium-download node module, put the following code at the bottom of your nightwatch.conf.js file:

require('selenium-download').ensure('./bin', function(error) {  
   if (error) {
     return console.log(error);
   } else {
     console.log('โœ” Selenium & Chromedriver downloaded to:', './bin');
   }
});
We run include this script in our nightwatch.conf.js which checks for the existence of selenium.jar before trying to run our tests. You will create your nightwatch.conf.js file in the next step.

But I dont believe the code is require. It appear to already be in the file.

Clarification text

Some of the text/order of the tutorial is a little confusing (after testing with @harrygfox and @JMurphyWeb). Therefore I propose we enhance the tutorial.

selenium download ensure

I can't seem to get this script to work

require('selenium-download').ensure('./bin', function(error) {  
   if (error) {
     return console.log(error);
   } else {
     console.log('โœ” Selenium & Chromedriver downloaded to:', './bin');
   }
});
[testium] grabbing selenium standalone server 2.53.0
Starting selenium server... There was an error while starting the Selenium server:

Error: Invalid or corrupt jarfile ./node_modules/nightwatch/bin/selenium.jar

Seems to be trying to start the server before the installation has completed? Is there a way to defer this in node?

Selenium won't start (because its already running)

If Nightwatch won't start Selenium:
nightwatch-already-running
It's because its already running.

Shut down existing running version of Selenium:

lsof -n -iTCP:4444 -sTCP:LISTEN -n -l -P | grep 'LISTEN' | awk '{print $2}' | xargs kill -9

Can we run Selenium as a Child Process?

This will allow us to spin it up just for the tests and shut it down again once they complete.

lsof -n -iTCP:4444 -sTCP:LISTEN -n -l -P | grep 'LISTEN' | awk '{print $2}' | xargs kill -9

Followed Instructions 1 by 1 but no success

MacBook Pro OS Sierra / 10.12.1 (16B2555)

I tried it first with the normal Tutorial from Nightwatch, gave me the same error. I figured at least this had to work.

Starting selenium server in parallel mode... started - PID:  1010

Started child process for: e2e/github 
Started child process for: e2e/guineaPig 
Started child process for: e2e/upload_screenshots_to_s3 
 e2e/upload_screenshots_to_s3   If you want to upload Screenshots to S3
      please set your AWS Environment Variables (see readme).
 e2e/upload_screenshots_to_s3   \n
 e2e/upload_screenshots_to_s3   [Upload Screenshots To S3] Test Suite
=========================================

  >> e2e/upload_screenshots_to_s3 finished.  


  >> e2e/github finished.  

 e2e/guineaPig   \n
 e2e/guineaPig   [Guinea Pig] Test Suite
===========================
 e2e/guineaPig   
 e2e/guineaPig   Results for:  Guinea Pig Assert Title
 e2e/guineaPig   โœ– Timed out while waiting for element <body> to be present for 15000 milliseconds.  - expected "visible" but got: "not found"
 e2e/guineaPig       at Object.module.exports.Guinea Pig Assert Title (/Users/XXXXXX/nightwatch/learn-nightwatch/test/e2e/guineaPig.js:8:8)
 e2e/guineaPig   FAILED:  1 assertions failed (21.219s)

  >> e2e/guineaPig finished.  


 _________________________________________________

 TEST FAILURE:  1 assertions failed, 0 passed. (21.613s)

 โœ– guineaPig

   - Guinea Pig Assert Title (21.219s)
   Timed out while waiting for element <body> to be present for 15000 milliseconds.  - expected "visible" but got: "not found"
       at Object.module.exports.Guinea Pig Assert Title (/Users/XXXXXX/nightwatch/learn-nightwatch/test/e2e/guineaPig.js:8:8)

npm ERR! Test failed.  See above for more details.

Which browser was the screenshot taken in?

At present we are only saving a basic filename for screenshots and it does not include any metadata... this is OK if we are only testing in a single browser but kinda useless if we want to compare different browsers over time...

I propose that we store the name of the browser & version number in the filename. thoughts?

Need help with - new clone of learn-nightwatch testing (npm ERR!)

Hello Everyone,
I was hoping to get some assistance. I am testing out nightwatch.js for the first time. I have created a new CentOS VM and installed all of the required components (node.js, java, etc). I then cloned the github learn-nightwatch repository and everything seems to have gone smoothly. However, after running "node nightwatch.conf.BASIC.js in order to download the selenium.jar file I run into an issue when I actually run the tests: npm test.

The attached snip contains the error:

npmerr

Additional information:

npm version = 4.1.2
node version = 7.6.0

Also, here's a snip using npm test --verbose

npmverbose1
npmverbose2

Any help with this matter is greatly appreciated!!

Cheers
MB

Doesn't work on arch

Following your guide doesn't work on Arch Linux.
Neither the repo nor the setup work.
I've played with the configs but it seems to be a selenium thing,
since the connection is always refused. I can start the selenium server manually though.

the step by step guide can be improved

I noticed it took me a few minutes to figure out (by going to the original folder) how to properly name the guinePig.js in the test/e2e folder in section "Installation (in details)" part "8) Create Your Nightwatch Test".

Not using env files

Hi,

I used the quick version of the tutorial - cloning the repo locally etc. However when I try and run my tests I get an error:
WARNING: env2 was required to load an .env file: learn-nightwatch/.env NOT FOUND!

If I comment out the require('env2')('.env') at the top of the nightwatch.conf.js I still get an npm ERR! although it no longer mentions the missing file. However after i run the npm test command I can see that it's running nightwatch --env local.

How do I resolve this?

SyntaxError when Running nightwatch.conf.BASIC.js File

I am able to get as far as Step 7 on running nightwatch on my own project, however, when I go to run the nightwatch.conf.BASIC.js file it throws a SyntaxError: Unexpected token <
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3

What exactly do I do to fix this? I do not know where to go from here or what that means.

Thank you in advance for helping me.

Firefox Crashes

When attempting to run the tests with firefox we see:
nightwatch-firefox-crash

Note: the same test run flawlessly in Chrome.

Step-by-Step tutorial is missing a couple steps

It's a little unclear what we should do in our own project to get it setup. Perhaps this is assumed by veterans of nightwatch, but I think it'd be great to spell it out in the readme.

Following the install of both selenium-download and nightwatch (via the steps mentioned):

  • Where do I put the nightwatch.conf.BASIC.js file? (Answer: within the same directory you ran the previous commands. You could start by copying it from node_modules\selenium-download.)
  • Run node nightwatch.conf.BASIC.js to download selenium for the first time.

Perhaps something along these lines could be added to the main readme?

Page objects

Page objects allow the user to create custom selectors and sequences of selenium commands for a particular page on the site. This allows us to keep the tests dry while keeping the namespacing the commands/selectors to a particular page.

This feature is quickly becomes useful as the size of the tests grows.

http://nightwatchjs.org/guide#page-objects

happy to write this up with examples and make a pull

Screenshot Viewer > Basic Routing

As a person reviewing the screenshots,
When I click on an image I want the route (hash) to change to reflect the image,
this will allow me share a link to a specific screenshot.

Nightwatch File Structure

I have created selenium tests before, but just page objects, test specs and parameters, I've never setup a new project from scratch. I'm having troubles figuring out what my file structure should look like.

Ideally, I'd like to be able to write multiple test suites for different web apps. So my current file structure looks like this starting off

Sandbox >> Test Suite Web App A
Test Suite Web App B

From here, what should be within each Test Suite and at what file level?
For instance, should node_modules one folder level in from the Test Suite: Sandbox >> Test Suite Web App A >> node_modules?

Should my nightwatch folder be in my node_modules folder?

The nightwatch folder contains bin, examples, index.js, lib, license.md, package.json and READEME.md, are these all in the correct order or do any of these need to be within the A Test Suite folder?

Where should the selenium.jar file go?
Where should package.json go?
Where should nightwatch.conf.js go?

I want to use the example tests that come with the package to play around with first, should I treat these as their own test suite?

Does each test suite folder need to have the same setup?

I know there are a lot of questions here, I really appreciate all the help on this.

Nightwatch Installation

When you install nightwatch on your localhost you will see many dependencies:

learn-nightwatch $ npm install nightwatch --save-dev
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
[email protected] /code/learn-nightwatch
โ””โ”€โ”ฌ [email protected]
  โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ””โ”€โ”ฌ [email protected]
  โ”‚   โ””โ”€โ”€ [email protected]
  โ”œโ”€โ”€ [email protected]
  โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
  โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ””โ”€โ”€ [email protected]
  โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ””โ”€โ”€ [email protected]
  โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ””โ”€โ”€ [email protected]
  โ”œโ”€โ”€ [email protected]
  โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ””โ”€โ”€ [email protected]
  โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ””โ”€โ”€ [email protected]
  โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚ โ””โ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”‚   โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
  โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
  โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
  โ”‚ โ””โ”€โ”ฌ [email protected]
  โ”‚   โ””โ”€โ”ฌ [email protected]
  โ”‚     โ”œโ”€โ”€ [email protected]
  โ”‚     โ””โ”€โ”€ [email protected]
  โ””โ”€โ”€ [email protected]

demo test failed

Results for: Demo test GitHub
โˆš Element was visible after 67 milliseconds.
ร— Testing if element contains text: "do what you love". - expected "do what you love" but got: "Skip to content

Extract selenium install logic to a specific module

Currently, the whole nightwatch.conf.js is set as a postinstall hook in package.json. But the only reason to do that -as far as I understand- is to ensure that selenium gets downloaded. This is pretty misleading since people just copypasting the configuration object from nightwatch.conf.js to their own config file as a template would not get the tests to run, since selenium would not be downloaded.

Also, this way is just more clear what the postinstall hook is about, and concerns are better separated between the nightwatch configuration and the selenium install.

Example not working for firefox

Firefox version: 47.0.1 (and 48.0.1)
Selenium version: 2.53.0

If you run:

git clone https://github.com/dwyl/learn-nightwatch.git && cd learn-nightwatch

Then change lines 51 - 58 from:

"browserName": "chrome",
        "chromeOptions": {
          "args": [
            `Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46
            (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3`,
            "--window-size=640,1136" // iphone 5
          ]
        },

To:

browserName: 'firefox'

Then run npm test and you get just a firefox browser and the test hangs

Saving screenshots how/where to?

Saving screenshots is the only way we have of confirming that the UI is what we expect it to be.
(yes, the fact that the assertions worked is re-assuring, but the whole point of front-end testing is visual assurance)

We need to decide where to save our images...

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.