Giter Site home page Giter Site logo

nightwatchjs / nightwatch Goto Github PK

View Code? Open in Web Editor NEW
11.7K 256.0 1.3K 53.06 MB

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack

Home Page: https://nightwatchjs.org

License: MIT License

JavaScript 95.98% EJS 0.31% TypeScript 3.62% Gherkin 0.05% Vue 0.03% Shell 0.01%
nightwatch javascript nodejs selenium webdriver end-to-end-testing automated-testing nightwatchjs chromedriver w3c-webdriver

nightwatch's People

Contributors

aberonni avatar ajpetersons avatar automatedtester avatar ayush-vish avatar beatfactor avatar candrews avatar davidlinse avatar dharin-shah avatar dikwickley avatar garg3133 avatar gravityvi avatar harshit-bs avatar iabw avatar iberdinsky-skilld avatar itsspriyansh avatar jjsquillante avatar lloiser avatar micahlc avatar mildmojo avatar nicopennec avatar oanabotezat avatar priyanka0613 avatar prudhvi22 avatar reallymello avatar senocular avatar sethmcl avatar swrdfish avatar topperfalkon avatar vaibhavsingh97 avatar yashpratp983 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

nightwatch's Issues

Support of XPath selectors ?

Regarding the docs it's possible to use either css or xpath selectors to find elements. Allhough it looks like that the css selector is hard coded all-over the place in commands and assertions ?
e.g.

// lib/selenium/assertions/elementPresent.js
return this.client.element("css selector", cssSelector, function(result) {}

Is there already any support for XPath selectors ?
regards
~david

Help with custom command

Hi there,

I'm trying to test a whole signup functionality, the typical two steps signup, you need to fill small form, get an email with a link and fill the second big form with more personal data. I'm building a very very very custom command that connects to a gmail inbox, retrieves a message, extract the link to the second form and starts the test for the second form.

The code for my command is as follows:

exports.command = function(callback) {

    var
        self = this,
        Imap = require("imap"),
        MailParser = require("mailparser").MailParser,
        inspect = require("util").inspect,
        jsdom = require("jsdom");

    var imap = new Imap({
        user: 'XXXXXXXXXX',
        password: 'XXXXXXXXXX',
        host: 'imap.gmail.com',
        port: 993,
        tls: true,
        tlsOptions: { rejectUnauthorized: false }
    });

    function openInbox(cb) 
    {
        imap.openBox('INBOX', true, cb);
    }

    function getConfirmationMessage() 
    {

        imap.once('ready',function(){
            openInbox(function(err, box) {
                if (err) throw err;

                imap.search(['ALL',['FROM','[email protected]'],['SUBJECT','Activa tu cuenta de email marketing gratis']], function(err,results) {

                    if (err) throw err;

                    var fetch = imap.fetch(results, { bodies: '' });

                    fetch.on('message', function(msg) {

                        var mailparser = new MailParser({ defaultCharset: 'utf-8'});

                        mailparser.on("end", function(mail_obj) {
                            var html = mail_obj.html;

                            jsdom.env(html,["http://code.jquery.com/jquery.js"], function(errors,window) {

                                var hash_link = window.$('a').attr("href");

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

                            });

                        });

                        msg.on('body',function(stream,info) {

                            stream.on("data",function(chunk) {
                                mailparser.write(chunk.toString('utf-8'));
                            })

                        });

                        msg.on("end",function() {
                           mailparser.end();
                        });

                    });

                    fetch.once('error', function(err) {
                        console.log('Fetch error: ' + err);
                    });

                    fetch.once('end', function() {
                        imap.end();

                    });

                });

            });
        });

        imap.once('error', function(err) {
            console.log(err);
        });

        imap.connect();

    }

    getConfirmationMessage();

    return this;

}

and my test looks like this:

module.exports = {
    'MDirector - Signup - Step 1': function(browser) {
        browser
            .url('http://2013.mdirector.dev.antevenio.com/')
            .waitForElementVisible('body', 1000)
            .waitForElementVisible('a[id=signupBtn]', 1000)
            .click('a[id=signupBtn]').pause(1000)
            .waitForElementVisible('input[name=name]',1000)
            .waitForElementVisible('input[name=email]',1000)
            .waitForElementVisible('button[id=submit]',1000)
            .setValue('input[name=name]','MDirector Testing Account')
            .setValue('input[name=email]','[email protected]')
            .click('input[name=terms')
            .click('button[id=submit]')
            .waitForElementVisible('div[id=success]',5000)
            .assert.containsText('#success','Su registro se ha completado con exito')
            .end();
    },
    'MDirector - Signup - Step 2': function(browser) {
        browser
            .checkImapInbox(function(url) {

            })
    }
};

Can I use the returned url in the callback to feed the browser.url and start a new test suite inside or outside the callback?

Besides this, I'm getting an error from nightwatch when I try to use the command, my command file is called checkImapInbox.js inside the mw_custom_commands directory, that is in my project root directory. I'm using a grunt task, via grunt-nightwatch to run my tests, my Gruntfile.js section for nightwatch looks like follow:

        nightwatch: {
            options: {
                test_settings: {
                    chrome_driver: "/usr/local/bin/chromedriver",
                    silent: true,
                    desiredCapabilities: {
                        browserName: "chrome",
                        platform: "LINUX",

                    }
                },
                settings: {
                    src_folders: ["tests/integration/frontend"],
                    output_folder: "public/test/integration/reports",
                    custom_commands_path: "./nw_custom_commands",
                    selenium: {
                        start_process: true,
                        server_path: "/usr/local/bin/selenium-server-standalone-2.40.0.jar",
                        log_path: false,
                        host: '127.0.0.1',
                        port: 4444
                    }
                },
                standalone: true,
                jar_path: "/usr/local/bin/selenium-server-standalone-2.40.0.jar"
            }   
        }

and the error I'm getting from nightwatch is:

An error occured while running the test:
TypeError: Object #<Nightwatch> has no method 'checkImapInbox'
    at Object.module.exports.MDirector - Signup - Step 2 (/home/diego/Code/mdirector.backend/tests/integration/frontend/signup-step1.js:22:14)
    at clientFn (/home/diego/Code/mdirector.backend/node_modules/grunt-nightwatch/node_modules/nightwatch/runner/run.js:149:19)
    at Object.setUp (/home/diego/Code/mdirector.backend/node_modules/grunt-nightwatch/node_modules/nightwatch/runner/run.js:52:35)
    at /home/diego/Code/mdirector.backend/node_modules/grunt-nightwatch/node_modules/nightwatch/runner/run.js:152:13
    at next [as _onTimeout] (/home/diego/Code/mdirector.backend/node_modules/grunt-nightwatch/node_modules/nightwatch/runner/run.js:103:11)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

Hope you can help me.

Thanks in advance.

Diego.

Specifying different launch_url in test_settings has no effects

I'm trying to call a different group of settings on my Windows CI server.

When I call

node nightwatch.js --env CI

it's still hitting the url of the default. It seems to be picking up the other settings because if I omit the chrome configuration at the end it starts looking for firefox.

{
  "src_folders" : ["tests"],
  "output_folder" : "../../../ui-tests",
  "custom_commands_path" : "",

  "selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444  
  },

  "test_settings" : {
    "CI" : {
      "launch_url" : "http://bob",
      "port"  : 4444,
      "silent": true,
      "firefox_profile": false,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },
    "default" : {
      "launch_url" : "http://localhost",
      "port"  : 4444,
      "silent": true,
      "firefox_profile": false,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

Start two browsers

@beatfactor
Do you know if there is a way to start 2 browsers ? I mean with only one command
For example if I need to test a chat, is there a way to test it with a second client ?

I did it with selenium but didn't find a way to do it using nightwatch

Is this only for headless automation testing?

Is there any way that I can run this test opening the browsers (chrome,safari,firefox,IE) and then run the test scripts. and if there is a way, can you please post in the website a tutorial on how to use it? Thanks!

How to catch errors with assertions

I need to loop through an array of selectors and for each selector I need to ensure the element is present in the DOM. If the element is not present, I need a way to catch those errors in order to accumulate them in a list.

Am I able to do that without modification to the code? If not, I feel like it would require a change to the assertions to allow for an error event to be emitted. Does this sound correct?

finishCallback undefined

Running with a simple directory structure to test ease of use:

tests
-- test.js
nightwatch (invokes runner)
settings.json

settings.json:

{
  "src_folders" : ["tests"],
  "output_folder": ["tests"],

  "selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444  
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "firefox_profile": false,
      "chrome_driver": "/usr/bin",
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

nightwatch:

#!/usr/bin/env node
require('nightwatch/bin/runner.js');

test.js:

module.exports = {
  "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();
  }
};

The tests pass OK, but an error is thrown onexit:

/Users/scalvert/Dev/nightwatch/node_modules/nightwatch/runner/run.js:285
              finishCallback();  
              ^
TypeError: undefined is not a function
    at /Users/scalvert/Dev/nightwatch/node_modules/nightwatch/runner/run.js:285:15
    at ChildProcess.<anonymous> (/Users/scalvert/Dev/nightwatch/node_modules/nightwatch/runner/run.js:160:23)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at Process.ChildProcess._handle.onexit (child_process.js:789:12)

Is something missing in my setttings.json file? It seems a finishCallback is never passed in to the run function in run.js.

How to organize tests in real life ?

Hello,

I am starting to learn how to use Nightwatch.js and I definitely find the syntax very straightforward !

After writing my first and complex test, and I am wondering how I should do to organize two tests that are using the same context :

Let's say I am using the same selector "button[name=btnG]" as in your Google example in another test function. It would be nice to declare a variable outside the "Demo test Google" function that could be used in that second test function.

Is there any recommended best practice ?

Problem creating custom command

I'm trying to add a custom command called waitForCondition. That command uses the execute action to execute some code on the target browser, and return once that condition is met. Here's how it looks so far:

var Protocol = require('../protocol.js'),
    util = require('util'),
    events = require('events');

function CommandAction() {
  events.EventEmitter.call(this);
  this.startTimer = null;
  this.cb = null;
  this.ms = null;
  this.selector = null;
};

util.inherits(CommandAction, events.EventEmitter);

CommandAction.prototype.command = function(condition, milliseconds, callback) {
  if (milliseconds && typeof milliseconds != 'number') {
    throw new Error('waitForCondition expects second parameter to be number; ' + 
      typeof (milliseconds) + ' given')
  }
  this.startTimer = new Date().getTime();
  this.cb = callback || function() {};
  this.ms = milliseconds || 1000;
  this.condition = condition;
  this.check();  
  return this;
}

CommandAction.prototype.check = function() {
  var self = this;
  Protocol.actions.execute.call(this.client, this.condition, function(result) {
    var now = new Date().getTime();
    if (result.status === 0) {
        self.cb(result.value);  
        var msg = "Condition satisfied after " + (now - self.startTimer) + " milliseconds.";
        self.client.assertion(true, result.value, true, msg, true);
        return self.emit('complete');
    } else if (now - self.startTimer < self.ms) {
      setTimeout(function() {
        self.check();
      }, 500);  
    } else {
      self.cb(false);
      var msg = "Timed out while waiting for condition after " + self.ms + " milliseconds.";
      self.client.assertion(false, false, false, msg, true);
      return self.emit('complete');  
    }
  });
};

module.exports = CommandAction;

I'm trying to determine the best way to test this command. I'd like to write a nodeunit test in my fork, but don't see any tests for execute itself, or for that matter where execute is defined. Can you point me in the right direction?

Of course, once I manage to get this working I'll open a PR.

selenium grid-server exception during attempt to send DELETE request

When running the following test against a selenium grid-hub/ -node setup the browser stays open and the selenium-hub logs the an exception.

 module.exports = {
    'should simply open and close': function (browser) {
        browser
          .url('http://github.com/beatfactor/nightwatch')
          .pause(1000)
          .end();
    }
 };

For the log output of the selenium-hub and nightwatch (with --verbose option) these two gits selenium-hub.log and nightwatch.log

Versions: (OSX 10.6.8)

$ node --version #=> 0.10.21
$ selenium-server-standalone.2.39.0.jar

Running nightwatch version: v0.3.1 (d942ed9)

If you need further infos please let me know.
regards
~david

Screenshots not saved into missing folders

When saving screenshots with the screenshots 'enabled' flag, if you specify a folder that does not exist, Nightwatch fails to create the folder. May be related to issue #55

Windows 7 x64, NW version 0.3.7

user defined Path to configuration file not working

On MAC and WIN (GIT BASH terminal)

./nightwatch -c ./settings-other.json
# error: 
ERROR There was an error while starting the test runner:

Error: No testing environment specified.
    at parseTestSettings (c:\dev\prj\git-repos\asgard.js\node_modules\nightwatch\bin\runner.js:118:11)
    at Object.<anonymous> (c:\dev\prj\git-repos\asgard.js\node_modules\nightwatch\bin\runner.js:156:25)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (c:\dev\prj\git-repos\asgard.js\nightwatch:2:1)
    at Module._compile (module.js:456:26)

Error in callbacks doesn't trigger the suite to fail

I've noticed that triggering an error in a callback doesn't fail the build:

this code (note the INDEXOF method)
screenshot 2014-02-26 12 48 02

actually succeed the build
screenshot 2014-02-26 12 48 21

I fixed it using a wrapper around every callback like this:

function tryCatch(callback) {
    return function(result){
        try{
            callback(result);
        } catch(e) {
            this.assert.ifError(e);
            console.log(e.stack);
        }
    };
};

but it would be nice to have it working out of the box

Cryptic error when no java installed

I configured nightwatch to manage the selenium server like this:

"selenium" : {
  "start_process" : true,
  "server_path" : "selenium-server-standalone-2.40.0.jar",
 // ...

and then I ran the following shell script without arguments:

#!/usr/bin/env node
require('nightwatch/bin/runner.js');

It gave me the following output

Starting selenium server... 
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:980:11)
    at Process.ChildProcess._handle.onexit (child_process.js:771:34)

It took me a while to figure out that java wasn't installed on my machine. It would be great if nightwatch displayed an error like "java not found".

Iframe Elements

I'm having trouble selecting elements within iframes. Is this possible?

navigate away from page with/without unload handle

client.url(....) will fail if unload handler
client.url(...).accept_alert() will be OK on page with unload handler
client.url(...).accept_alert() will report error on page without unload handler, but will go on

how to check if alert is present or suppress errors on accept_alert ???

thanx a lot lot

Move output_folder to test_settings, group test runs by date/time

@jordan112 and I were talking about the junit output. I can make the changes but wanted to get some feedback first. If the output_folder was moved to the test settings we could have setting specific output. This would be best if we wanted to run tests in multiple browsers but wanted to have the output specific to each browser/test config.
Also, if we set a date/time variable at the start of the test run in runner/run.js we could have testing history. So the folder structure would looks something like:
output_folder/2014-02-24-15-20-45/test_group/test

Assert current URL and/or path?

Is it possible to assert that the browser is currently on a specific URL or path?

Can obviously work around this by asserting that page specific elements are present, but it would be nicer to assert against the current URL or path, in order to isolate a spec to test the redirect only.

(Thanks by the way, nightwatch is proving really useful).

Chrome driver for selenium

Hello @beatfactor

I found a problem with chromedriver. For fix this problem I added a new line to your code. Also I added a new property in settings.json file. For example:

Settings,json:

"test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "port"  : 4444,
      "silent": true,
      "firefox_profile": false,
      "chrome_driver": "C:/tools/chromedriver.exe",
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }

And in the runner/run.js:

  if (test_settings.firefox_profile) {
    cliOpts.push('-Dwebdriver.firefox.profile=' + test_settings.firefox_profile);    
  }

  if (test_settings.chrome_driver) {
    cliOpts.push('-Dwebdriver.chrome.driver=' + test_settings.chrome_driver);
  }

I think that those additions will be very useful.

Unable to access jarfile

I followed the instructions for windows but receive the error: Unable to access jarfile ./bin/selenium-server-standalone-2.39.0.jar

Why is it trying to find it at ./bin? I tried adding it to my classpath, but the getting started instructions didn't take me far enough, I am new to node, so if this is normal node stuff that I don't understand please forgive me.

How to mock your backend while using Nightwatch.js ?

Hi guys,

Currently developing a frontend application using AngularJS which connects to a backend server, I am using Nightwatch.js to check my frontend interfaces.

I would like my frontend to display fake data and think about using a mock backend. What mock server would you recommand ?

I started using nock which looks very promising, but I am facing some problem. Nock does not intercepts my HTTP requests to my backend. It might be due to selenium which proxy requests from my local machine.

Any thoughts about how to achieve this ?

Thanks,

Change settings.json file name to nightwatch.json

Similar to a change the Bower project went through. They originally called their config file components.json but have since changed it to bower.json. bower/bower#39

I was looking to embed Nightwatch in to an existing project and felt the settings.json file name was too generic. Yes with the -c arg I can change the config file's name, but for visibility and promtion of the project's brand I think nightwatch.json should become the standard.

When someone sees a nightwatch.json file in a project they'll know the E2E testing is probably in place. When they see a settings.json they'll wonder what that is.

Thank you.

Advanced CSS selectors eg. :contains('John')

@beatfactor - I would like to suggest to add support for extended CSS selector for selecting elements with specific text. Similar to JQuery http://api.jquery.com/contains-selector/. It would be usefull for testing worflow. Eg. for testing of creating / updating / deleting records.

browser.click("ul li a:contains('Record')");

or

browser.click("ul li a[text='Record']");

Maybe XPath selectors could handle it?
Thank you!
Btw. Nightwatch.js is cool :-)

nightwatch generates results for non test `js` files

I have a utility.js file that contains utility functions. My other tests require this script. Nightwatch doesn't detect that there are no tests in this file and produces a utility.xml in the results folder.

versioning

npm is being updated, but github doesn't have any of the version tags. if you're using npm version to bump the versions, could you also run git push --tags to make sure the different versions can be inspected on github? given that the docs aren't always kept up to date with the head of master, it would also be nice to see in the docs which version they are referencing.

google sample fails on OSX and chrome (not 20)

./nw -t ./git-version/examples/tests/google.js --verbose
Starting selenium server... started - PID: 59852
Running tests

[ google module ]

Running: step one
Setting up...
INFO Request: POST /wd/hub/session

  • data: {"desiredCapabilities":{"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform":"ANY"},"sessionId":null}
  • headers: {"Content-Type":"application/json","Content-Length":129}
    INFO Response 200 POST /wd/hub/session{ status: 0,
    sessionId: '25b55e4b-0ad7-4a36-830a-36863cff3d7a',
    value:
    { platform: 'MAC',
    acceptSslCerts: true,
    javascriptEnabled: true,
    browserName: 'chrome',
    chrome: { userDataDir: '/var/folders/cs/7zzbk12j0k14ykd00r62l3jc0000gn/T/.org.chromium.Chromium.eOaHer' },
    rotatable: false,
    locationContextEnabled: true,
    'webdriver.remote.sessionid': '25b55e4b-0ad7-4a36-830a-36863cff3d7a',
    version: '32.0.1700.107',
    takesHeapSnapshot: true,
    cssSelectorsEnabled: true,
    databaseEnabled: false,
    handlesAlerts: true,
    browserConnectionEnabled: false,
    nativeEvents: true,
    webStorageEnabled: true,
    applicationCacheEnabled: false,
    takesScreenshot: true },
    state: null,
    class: 'org.openqa.selenium.remote.Response',
    hCode: 38227648 }
    INFO Got sessionId from selenium 25b55e4b-0ad7-4a36-830a-36863cff3d7a
    INFO Request: POST /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a/url
  • data: {"url":"http://google.com"}
  • headers: {"Content-Type":"application/json","Content-Length":27}
    INFO Response 204 POST /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a/url {}
    LOG - Completed command url
    INFO Request: POST /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a/element
  • data: {"using":"css selector","value":"body"}
  • headers: {"Content-Type":"application/json","Content-Length":39}
    INFO Response 200 POST /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a/element{ status: 0,
    sessionId: '25b55e4b-0ad7-4a36-830a-36863cff3d7a',
    value: { ELEMENT: '0' },
    state: null,
    class: 'org.openqa.selenium.remote.Response',
    hCode: 1480640363 }
    INFO Request: GET /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a/element/0/displayed
  • data:
  • headers: {"Accept":"application/json"}
    INFO Response 200 GET /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a/element/0/displayed{ status: 0,
    sessionId: '25b55e4b-0ad7-4a36-830a-36863cff3d7a',
    value: true,
    state: null,
    class: 'org.openqa.selenium.remote.Response',
    hCode: 274747841 }
    ✔ Element was visible after 96 milliseconds.
    LOG - Completed command waitForElementVisible
    INFO Request: POST /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a/element
  • data: {"using":"css selector","value":"input[type=text]"}
  • headers: {"Content-Type":"application/json","Content-Length":51}
    INFO Response 200 POST /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a/element{ status: 0,
    sessionId: '25b55e4b-0ad7-4a36-830a-36863cff3d7a',
    value: { ELEMENT: '1' },
    state: null,
    class: 'org.openqa.selenium.remote.Response',
    hCode: 1978250683 }
    INFO Request: GET /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a/element/1/location
  • data:
  • headers: {"Accept":"application/json"}
    INFO Response 200 GET /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a/element/1/location{ status: 0,
    sessionId: '25b55e4b-0ad7-4a36-830a-36863cff3d7a',
    value:
    { class: 'org.openqa.selenium.Point',
    hCode: 63744,
    y: 316,
    x: 249 },
    state: null,
    class: 'org.openqa.selenium.remote.Response',
    hCode: 624159493 }
    ✖ Assertion failed: is 20
    INFO Request: DELETE /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a
  • data:
  • headers: {}
    LOG - Completed command getLocation
    INFO Response 204 DELETE /wd/hub/session/25b55e4b-0ad7-4a36-830a-36863cff3d7a {}
    Closing down...

TEST FAILURE: 1 assertions failed, 1 passed and 5 skipped.
FAILED: 1 assertions failed, 1 passed and 5 skipped
LOG - Completed command session
INFO Selenium process finished.

Accessing existing javascript resources in custom commands

I'm wondering if it's possible to call functions that can be called via the console in a normal browser within a custom command?

helper.js

function notice(title, message) {
      // some stuff
}

commands/notify.js

exports.command = function () {
    notice("test", "testing");
    this.execute(function () {
        App.notify();
        return true;
    });

    return this;
};

server stays running when test crashes

when test crashes (bug in test method) server stays running
test cannot be relaunched without killing the selenium server.

Please allow runner ti reuse running server or add shutdown hook.

BTW: already helpful, than for you work...

tests results are losts if same file name in different test groups

I have "test groups" in my tests folders using sub folders. When I run the tests, the results are saved "flat" in the output_folder. The problem is that it overwrites tests with the same name.

I have

/tests/end-user-tests/login.test.js
/tests/admin-tests/login.test.js

But I end up with

/results/login.test.xml

My preference would be a single results.xml with multiple <testsuite> where the name of each <testsuite> is made of the path

    <testsuites name="??">
        <testsuite name="end-user-tests/login : Login Sucess">...
        <testsuite name="admin-tests/login : Login Sucess">...
    </testsuites>

But mirroring the tests structure in the output_folder would be fine too.

Nightwatch + Browserstack behind Corporate Proxy

I've successfully connected nightwatch to a selenium server provided by browserstack on my personal mac however as soon as I try to get setup behind my corporate proxy the DNS is failing to resolve. I went into the source and printed out some extra information...

Error: {} { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENO
TFOUND', syscall: 'getaddrinfo' }
Connection refused! Is selenium server started?

Here is a snippet of my settings.json...

"test_settings" : {
    "default" : {
        "launch_url" : "http://hub.browserstack.com",
        "selenium_port"  : 80,
        "selenium_host"  : "hub.browserstack.com"
        "desiredCapabilities": {
            "browserName": "firefox",
            "javascriptEnabled": true,
            "acceptSslCerts": true,
            "browserstack.user": "Foo",
            "browserstack.key": "Bar",
            "browserstack.debug" : "true"
    }
}

Is there any support to go via a proxy to resolve URLs in nightwatch? Is my thinking that this might be the problem correct?

Any pointers appreciated....

Nightwatch throws error when selenium.log_path is false or undefined.

This line expects a value or it throws an error:

❯ ./nightwatch
Starting selenium server... started - PID:  6967
Running tests

[ sample module ]

Running:  Demo test Google
Setting up...
✔  Element <body> was visible after 148 milliseconds.
✔  Element <button[name=btnG]> was visible after 13 milliseconds.
✔  Testing if element <#main> contains text: The Night Watch
Tearing down...
OK. 3 assertions passed.

path.js:360
        throw new TypeError('Arguments to path.join must be strings');
              ^
TypeError: Arguments to path.join must be strings
    at path.js:360:15
    at Array.filter (native)
    at Object.exports.join (path.js:358:36)
    at ChildProcess.closeHandler (/test/nightwatch-test/node_modules/nightwatch/runner/run.js:122:23)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:735:16)
    at Process.ChildProcess._handle.onexit (child_process.js:802:5)

The workaround, of course, is to add some value to the configuration file:

{
    "selenium" : {
        "log_path" : "tests"
    },
}

Selenium Handling of Alert Boxes breaks message response handling

If an app being tested raises an alert box, selenium attempts to handle the alert box and presses ok for example.

However the response back to nightwatch is unexpected causing a crash and stack trace in nightwatch, as well as no cleanup of spawned processes.

Solution I believe is to add at line 418 a check for errorCodes[result.status] being undefined before accessing message.

Stack trace below.

There was an error while executing the Selenium command - enabling the --verbose option might offer more details.

There was an error while executing the Selenium command - enabling the --verbose option might offer more details.
Modal dialog present: Saved successfully
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'iMac.local', ip: '192.168.1.52', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.1', java.version: '1.7.0_51'
Session ID: 7b21d1e5-5660-2d4a-9419-4d15c5b7c991
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=27.0}]

