I am using the code bellow for arguments which are using in protractor configuration file
protractor: {
options: {
keepAlive: true,
configFile: "test/config.js",
args:{
params:{
user:"user1",
password:"password1"
}
}
},
and retrieving in protractor conf file as browser.params.user,browser.params.password
These are working files.
I want to change the user and password values from command.
How to change the values?
This is a simple work around:
When you pass a parameter to your grunt task:
grunt e2e --user=alex --password=password
it's available as
grunt.option('user')
You can then edit the values you have in the config using:
var protConfig = grunt.config.get('protractor');
protConfig.options['someKey']=newValue;
grunt.config('protractor', protConfig);
grunt.task.run('protractor');
Not sure this is the best way to go about it, but it's working fine for me.
Also notice that we're wrapping the protractor task rather than calling it right away
how to fetch --user argument in protractor Specs?
In the code below I register a task "myprotractor" and whatever comes after the task as argument will go as parameter into the anonymous function:
grunt myprotractor:dev:pwd
module.exports = function(grunt) {
grunt.registerTask('myprotractor', function(user, pwd) {
console.log(user + pwd);
grunt.config('protractor', {
options: {
keepAlive: true,
configFile: "test/config.js",
args: {
params: {
user: user,
password: pwd
}
}
}
});
//here I am running the task
grunt.task.run([
'protractor'
]);
});
};
If you need you can configure 2 targets for protractor, having some common configuration and the args being set depending if you wish them from cmd or from config.
grunt myprotractor:cmd:dev:pwd
module.exports = function(grunt) {
grunt.registerTask('myprotractor', function(target, user, pwd) {
console.log(user + pwd);
grunt.config('protractor', {
options: {
keepAlive: true,
configFile: "test/config.js"
},
cmd: {
options: {
args: {
params: {
user: user,
password: pwd
}
}
}
},
config: {}
});
//here I am running the task with a target
grunt.task.run([
'protractor:' + target
]);
});
};
Related
Below is my config file that I use to run a single user and multiple test suite.Now, am having a issue where I want to run few protractor suites with User A and few protractor test suite with User B. I don't know how to achieve this in protractor.
exports.config = {
capabilities: {
browserName: 'chrome'
},
suites: {
loginAndNavigate: 'e2e/specFiles/LoginAndNavigateSpec.js',
homepage: 'e2e/specFiles/policiesList_HomepageSpec.js',
versionPage: 'e2e/specFiles/ER_VersionsPageSpec.js'
policyDetails: 'e2e/specFiles/policyDetailsPageSpec.js'
},
seleniumServerJar: '../node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-2.53.1.jar',
chromeDriver: '../node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.26',
baseUrl: 'https://shared.qa.com/EdgeAuth/logindirect.jsp',
params: {
login: {
user: ‘user ',
password: 'abc123'
}
},
onPrepare: function() {
global.EC = protractor.ExpectedConditions;
browser.getCapabilities().then(function(c) {
console.log(c.get('browserName'));
});
global.Utils = require('./e2e/utils.js');
require('./e2e/matchers.js');
require('./e2e/customLocators.js');
},
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 100000
}
};
You can provide new param (user details) and suite details when you run the test.
For the params object use --params.login.user "User B" etc etc to overwrite config file details.
For the suites you can use --suite=loginAndNavigate or if more than one then --suite=loginAndNavigate,homepage to choose what to run.
You will need the proper combination of these two to suit your needs.
https://github.com/angular/protractor/blob/master/lib/config.ts
I have getcookie(username,password) function of javascript in getcookies.js file.
'use strict';
var getcookie = function(username,password){
//body of the getcookie method.
};
I am calling this function using grunt for that I have written task in grunt.js file.
module.exports = function(grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
protractor: {
options: {
keepAlive: false,
configFile: "./config/protractorConf.js"
},
getcookie: {
options: {
args: {
specs: ['getcookie.js']
}
}
}
}
});
//Note: Create task and add it to register task. In order to run single task comment all other tasks and run
grunt.registerTask('getcookie', ['protractor:getcookie']);
};
I want to pass the arguments username and password to the getcookie function from the grunt file.
How can I achieve this?
I use Grunt to run Nightwatch tests. I have created a Grunt task for running an express proxy server that is run before the tests can be run. Then I registered a task to run this proxy first and after that execute the Nightwatch tests. Now I want to register a second Grunt task that runs a different express server and then executes the nightwatch tests. How can I define a second express task? This is my express task:
express: {
options: {
// Override defaults here
},
dev: {
options: {
script: 'server/server.js'
}
}
},
And I start it like this:
grunt.registerTask('testnightwatch', [ 'express:dev' , 'nightwatch']);
I need something like this:
express2: {
options: {
// Override defaults here
},
dev: {
options: {
script: 'server/server2.js'
}
}
},
grunt.registerTask('testnightwatch', [ 'express2:dev' , 'nightwatch']);
But this does not work... Does anybody know how to do this?
You can do this:
express: {
options: {
// Override defaults here
},
dev1: {
options: {
script: 'server/server.js'
}
},
dev2: {
options: {
script: 'server/server2.js'
}
}
},
and start it like this
grunt.registerTask('testnightwatch1', [ 'express:dev1' , 'nightwatch']);
or this
grunt.registerTask('testnightwatch2', [ 'express:dev2' , 'nightwatch']);
I think you can do something like that :
express: {
express1 : {
options: {},
dev: {}
},
express2 : {
options: {},
dev: {}
}
}
But you have to check if your task supports multi task.
i am trying to use grunt-ssh to automate deployment of server from my macbook pro.
So what i am trying to do with this task is to pull from my private bitbucket depository.
Deployment is looks okay once i do grunt deploy on bash but nothing gets pulled in server
This is my gruntfile:
module.exports = function(grunt) {
grunt.initConfig({
sshconfig: {
notify: {
host: 'mydomain.com',
port: 22,
username: 'root',
agent: process.env.SSH_AUTH_SOCK
}
},
sshexec: {
deploy: {
command: [
'cd notify',
'git pull origin master',
'npm install',
].join(' && '),
options: {
config: 'notify'
}
}
}
});
// Load the plugin that provides "sshevexc" task
grunt.loadNpmTasks('grunt-ssh');
// Register new task, deploy
grunt.registerTask('deploy', ['sshexec:deploy'], function(err){
if(err)
return false;
grunt.log.write('Done deploying!').ok();
});
}
Try adding in your sshconfig:
agentForward: true
I have been working all day on trying to get my proxies set up in my Gruntfile. Here is my Gruntfile:
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
module.exports = function(grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
connect:{
livereload: {
options: {
middleware: function (connect) {
return [proxySnippet];
}
}
},
options: {
port: 9000,
base: 'app',
keepalive: true,
livereload: true
},
proxies: [
{
context: '/public/api',
host: 'localhost',
port: 8182,
https: false,
rewrite: {
'^/public/api': ''
}
}
]
}
});
grunt.registerTask('server', ['less', 'configureProxies', 'connect', 'connect', 'watch', 'open:dev']);
};
When I run my grunt server I can only hit my proxy. If I try to just hit anything other than the proxy I get a 404. What is giving me this issue?
I also had a lot of trouble setting up a proxy using grunt-connect-proxy.
Digging in the source code of grunt-contrib-connect, I realized that it uses the nodeJs Connect framework behind the scene.
Internally the middleware option defaults to this function:
function (connect, options) {
var middlewares = [];
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
var directory = options.directory || options.base[options.base.length - 1];
options.base.forEach(function (base) {
// Serve static files.
middlewares.push(connect.static(base));
});
// Make directory browse-able.
middlewares.push(connect.directory(directory));
return middlewares;
}
Which basically adds the connect.static and the connect.directory middlewares to an array passed to the connect(middlewares) constructor.
Knowing that, we can make use of the proxy-middleware nodeJs package like this:
connect: {
server: {
options: {
port: 9002,
keepalive: true,
middleware: function (connect, options) {
// Proxy all requests to target the local application.
var proxyOptions = require('url').parse('http://localhost:8080/');
proxyOptions.route = '/api';
return [
require('proxy-middleware')(proxyOptions), // Include the proxy first.
connect.static(options.base), // Serve static files.
connect.directory(options.base) // Make empty directories browse-able.
];
}
}
}
}
Basically we are adding a middleware to the middleware array.
This new proxy middleware will translate any incoming request like http://localhost:9002/api/ into http://localhost:8080/