Skip to content

Nightwatch with Gulp - How to run a single test file from command line #43

@MukeshPanda

Description

@MukeshPanda

I am using Nightwatch along with Gulp to run my tests. Right now I am running my test with the command "gulp local:e2e" or "gulp preprod:e2e".
When i run this command it runs all the test files inside test folder with different urls.
What I want to is the ability to run only a single test file if I want to, something like this
"gulp <> <<testfilename/testfilenames.js>>"
Here is how my nightwatch.json and gulpfile.js files are configured.

What changes should I make to my nightwatch,json and what type of new tasks should i add to my gulpfile.js to achieve what i desire.
Please help.

nightwatch.json

{
"src_folders": ["tests"],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "",
"globals_path": "",

"selenium" : {
"start_process" : true,
"server_path" : "./node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.47.1.jar",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "drivers/chromedriver",
"webdriver.ie.driver" : ""
}
},

"test_settings": {
"chrome": {
"selenium_port": 4444,
"selenium_host": "selenium-hub.nikedev.com",
"globals": {
"platform": "desktop"
},
"screenshots": {
"enabled": true,
"on_failure": true,
"on_error": true,
"path": "screenshots/chrome"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"local": {
"selenium_port": 4444,
"selenium_host": "127.0.0.1",
"globals": {
"platform": "desktop"
},
"screenshots": {
"enabled": true,
"on_failure": true,
"on_error": true,
"path": "screenshots/chrome"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}

gulpfile.js

var gulp = require('gulp'),
nightwatch = require('gulp-nightwatch');

gulp.task('test:e2e', function() {
process.env.seleniumon = 'cloud'
return gulp.src('')
.pipe(nightwatch({
configFile: 'nightwatch.json',
cliArgs: ['--env chrome']
}));
});

gulp.task('local:e2e', function() {
process.env.seleniumon = 'local'
return gulp.src('')
.pipe(nightwatch({
configFile: 'nightwatch.json',
cliArgs: ['--env local']
}));
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions