Giter Club home page Giter Club logo

clinical-nightwatch's Introduction

clinical:nightwatch

NOTICE: This package is being deprecated in favor of the StarryNight utility, which resolves most all of the configuration and launching issues that this package had.
starrynight.meteor.com

=================== Ultra-easy acceptance testing for your Meteor app with Selenium and Nightwatch.

Prezi View the Prezi on Nightwatch Architecture for Meteor Applications

Size Warning!

This package is 11mb large, because of the Selenium browser automation server, and will increase the overall size of your application by 11mb! The good news, however, is that this extra weight won't be shipped down to the client, and is simply bloats the bundle file and adds an unnecessary file to the server.

Table of Contents

Quickstart

Step 1 - Configure the Filesystem
Begin by creating the following files in your /tests directory. For now, the contents of global.json can be an empty json object {}.

/tests/nightwatch/globals.json
/tests/nightwatch/logs
/tests/nightwatch/commands
/tests/nightwatch/assertions
/tests/nightwatch/walkthroughs

terminal-a$ chmod -R 777 tests/nightwatch

Step 2 - Add Nightwatch To Your Application

Nightwatch works a lot like when you run the meteor mongo command. That is, you need to have an instance of meteor running for it work. More specifically, Nightwatch will attach itself to the compiled version of your app in the .meteor/local/build directory, and spin up a mirror copy of your app to test with. Your other app doesn't actually have to be running, but it does need to be run at least once before.

# go to the root of your application
terminal-a$  cd myappdir
terminal-a$  meteor add clinical:nightwatch

# Go to the root of your application
terminal-a$ cd myappdir

# run the leaderboard application
terminal-a$ meteor

Step 3 - Set up the Launch Script and Run Nightwatch

Copy the run_nightwatch.sh script into your application root. Once you do that, make sure your permissions are set correctly.

# In the same way that we run 'meteor mongo' in a separate terminal while our application is already running,
# we want to open up a new terminal, and run nightwatch
terminal-b$ chmod -R 777 .meteor
terminal-b$ chmod 777 run_nightwatch.sh
terminal-b$ ./run_nightwatch.sh

# you might want to do something clever like pass in arguments and run specific tests
terminal-b$ ./run_nightwatch.sh -t tests/nightwatch/leaderboard.js

# of run only the tests that have been tagged with a specific label
terminal-b$ ./run_nightwatch.sh --tag foo

Write Your First Acceptance Test

Check out this super simple syntax for writing acceptance tests. All you need to do is copy the following code into a file in the /tests directory, and Nightwatch will parse it accordingly.

// tests/helloworld.js

module.exports = {
  "Hello World" : function (client) {
    client
      .url("http://127.0.0.1:3000")
      .waitForElementVisible("body", 1000)
      .assert.title("Hello World")
      .end();
  }
};

// tests/google.js
module.exports = {
  tags: ["foo"],
  "Demo Test Google" : function (client) {
    client
      .url("http://www.google.com")
      .waitForElementVisible("body", 1000)
      .assert.title("Google")
      .assert.visible("input[type=text]")
      .setValue("input[type=text]", "nightwatch")
      .waitForElementVisible("button[name=btnG]", 1000)
      .click("button[name=btnG]")
      .pause(1000)
      .assert.containsText("#main", "The Night Watch")
      .end();
  }
};

Resetting the Database For New Runs

You may notice that your database has gotten out of sync with your tests. Don't worry, as that's normal. The easy thing to do is just reset your database. But you'll eventually need to write your tests so they don't destructively modify your database, or you'll need to create tearUp and tearDown methods, or set up a testing database, or any number of other activities to manage your test data.

# if you want to rerun the acceptance tests, go back to the first terminal
# and be sure to reset the database
terminal-a$ ctrl-c
terminal-a$ meteor reset
terminal-a$ meteor

Configuring a Shared Testing Database

With bigger test suites, you'll maybe want to set up an entire test database, in which case you'll want to attach your Nightwatch instance against a test database. That's probably getting past the extent of this README, but here's a quick reference to how to do that...

# launch your application against a test database
terminal-a$ MONGO_URL=mongodb://127.0.0.1:27017 PORT=3000 node .meteor/local/build/main.js

Advanced Topics - Custom Commands, Assertions, and Logs

Custom Commands
Using Globals.js to Define Test Data
File Upload Dialog
Download File Assertion
Testing Minimongo and Browser Console with execute()
Code Injection using execute()
Connecting to SauceLabs