/Users/myuser/Workspaces/Obfusc/ObfuscTesting/node_modules/nightwatch/lib/index.js:418
errorMessage = errorCodes[result.status].message || "";
^
TypeError: Cannot read property 'message' of undefined
at Nightwatch.handleTestError (/Users/myuser/Workspaces/Obfusc/ObfuscTesting/node_modules/nightwatch/lib/index.js:418:45)
at HttpRequest. (/Users/myuser/Workspaces/Obfusc/ObfuscTesting/node_modules/nightwatch/lib/index.js:300:19)
at HttpRequest.EventEmitter.emit (events.js:106:17)
at IncomingMessage. (/Users/myuser/Workspaces/Obfusc/ObfuscTesting/node_modules/nightwatch/lib/request.js:118:14)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)

waitForJavascript

Hi,

According to your commands like waitForElementVisible , I tried to do a waitForJavascript command

My problem is that I can't find a way to do the same as you (call the function back in order to check the value)

Here is what I did
This is simple test to wait for a true return after 2 seconds

Command

CommandAction.prototype.command = function(browserFunction, milliseconds, callback) {

    this.startDate = Date.now();
    this.callback = callback || function() {};
    this.browserFunction = browserFunction;
    this.milliseconds = milliseconds;

    this._check()

    return this;
}

