I am new to protractor framework,working on parameterising specs in conf.js...seeked help,googled but didn't get a solution...if any one is aware kindly help me...
If you want to run multiple files in protractor better use the naming conventions.
For example if there are two files :
todo-spec.js
log.js
If both files are in D:/Folder
Better name it in following way:
todo-spec.test.js
log.test.js
And for the spec file use the following way:
exports.config ={ specs: ['D:/Folder/*test.js']};
These will make sure that all your files containing test.js as a part of file name will run.
So keep a habit of writing test after every file.
I hope you are clear now. :-)
You can use multicapabilities , if you can:
exports.config = {
specs: [
// keep this blank
],
multiCapabilities: [{
'browserName': 'chrome',
'specs': ['todo-spec.js']
}, {
'browserName': 'chrome',
'specs': ['log.js']
}, {
'browserName': 'chrome',
'specs': ['test.js']
}],
};
I'm not sure if you are familiar with tools like Grunt and Gulp but it sounds to me like you will probably need one of them to do this. If I had the same requirements as you I would setup a Gulp task that opened your excel/csv file and put the file names of the tests you want to run into a list. Then you can use that same gulp task to kick off your protractor tests by using a package like gulp-protractor to run the tests. You will need to work out the logic to get your list of files on your own but here is an example of how to use a gulp task to do this:
gulp.task("e2e", function() {
//logic to get list of spec files here
gulp.src([<array/list of spec files>])
.pipe(protractor({
configFile: "test/protractor.config.js"
}))
.on('error', function(e) { throw e })
})
Related
I have been trying to follow a tutorial given HERE. However, when I try to start the protractor test given, no tests seem to run at all. My webdriver-manager seems to run perfectly however. Basically nothing happens.
I have tried the following:
node protractor conf.js
node node_modules/protractor conf.js
node node_modules/protractor node_modules/protractor/conf.js
node node_modules/protractor node_modules/protractor/tests/conf.js
None of these work, and the first one throws an error. I've tried putting copies of the files in multiple directories, but none of those seem to work either. I'm no exactly sure what the issue is, but this is how much files are setup.
ui_directory/ <-- This is the overall directory for my web projects
ui_directory/conf.js
ui_directory/todo-spec.js
ui_directory/node_modules/
ui_directory/node_modules/protractor/
ui_directory/node_modules/protractor/conf.js
ui_directory/node_modules/protractor/todo-spec.js
ui_directory/node_modules.protractor/tests/
ui_directory/node_modules.protractor/tests/conf.js
ui_directory/node_modules.protractor/tests/todo-spec.js
What exactly is the proper command to run the tests from the tutorial? All todo-spec.js and conf.js files are the same.
My conf.js file contains the following:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo-spec.js']
};
Please follow the below steps to run basic protractor Test.
Create a Folder, Say example in Desktop (Folder name is protractor)
Create a config and Spec file with .js extension
Make sure both the files are in Same Location / Folder
Open Command Prompt, And Navigate to project Folder (protractor)
Once navigated to project folder, Type as in bracket:
[protractor config.js] // This will execute protractor Test
Example of Basic Protractor Config File is given as
exports.config = {
//The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
//Here we specify the name of the specs files.
framework: 'jasmine',
specs: ['Protractor_spec.js'],
jasmineNodeOpts: {
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 1440000
},
}
What is the difference between nightwatch.conf.BASIC.js and
nightwatch.conf.js in nightwatch framework.
And what is basic requirement for setup nightwatch framework with
node js and selenium
There is no differences between nightwatch.conf.BASIC.js and nightwatch.conf.js.
You have just to know 5 things:
You can name your config file as you want (nightwatch.conf.BASIC.js, nightwatch.json, nightwatch.conf.js or anything.json or anything.js)
You can have more than 1 config file per project.
When you put your Nightwatch configuration in a file named nightwatch.json or nightwatch.conf.js you don't need to say which configuration file should be used since
A nightwatch.conf.js file or a nightwatch.json file will also be loaded by default, if found.
Just keep in mind that:
The nightwatch.conf.js always takes precedence over
nightwatch.json if both are present.
In this case, you can launch your tests like this:
$> nightwatch
When you put your Nightwatch configuration in an other file, you must tell Nightwatch where are the configurations to use. In this case you need to write your tests like this (for example in Node.js):
module.exports = (function(settings) {
//....
})(require('path/to.your/config/file'));
or
var config = require('path/to.your/config/file');
module.exports = {
//....
};
In this case, you need to specify which configuration file to take when launching tests:
$> nightwatch --config path/to.your/config/file
Since naming your config file nightwatch.conf.js or nightwatch.json doesn't change anything to Nightwatch, is there a reason to choose one and not the other?
Answer: Yes!
Why?: Sometimes you need to write a JavaScript code in your configuration file. In this case your file should be a .js file and not a .json file.
Example of use? When you have many environments to test, maybe you don't want to update many lines to change the same information. So you write a nightwatch.conf.js (The objective is to just change one line when you want to deactivate video instead of going to each environment in a .json file and make changes):
nightwatch_config = {
src_folders : [ "a/file/to/test" ],
selenium : {/*...*/},
common_capabilities: {/*...*/},
test_settings: {
default: {},
chrome: {desiredCapabilities: {browser: "chrome"}},
firefox: {desiredCapabilities: {browser: "firefox"}},
safari: {desiredCapabilities: {browser: "safari"}},
ie: {desiredCapabilities: {browser: "internet explorer"}}
}
};
for(var i in nightwatch_config.test_settings){
var config = nightwatch_config.test_settings[i];
for(var j in nightwatch_config.common_capabilities){
config['desiredCapabilities'][j][browserstack.video] = true;
}
}
module.exports = nightwatch_config;
In my application, I want to have an environment config that uses a different version name for every deploy so that the application is properly cache busted and users don't have stale versions of code in their browser cache. Note I have been following this guide.
Thus, in main.js, before I do anything, I call require.config with a generic config that uses the current date/time to bust the cache on the environment config file, then after the environment config is loaded, I use the environment "config.version" as part of the urlArgs to guarantee that the newly deployed code is included and not a stale version. Note that the object from the config file has other properties that will be used throughout the application as well (e.g. google analytics account number).
It seems that my r.js build file is fine if I remove the first require.config that allows me to setup the environment/config dependency, but when I add it back in, the infrastructure JS module that I'm using to group third-party scripts chokes saying it can't find my underscore lib (or any lib I include in there for that matter). Note that even if I don't include environment/config and just make the two require.config calls, the same error results. Is there a reason two require.config calls would cause this error? Thanks for any help.
//Error:
Error: ENOENT, no such file or directory '<%root_folder%>\dist\js\underscore.js'
In module tree:
infrastructure
My main JS file
//main.js
require.config({
baseUrl: "js",
waitSeconds: 0,
urlArgs: "bustCache=" + (new Date).getTime()
});
require(["environment/config"], function(config) {
"use strict";
require.config({
urlArgs: "bustCache=" + config.version,
baseUrl: "js",
waitSeconds: 0,
paths: {
underscore: "lib/lodash.underscore-2.4.1-min",
},
shim: {
"underscore":{
exports : "_"
}
}
});
//commented out, b/c not needed to produce the error
//require(["jquery", "infrastructure"], function($) {
//$(function() {
//require(["app/main"], function(app) {
//app.initialize();
//})
//});
//});
});
And here's the build file...
//build file
({
mainConfigFile : "js/main.js",
appDir: "./",
baseUrl: "js",
removeCombined: true,
findNestedDependencies: true,
dir: "dist",
optimizeCss: "standard",
modules: [
{
name: "main",
exclude: [
"infrastructure"
]
},
{
name: "infrastructure"
}
],
paths: {
"cdn-jquery": "empty:",
"jquery":"empty:",
"bootstrap.min": "empty:"
}
})
Here infrastructure.js
define(["underscore"], function(){});
config file (will have more keys like google analytics account number and other environment specific info.)
//config.js
define({version:"VERSION-XXXX", cdn: { jquery: "//path-to-jquery-1.11.0.min" }});
command I'm running: "r.js -o build.js"
Ok, yes, it is a problem with the two require.config calls. At runtime, there is absolutely no problem calling config multiple times. However, at build time, r.js is not able to follow the calls. So if your build depends on any later call to require.config you are going to have problems.
I see that your second call to require.config does not contain any value that is computed on the basis of what is loaded after the first call, except for urlArgs so you could move everything from that second call into the first one, except for urlArgs.
I'm using grunt-mocha-test to run node server side tests.
My Gruntfile.js looks like this
module.exports = function(grunt) {
// Add the grunt-mocha-test tasks.
grunt.loadNpmTasks('grunt-mocha-test');
grunt.initConfig({
// Configure a mochaTest task
mochaTest: {
test: {
options: {
reporter: 'dot'
},
src: [ 'test/setup.js', 'test/*.test.js' ]
}
},
});
grunt.registerTask('default', 'mochaTest');
};
What I want to do is this, I want to be able to run different test groups with different commands as follows
grunt will run all tests
grunt test1 runs a subset of tests in the test folder, and
grunt test2 runs another subset of tests
I don't know if this is possible, and I haven't been able to find anything about this in the documentation for grunt-mocha-test
I could sure use some help here.
Thanks
At the moment you have one group called test. Just add another object inside mochaTest and call grunt mochaTest:test2.
I'm using CucumberJS to run tests on my NodeJS web app.
At the moment, I can run all of my grunt tasks by executing grunt, or only the CucumberJS tasks, using grunt cucumberjs.
But now I want to only execute particular features.
For example, say I have the following feature files:
Signin.feature
Favourite.feature
I want to only run the Favourite feature tests, using a command such as:
grunt cucumberjs Favourite
Is this possible?
BTW, here's my gruntfile.js:
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
...
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty'
}
}
});
...
grunt.loadNpmTasks('grunt-cucumber');
grunt.registerTask('default', [... 'cucumberjs']);
};
I finally figured out a solution that seems to work well enough, based on tags.
So for each of my feature files, I've added a tag.
For example, for Favourite.feature:
#favourite
Feature: Favourite
As a user of the system
I would like to favourite items
Then I've used a GruntJS option to specify the tags I want to run via a command-line argument.
I do this through a grunt.option() call in my gruntfile:
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty',
tags: grunt.option('cucumbertags')
}
}
So now I can run GruntJS from the command-line like this:
grunt cucumberjs --cucumbertags=#favourite
And it will only run the feature with the #favourite tag. Yay!
here is my task that allows you to filter by feature.name:
https://github.com/webforge-labs/cuked-zombie/blob/master/tasks/cucumber.js
(download it into a "tasks" folder and you can load it with: grunt.loadTasks('tasks'))
configure it like this (Gruntfile.js):
grunt.loadNpmTasks('grunt-cucumber');
grunt.initConfig({
cucumberjs: {
// config for all features when called with: `grunt cucumber`
all: {
src: 'features',
options: {
steps: "tests/js/cucumber/bootstrap.js",
format: "pretty"
}
},
// config for single features when called with `grunt --filter some-feature`
features: {
src: 'features',
options: {
steps: "tests/js/cucumber/bootstrap.js",
format: "pretty"
}
}
}
});
use it with:
grunt cucumber --filter post
which will run the post.feature (somewhere in your feature directory)
With the new cucumber-js Version it is possible to run it by feature-line:
https://github.com/cucumber/cucumber-js/pull/168
I haven't tested it with grunt but cucumber has an option for executing a scenario without modifying the gherkin file. Just call cucumber-js --name "Scenario Name", therefore I assume that sending the same argument to grant it will do its job.