nightwatchjs / nightwatch Goto Github PK
View Code? Open in Web Editor NEWIntegrated 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
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
I'm having trouble selecting elements within iframes. Is this possible?
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.
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)
It looks like Nightwatch suppports FF and Chrome now. Can it add support for IE in the same way that it supports the Chrome Driver? https://code.google.com/p/selenium/wiki/InternetExplorerDriver
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?
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....
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?
I've noticed that triggering an error in a callback doesn't fail the build:
this code (note the INDEXOF method)
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
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.
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
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>
https://npmjs.org/package/selenium-webdriver
It might be worth adding some copy to the README to state how this project is any different/better.
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".
Nightwatch's main goal seems to be usability. It'd be handy if there was a little more support, even if just from a documentation perspective, to help people new to automated browser testing get across using multiple webDrivers.
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;
};
Hello @beatfactor
Are you will plan a new feature with Gherkin bdd syntax?
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": ...
}
}
}
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)
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?
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.
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.
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
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 ?
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?
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.
I tried it with ghost driver but didn't work
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"
},
}
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.
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??
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!
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
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.
Based on #50
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
}
}
}
}
@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
I like what you have done a lot. However, I would love to see some more real life examples how the API reference is put into action.
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.
./nightwatch -t nightwatch-tests/some-nightwatch-test.js
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)
# ... redacted success output, and then:
OK. 5 total assertions passed.
# 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"
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...
./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
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.
Add a command-line argument for piping test output to an alternative reporter, with a fallback to junit as default.
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.
@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 :-)
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.
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,
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?
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.
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
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).
@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
Anyone want in/Already working on one?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.