CommandAction.prototype._check = function() {
    console.log('check')
    var self = this;

    this.client.execute(this.browserFunction, [], function(result){
        console.log('result', result)
        if( result.value === true && result.status === 0  ){
            console.log('suceeed!!!')
            self.callback(true) 
            return self.emit('complete');
        } else if( Date.now() - this.startDate < this.milliseconds ){
            console.log('looping')
            setTimeout(function() {
                self._check()
            }, 500);
        } else {
            console.log('failed!!!')
            self.callback(false)  
            return self.emit('complete');
        }
    })
}

Bash output

Running:  test javascript execution
check
result { status: 0,
  sessionId: '478c717e-a3b4-44eb-9f44-a4fab7fdb63b',
  value: false,
  state: null,
  class: 'org.openqa.selenium.remote.Response',
  hCode: 764998737 }
failed!!!
false
No assertions ran.

My client test

<body>
    <h1>Test waitForJs</h1>

    <script>

    window.value = false;
    console.log('current value', window.value);

    setTimeout(function() {
        window.value = true;
        console.log('current value', window.value);
    }, 2000);

    </script>

</body>

BDD

Hello @beatfactor

Are you will plan a new feature with Gherkin bdd syntax?

reporting not working in windows (for single test)

JUnit XML Reporting (helps with Continue Integration [Bamboo, Jenkins, etc])
Any help will be appreciated. I'm a coder at Disney and I'm trying to push NightwatchJS instead of TheIntern.io.

Works on MAC just fine

This is what I do:
./nightwatch -t nightwatch-tests/some-nightwatch-test.js
when I run on windows, i get this:
OK. 2 assertions passed.

fs.js:427
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory 'c:\dev\prj\git-repos\asgard.js\reports\c:\dev\prj\git-repos\asgard.js\nightwat
ch-tests\some-nightwatch-test.xml'
    at Object.fs.openSync (fs.js:427:18)
    at Object.fs.writeFileSync (fs.js:966:15)
    at c:\dev\prj\git-repos\asgard.js\node_modules\nightwatch\runner\reporters\junit.js:36:10
    at fs.js:266:14
    at Object.oncomplete (fs.js:107:15)
when I run on MAC, i get this:
# ... redacted success output, and then: 
OK. 5 total assertions passed.

My WIN box info (within GIT BASH TERMINAL):

# enter NODE repl:
> os.type()
'Windows_NT'
> os.arch()
'ia32'
> os.platform()
'win32'
# exit REPL
$ node --version
v0.10.24
$ npm --version
1.3.21
# my package.json$devDependencies (excerpt)
"nightwatch": "~0.2.4"

Custom commands not working correctly?

Hello. Firstly, this could be an issue with how I am creating custom commands, but I have found that whenever I do attempt to use one the tests no longer pass - however, they did pass before being abstracted into the custom command.

