This boilerplate was created to enable cucumber testing within a corporate network where you cannot run the npm selenium standalone installs.
This uses selenium standalone jar file with chrome driver which you can download manually.
Given the problems with phantomjs trying to test against javascript driven applications, built by something like React or Angular, it is easier to use chromedriver with an argument to force to run headlessly.
To run like the equivalent npm selenium_standalone where you don't want to run two seperate commandlines, this uses gulp and npm-run-cmd to auto load a seperate cmd in the background to run selenium and closes when it's finished.
- java
- node
- npm
- git
$ git clone thisrepo
$ npm install
- from: cucumber-boilerplate/selenium_drivers/chromedriver_win32.zip
- into: cucumber-boilerplate/selenium_drivers/chromedriver.exe
$ npm run test
$ cd myproject
or download and extract it if you don't have access over network
$ git clone https://github.com/webdriverio/cucumber-boilerplate.git
https://docs.seleniumhq.org/download/ selenium-server-standalone-3.11.0.jar put into
./myproject/cucumber-boilerplate/selenium_drivers/selenium-server-standalone-3.11.0.jar
https://sites.google.com/a/chromium.org/chromedriver/home chromedriver_win32.zip put into ./myproject/cucumber-boilerplate/selenium_drivers/chromedriver_win32.zip
extract to ./myproject/cucumber-boilerplate/selenium_drivers/chromedriver.exe
chromedriver.exe
const path = require('path');
const gulp = require('gulp');
const gutil = require('gutil');
const nrc = require('node-run-cmd');
const Launcher = require('webdriverio').Launcher;
gulp.task('selenium', cb => {
nrc.run(`java
-Dwebdriver.chrome.driver=./selenium_drivers/chromedriver.exe
-jar ./selenium_drivers/selenium-server-standalone-3.11.0.jar
-port 4444`, err => {
cb(err)
})
});
gulp.task('wdio', () => {
const createLauncherWithConfig = () => {
const strFile = path.join(__dirname, 'wdio.conf.js');
const wdio = new Launcher(strFile, {
specs: ['./src/features/**/*.feature']
});
return wdio;
};
const wdio = createLauncherWithConfig(gutil.env);
wdio.run().then(
code => {
process.exit(code);
}, error => {
console.error('Launcher failed to start the test', error.stacktrace);
process.exit(1);
}
);
});
gulp.task('default', ['selenium', 'wdio']);
services: ['selenium-standalone']
capabilities: [{
// maxInstances can get overwritten per capability. So if you have an
// in-house Selenium grid with only 5 firefox instance available you can
// make sure that not more than 5 instance gets started at a time.
maxInstances: 5,
//
browserName: 'chrome',
chromeOptions: {
args: ['--headless --disable-extensions']
}
}]
deprecationWarnings: false,
$ npm init -y
"scripts": {
"test": "gulp --gulpfile cucumber-boilerplate/gulpfile.js"
},
$ npm install gulp gutil node-run-cmd --save-dev
package.json should look like this:
{
"name": "project-with-internal-cucumber-testing",
"version": "1.3.2",
"description": "project with internal cucumber testing",
"scripts": {
"test": "gulp --gulpfile cucumber-boilerplate/gulpfile.js"
},
"keywords": [
"webdriverio",
"cucumber",
"test",
"selenium"
],
"license": "MIT",
"dependencies": {
"babel-jest": "~23.0.0-alpha.0",
"babel-polyfill": "~6.26.0",
"babel-preset-es2015": "~6.24.0",
"babel-register": "~6.26.0",
"chai": "~4.1.2",
"forever": "~0.15.3",
"gulp": "^3.9.1",
"gutil": "^1.6.4",
"jest": "~22.1.0",
"node-run-cmd": "^1.0.1",
"wdio-cucumber-framework": "~1.1.0",
"wdio-phantomjs-service": "~0.2.2",
"wdio-selenium-standalone-service": "~0.0.9",
"wdio-spec-reporter": "~0.1.2",
"webdriverio": "4.12.0"
}
}
$ yarn run test
Make sure you have extracted: chromedriver_win32.zip From ./myproject/cucumber-boilerplate/selenium_drivers/chromedriver_win32.zip extract to ./myproject/cucumber-boilerplate/selenium_drivers/chromedriver.exe
Close cmd and open a new cmd CTRL ALT DELETE find proceses 2.36-x64-chromedriver*32 kill all of them start again
$ cd myproject java -Dwebdriver.chrome.driver=./cucumber-boilerplate/selenium_drivers/chromedriver.exe -jar ./cucumber-boilerplate/selenium_drivers/selenium-server-standalone-3.11.0.jar -port 8080
.git .github .yarn.lock node_modules package.json test/ folder .babelrc - should be moved to myproject .gitignore - should be moved to myproject
sampleSnippets.feature