Licensing

MIT License. Use as you wish, including for commercial purposes.

clinical-nightwatch's People

Contributors

awatson1978 avatar

Stargazers

 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

clinical-nightwatch's Issues

Permission issues

Why in your instructions you always say to do chmod 777?
Is this really necessary and recommended? I would never want to do this on files that I execute!
There must be a safer way to work. Does Nightwatch run as some kind of dummy user or something? Why not just work with my own user permissions (chmod 755 or even 700)?

Also, these lines in run_nightwatch.sh don't make much sense:

TODO cd into the app dir as PWD

echo "Changing file permissions..."

Setup: changing file permissions"

mkdir -p .meteor/local/build/programs/server/assets/packages/clinical_nightwatch
chmod +x .meteor/local/build/programs/server/assets/packages/clinical_nightwatch/launch_nightwatch*.sh
chmod +x .meteor/local/build/programs/server/assets/packages/clinical_nightwatch/selenium/selenium-server-standalone-2.44.0.jar

You're creating a dir and immediately assuming there are files inside it? The script crashed at this point for me....

Nightwatch gets automatically removed every buildcycle?

Basically, I have to manually create a node-modules directory in the .meteor/build directory, otherwise the nightwatch runner fails to install the npm package. This directory gets removed every time the application gets rebuilt, making it quite an irritating process; also, re-pulling the npm package every time seems to be pretty inefficient.

Might it be a better solution just to require Nightwatch to be installed globally for the app to run?

Migration plan?

Is http://clinical.meteor.com/ hosted on meteor's free tier? If so, it needs to be migrated asap before March 25th noon Pacific time. I'm thinking about hosting a migration party early Friday morning :) j/k ... thinking about it.

Custom commands and assertions

Hi!

A month ago we talked about the possibility to add custom assertions and commands.
I just want to ask when these changes could be integrated?

Is it possible to run a Meteor.call method from within a nightwatch command?

I would like to try and run a Meteor call from a nightwatch command: something like this:

exports.command = function(taskId, callback) {
  var self = this;

  this.execute (
    function(data) { 
      Meteor.call('resolveThingForMe', data);
      return true;
    }, 

    [taskId],

    function(result) {
      if (typeof callback === "function") {
        callback.call(self, result);
      }
    }
  );

  return this;
};

Is this possible at all?

Selenium fails to connect by default

I'm not sure if this is a mis-configuration, but following the guide, Firefox starts and maintains a blank page, indicating that the Selenium connection is failing. I manually grabbed the Selenium jar from the project's website and put it in my project's root, following the Nightwatch instructions, and it worked after that (although I had to re-write the runner bash file because the default Nightwatch config tries to open IE, which is unfortunately not available on Linux...)

Should this be reflected in the docs or am I doing something wrong?

browerstack?

How to plug browserstack into this?