Here's a custom command that I tried:

exports.command = function() {
    return this.waitForElementVisible('body', 1000)
        .setValue('input[type=text]', 'nightwatch')
        .waitForElementVisible('button[name=btnG]', 1000)
        .click('button[name=btnG]')
        .pause(1000)
        .assert.containsText('#main', 'The Night Watch')
};

and heres the test that uses this custom command:

this.demoTestGoogle = function (browser) {
    browser
        .url("http://www.google.com")
        .google()
        .end();
};

When I run this test with the custom command I receive the following output:

$ node nightwatch.js -t test.js                                     
Starting selenium server... started - PID:  1740                    
Running tests                                                       

[ test module ]                                                     

Running:  demoTestGoogle                                            
✔  Element <button[name=btnG]> was visible after 1092 milliseconds. 
✖  Element <button[name=btnG]> was not visible in 1000 milliseconds.
✖  Testing if element <#main> contains text: The Night Watch        
FAILED:  2 assertions failed and 1 passed                           
No assertions ran.                                                                                                                     

When I run the default Google demo test I receive the expected following output:

$ node nightwatch.js -t test.js                                   
Starting selenium server... started - PID:  10680                 
Running tests                                                     

[ test module ]                                                   

Running:  demoTestGoogle                                          
✔  Element <body> was visible after 182 milliseconds.             
✔  Element <button[name=btnG]> was visible after 31 milliseconds. 
✔  Testing if element <#main> contains text: The Night Watch      
OK. 3 assertions passed.                                          

