Coder Social home page Coder Social logo

docker-grid-nightwatch's Introduction

A Dockerized Selenium Grid with Nightwatch

I built this project to quickly provision a dockerized environment for running UI tests against a dockerized app. It employs a dockerized Selenium Grid, which yields a far more cost-effective CI solution compared to purchasing and maintaining n dedicated machines.

This project is geared toward a Node.js audience, meaning I've included npm scripts as wrappers for the docker-compose commands. Hopefully, once you've completed the initial setup, you won't have to recall any docker commands. ๐Ÿ˜ƒ

Nightwatch serves as the testrunner. It is automatically provisioned in the nightwatch docker image, which you can easily customize in the included nightwatch.json file.

Dependencies (Mac OSX)

  1. dinghy <--- You'll love it!!

If you haven't already followed dinghy's advice by adding the specified environment variables to your .bashrc file or equivalent, you need to do that now.

You'll know everything is working when you execute these commands...

$ dinghy up
$ dinghy status

... and you see this:

$ dinghy status
  VM: running
 NFS: running
FSEV: running
 DNS: running
HTTP: running

Your environment variables are already set correctly.
  1. docker-compose: $ brew install docker-compose
  2. a copy of this repo on your machine
  3. a docker image of the app under test (optional if you want to skip ahead)

By default the project will use a bare-bones Sinatra web app as the app under test, so if you'd like to see this project in action before adding your app, go ahead and skip to the "How do I execute the tests?" section.

Setup

Add the docker image of the app under test to the docker-compose.yml file. Be sure to define its virtual URL (a default is provided). For example:

web:
  image: app-under-test:latest
  environment:
    VIRTUAL_HOST: app.under.test

That was easy!

NOTE: VIRTUAL_HOST is your app's URL against which Nightwatch will execute the tests. It can be whatever you want. If you change it, be sure to replace the launch_url value located in the nightwatch.json file.

If you're not sure how to create or pull a docker image, I recommend working through the official Docker tutorial located on their website.

How do I execute the tests?

Start dinghy if it isn't already running (you can check with $ dinghy status):

$ dinghy up

Start the Selenium hub, the app under test, and the Selenium browser nodes:

$ npm start

Execute the tests with Nightwatch:

$ npm test

When you're done, stop and remove the docker containers:

$ npm stop

Can I view the Selenium grid console?

Yep! After having started the Selenium hub and nodes ($ npm start), open a browser and go to http://selenium.hub.docker, then click the 'console' link.

A test is failing. How do I debug it?

Start the Selenium hub, the app under test, and the Selenium debug browser nodes:

$ npm run debug_start

View the chrome debug node via VNC (password: secret):

$ open vnc://node.chrome.debug.docker

View the firefox debug node via VNC (password: secret):

$ open vnc://node.firefox.debug.docker

Next execute the Nightwatch tests against the debug nodes:

$ npm run debug_test

Again, once you're finished:

$ npm stop

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.