(I'll update this issue myself as I learn more about it. Not that much time for that right now - although I would like to use this with browserstack right now ;)

Seems to just run and never complete

➜ tlfbz git:(dev) ✗ mkdir tests/nightwatch
➜ tlfbz git:(dev) ✗ mkdir tests/nightwatch
mkdir: tests/nightwatch: File exists
➜ tlfbz git:(dev) ✗ ./run_nightwatch.sh
Setting variables...
Checking user defined options...

Parsing options...
Changing file permissions...
Looking for Nightwatch executables...
Stitching together command to run: .meteor/local/build/node_modules/nightwatch/bin/nightwatch -e default -c .meteor/local/build/programs/server/assets/packages/clinical_nightwatch/nightwatch_from_app_root.json
Running Nightwatch...

Starting selenium server... started - PID: 23571

[Nightwatch Run] Test Suite

Running: Demo test Google

( after 18 mins... )

Running: Demo test Google

It seems to just stop there and not actually do anything more than open firefox.
The same happened when I installed nightwatch with velocity.
I did notice that you ran under root in the README, I however prefer not to and just gave myself rwx for run_nightwatch.sh if that is a potential problem
Also in the README it says put the files in the root of tests, however when I ran it asked me to put it into a test/nightwatch

Thanks in anticipation of assistance!

How to approach the UI workflow test which involves multiple URL links

Abigail,

Thanks a lot for creating infrastructure for acceptance testing.

I have setup nightwatch framework for acceptance testing and I am planning to write test to check where

  1. User logs in to the account as admin
  2. Go to a specific route and performs UI actions

Can you please suggest me a way to implement the workflow?

How to make PhantomJS default

@awatson1978
My preference is Casperjs, but I see that the project is inactive. So I'm trying this, but there's more config and learning curve than I expected.
Is there a reason Phantomjs is not the default here (and bundled with)? Also, wish there was some documentation on changing to Phantom if that is possible.
FYI, my main use is for CI, so I wish we didn't have to manage the dependencies here.

Can't run all tests

I have 6 submodels for test and nightwatch run only 5 of them. I tried change the order of submodels and all the time the last one won't launch

Cannot run example with Firefox 33 on Ubuntu

I'm trying to get the package running with the example tests from the readme. I was confused on first impression that sudo was required to run the tests. That helped and was able to get an instance of firefox to pop up with the included selenium 2.42.0 jar but no tests ran. It looks like the latest 2.44.0 must be installed for Firefox 33 support so I downloaded the jar and updated the package.js, nightwatch_from_app_root.json and launch_nightwatch_from_app_root.sh (displayed below)

#!/bin//bash
# run this file from your application's root directory

echo "changing file permissions"
chmod +x .meteor/local/build/programs/server/assets/packages/clinical_nightwatch/launch_nightwatch*.sh
chmod +x .meteor/local/build/programs/server/assets/packages/clinical_nightwatch/selenium/selenium-server-standalone-2.44.0.jar

echo "installing nightwatch in .meteor/local/build"
  cd .meteor/local/build
  npm install [email protected]
  cd ../../..

echo "running nightwatch"
   .meteor/local/build/node_modules/nightwatch/bin/nightwatch -c .meteor/local/build/programs/server/assets/packages/clinical_nightwatch/nightwatch_from_app_root.json $1 $2

Now it hangs trying to start selenium:

$ ./run_nightwatch.sh --verbose
changing file permissions
installing nightwatch in .meteor/local/build
[email protected] node_modules/nightwatch
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected])
running nightwatch
Starting selenium server... 

Have you had any luck running with firefox 33 / selenium 2.44.0?

Looks like the jar works fine:

$ java -jar .meteor/local/build/programs/server/assets/packages/clinical_nightwatch/selenium/selenium-server-standalone-2.44.0.jar 
16:47:45.772 INFO - Launching a standalone server
16:47:45.949 INFO - Java: Oracle Corporation 24.65-b04
16:47:45.950 INFO - OS: Linux 3.13.0-39-generic amd64
16:47:46.027 INFO - v2.44.0, with Core v2.44.0. Built from revision 76d78cf
16:47:46.264 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match with current platform: LINUX
16:47:46.495 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
16:47:46.497 INFO - Version Jetty/5.1.x
16:47:46.498 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
16:47:46.499 INFO - Started HttpContext[/selenium-server,/selenium-server]
16:47:46.500 INFO - Started HttpContext[/,/]
16:47:46.631 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@22729305
16:47:46.632 INFO - Started HttpContext[/wd,/wd]
16:47:46.649 INFO - Started SocketListener on 0.0.0.0:4444
16:47:46.650 INFO - Started org.openqa.jetty.jetty.Server@52675236

Nightwatch does throw an error if the port is occupied:

$ ./run_nightwatch.sh --verbose
changing file permissions
installing nightwatch in .meteor/local/build
[email protected] node_modules/nightwatch
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected])
running nightwatch
Starting selenium server... ERROR There was an error while starting the Selenium server:
16:52:15.416 INFO - Launching a standalone server
Setting system property webdriver.chrome.driver to selenium/chromedriver
16:52:15.617 INFO - Java: Oracle Corporation 24.65-b04
16:52:15.617 INFO - OS: Linux 3.13.0-39-generic amd64
16:52:15.653 INFO - v2.44.0, with Core v2.44.0. Built from revision 76d78cf
16:52:15.808 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match with current platform: LINUX
16:52:16.030 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
16:52:16.032 INFO - Version Jetty/5.1.x
16:52:16.033 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
16:52:16.035 INFO - Started HttpContext[/selenium-server,/selenium-server]
16:52:16.035 INFO - Started HttpContext[/,/]
16:52:16.164 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@22729305
16:52:16.165 INFO - Started HttpContext[/wd,/wd]
16:52:16.195 WARN - Failed to start: [email protected]:4444
Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or some other service is.
    at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:491)
    at org.openqa.selenium.server.SeleniumServer.boot(SeleniumServer.java:300)
    at org.openqa.selenium.server.SeleniumServer.main(SeleniumServer.java:245)
    at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:97)

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.