Am I using custom commands correctly?

Add ability to use a remote selenium server that requires auth

Currently nightwatch seems to only run locally. Would be great to e.g. run tests on Sauce Labs using nightwatch saucelabs:

{
  ...        
  "test_settings" : {
    "default" : {
      ...
    },
    "saucelabs" : {
      "selenium_host": "ondemand.saucelabs.com",
      "selenium_port": 80,
      "username": ...,
      "key": ...
    }
  }        
}

Installation failed on Windows 7

npm ERR! fetch failed https://registry.npmjs.org/nightwatch/-/nightwatch-0.
gz
npm ERR! Error: 404 Not Found
npm ERR! at WriteStream. (c:\Program Files\nodejs\node_modul
m\lib\utils\fetch.js:57:12)
npm ERR! at WriteStream.EventEmitter.emit (events.js:117:20)
npm ERR! at fs.js:1596:14
npm ERR! at c:\Program Files\nodejs\node_modules\npm\node_modules\grace
s\graceful-fs.js:103:5
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "c:\Program Files\nodejs\node.exe" "c:\Program Files
s\node_modules\npm\bin\npm-cli.js" "install" "nightwatch"
npm ERR! cwd C:\dev\playground\nightw-play1
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.3.5
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\dev\playground\nightw-play1\npm-debug.log
npm ERR! not ok code 0

