Writing tests is a chore.
It's hard to get developers to write tests, especially when starting a new project or feature.
A common interface for communicating with browsers
Install browsers you want to test against.
var selenium = require('selenium-standalone');
var seleniumProcess = null; // for tracking the selenium process
gulp.task('selenium:install', function(done) {
selenium.install(done);
});
gulp.task('selenium:start', ['selenium:install'], function(done) {
selenium.start(function(err, process) {
seleniumProcess = err ? null : process;
done();
});
});
var spawn = require('child_process').spawn;
gulp.task('test', ['selenium:start', 'serve'], function(done) {
var nw = spawn('./node_modules/.bin/nightwatch', [
'--config', 'test/nightwatch.conf.js'
]);
nw.stdout.on('data', function(data) {
console.log(data.toString());
});
nw.stderr.on('data', function(data) {
console.log(data.toString());
});
nw.on('close', function(code) {
gutil.log('Nightwatch process exited with code', code);
if (seleniumProcess) {
seleniumProcess.kill();
seleniumProcess = null;
}
done();
});
nw.on('error', function(err) {
gutil.log('Failed to start Nightwatch process', err);
});
});
module.exports = {
src_folders: 'test',
output_folder: false,
test_settings: {
default: {
launch_url: 'http://localhost:8080/',
filter: '*.spec.js',
screenshots: {
enabled: false,
path: ''
},
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
}
}
}
};
module.exports = {
'Initial loading': function(browser) {
browser
.init()
.waitForElementVisible('div.flowtime', 1000)
.assert.visible('h1')
.assert.containsText('h1', 'Automate Your Browser Testing')
.end();
}
};
Check out the Nightwatch API docs for details.
module.exports = {
src_folders: 'test',
output_folder: false,
test_settings: {
default: {
// ... same as before ...
},
saucelabs: {
selenium_host: 'ondemand.saucelabs.com',
selenium_port: 80,
username: '${SAUCE_USER}',
access_key: '${SAUCE_ACCESS_KEY}',
silent: true,
output: true,
screenshots: {
enabled: false,
on_failure: true,
path: ''
},
selenium: {
start_process: false
}
}
}
};
Sauce Connect is a tunneling app that you set up in your local network that opens a secure connection between a Sauce Labs virtual machine running your browser tests, and an application or website you want to test that's on your local machine or behind a corporate firewall.
$ sc -u SAUCE_USERNAME -k SAUCE_ACCESS_KEY