Any idea?

Add helper fns to check against expected values

Running into the issue where I need to conditionally check an assert [or] verify -- I am currently running a test that get's all the file paths in a directory to see if there are error pages and what type of error they are, I can grab it with a class/id but there's no checkForElementPresent or similar to make my .xml file a bit more detailed.

If something like this exists already and I just haven't found it through the API I'd love a ProTip.

Thanks, great job on this, really.

let browser active

how to let browser tab active..

I want to use nightwatch as auto login to web based network login in company..
how to let browser tab open after login success??

SetValue appends text instead of replacing on subsequent tests

I'm running a series of tests on a login page including all of the usual suspects (missing username/password, wrong username/password, etc.) I've found that instead of overriding the previous value in the textbox when a test uses setValue it's appending the value to the existing value.
My tests:

module.exports = {
    "Bad Password": function (browser) {
        browser
          .url("http://localhost")
          .waitForElementVisible('body', 5000)
          .setValue('input[name=UserName]', 'user')
          .setValue('input[name=Password]', 'bob')
          .click('#Login')
          .pause(5000)
          .assert.containsText('div[role=input]', 'The Username or password provided is incorrect.')
          .click('a.x-btn-noicon')
    },
    "Bad Username": function (browser) {
        browser
          .setValue('input[name=UserName]', 'steve')
          .setValue('input[name=Password]', 'bob')
          .click('#Login')
          .pause(5000)
          .assert.containsText('div[role=input]', 'The Username or password provided is incorrect.')
          .click('a.x-btn-noicon')
          .end();
    }
};

[Abbreviated for simplicity]

Not sure if this is the intended functionality or not. If so is there a method to clear an input?

Accepting Confirm Boxes

I don't see any implementation of sending a key or clicking on a confirm() alert anywhere. I may just not know how to do it though - is this possible?

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.