I am not able to run the test using gulp-protractor task. It starts the standalone Selenium Server and launch the Chrome Browser but does nothing after that.
gulp.js
var gulp = require('gulp');
var gp = require('gulp-protractor');
var protractor = require("gulp-protractor").protractor;
var webdriver_standalone = require("gulp-protractor").webdriver_standalone;
gulp.task('protractor',function(cb) {
gulp.src(['./test/e2e/*.js'])
.pipe(protractor({
configFile: 'conf.js'
})).on('error', function(e) {
console.log(e)
}).on('end', cb);
})
conf.js
exports.config = {
//directConnect: true,
seleniumServerJar: './node_modules/protractor/selenium/selenium-server-standalone-2.48.2.jar',
specs: ['./test/e2e/*.js'],
baseUrl: http://url
Console output
[13:25:11] Starting 'protractor'...
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://IP:64422/wd/hub
Started
.........*
Pending:
1) should be able to click on Company Name "ABC firm
No reason given
10 specs, 0 failures, 1 pending spec
Finished in 0.041 seconds
Shutting down selenium standalone server.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chromeANY #1 passed
[13:25:17] Finished 'protractor' after 5.69 s
Please advice.
In gulpfile.js
var angularProtractor = require('gulp-angular-protractor');
gulp.task('test', function (callback) {
gulp
.src([__dirname+'/public/apps/adminapp/**/test/**_test.js'])
.pipe(angularProtractor({
'configFile': 'public/apps/adminapp/app.test.config.js',
'debug': false,
'args': ['--suite', 'adminapp'],
'autoStartStopServer': true
}))
.on('error', function(e) {
console.log(e);
})
.on('end',callback);
});
In config file
exports.config = {
baseUrl: 'http://localhost:8000/#/login',
framework:'jasmine',
seleniumServerJar : '../../../node_modules/selenium-standalone-jar/bin/selenium-server-standalone-2.45.0.jar',
suites: {
adminapp: [
'login/test/login_test.js',
'jobs/test/jobs-edit_test.js'
]
},
capabilities: {
browserName: 'chrome'
}
}
Its pretty easy and straight forward and also works for me.
Related
Can any one help me the set up required to run the Protractor test script in Microsoft edge browser .
I have tried below steps
In the Protractor configuration file
{
'browserName' : 'MicrosoftEdge',
'SharedTestFiles' : false
}
seleniumArgs : ['-Dwebdriver.edge.driver=C:/Windows/SystemApps/Microsoft.MicrosoftEdge_8wekyb3d8bbwe/MicrosoftEdge.exe'],
run the selenium webdriver server with the below command
webdriver-manager start
It is displaying below error message
SessionNotCreatedError: Unable to create new service: EdgeDriverService
I tried below and worked fine for me:-
config.js
exports.config = {
seleniumAddress: 'http://localhost:4444',
capabilities: {
browserName: 'MicrosoftEdge',
elementScrollBehavior: 1,
nativeEvents: false
},
framework: 'jasmine',
baseUrl: 'http://angularjs.org',
specs: [
'spec.js'
],
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
}
Test Case/Spec file:-
describe('IE Test cases suite', function() {
it('first IE test case', function() {
browser.get(browser.baseUrl);
browser.getCurrentUrl().then(function(url){
console.log(url);
});
});
});
Also you can find some pre-requisites for webdriver manager refer
https://github.com/angular/protractor/issues/2377#issuecomment-290836086
I am new to java script protractor cucumber framework.
I can see similar issue raised here an year ago but this was fixed in a protractor release an year ago as well. hence raising a new question.
I am using latest version of cucumber, protractor, protractor-cucumber-framework, chai, chai-as-promised. I am using visual studio code as editor.
Node Version is 6.11.4. Please look at the package.json below for all version details.
When I execute my tests, it finishes of in less than a second with a pass result but it just launches the browser and then doesn't do anything in the browser.
Please look at the files I am using and suggest me where is the problem. I am not sure whether this is a bus in the latest version of protractor.
protractor.conf.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['features/*.feature'],
getPageTimeout: 60000,
allScriptsTimeout: 500000,
baseURL: 'http://www.protractortest.org/testapp/ng1/#/form',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
cucumberOpts: {
require: [ './features/step_definitions/*.steps.js' ],
tags: false,
profile: false,
'no-source': true
}
};
package.json:
{
"name": "protractor_test",
"version": "1.0.0",
"description": "",
"main": "protractor.conf.js",
"dependencies": {
"protractor": "^5.2.0",
"cucumber": "^3.1.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"#types/chai-as-promised": "^7.1.0",
"#types/cucumber": "^2.0.4",
"#types/protractor": "^4.0.0"
},
"devDependencies": {
"protractor-cucumber-framework": "^4.1.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
test.feature:
Feature: Running Cucumber with Protractor
As a user of Protractor
I should be able to use Cucumber
In order to run my E2E tests
Scenario: Login to myApp
Given I go to Login page
When I login with "username" and "pwd"
Then "You are logged in as ADMIN" is displayed
test.steps.js:
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var {defineSupportCode} = require('cucumber');
var expect = chai.expect;
chai.use(chaiAsPromised);
defineSupportCode(function({Given, When, Then}) {
Given('I go to DSH Login page', function () {
browser.get("http://localhost/myapp");
expect(element(by.buttonText('Login')).isDisplayed()).to.eventually.equal(true);
});
When('I login with {string} and {string}', function (username, password) {
element(by.id('username')).sendKeys(username);
element(by.id('password')).sendKeys(password);
element(by.buttonText('Login')).click();
});
Then('{string} is displayed', function (headerText) {
expect(element(by.cssContainingText('ng-isolate-scope', headerText)).isDisplayed()).to.eventually.equal(true);
});
});
Console Output:
Debugging with legacy protocol because Node.js v6.11.4 was detected.
'C:\Program Files\nodejs\node.exe' --debug-brk=38084 --nolazy node_modules\protractor\bin\protractor protractor.conf.js
Debugger listening on [::]:38084
[16:48:02] I/launcher - Running 1 instances of WebDriver
[16:48:02] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
...
1 scenario (1 passed)
3 steps (3 passed)
0m00.015s
[16:48:05] I/launcher - 0 instance(s) of WebDriver still running
[16:48:05] I/launcher - chrome #01 passed
Selenium Chrome node console output:
Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 11099
Only local connections are allowed.
16:48:04.496 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession#1418ca00
16:48:04.496 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/timeouts (handler: ServicedSession)
16:48:04.496 INFO - To upstream: {"script":500000}
16:48:04.496 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":13,"value":{"message":"unknown error: 'ms' must be a double\n (Session info: chrome=60.0.3112.78)\n (Driver info: chromedriver=2.33.506120 (e3e
53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.3.9600 x86_64)"}}
16:48:04.512 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession#1418ca00
16:48:04.512 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/timeouts (handler: ServicedSession)
16:48:04.512 INFO - To upstream: {"type":"script","ms":500000}
16:48:04.527 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":0,"value":null}
16:48:05.010 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession#1418ca00
16:48:05.010 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession#1418ca00
16:48:05.010 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing DELETE on /session/ed9fb79d586bc77176974953aaf98ef2 (handler: ServicedSession)
16:48:05.010 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/url (handler: ServicedSession)
16:48:05.026 INFO - To upstream: {"url":"data:text/html,<html></html>"}
16:48:05.088 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":0,"value":null}
16:48:05.088 INFO - Removing session org.openqa.selenium.remote.server.ServicedSession#1418ca00
16:48:05.138 INFO - To downstream: {"sessionId":"","status":0,"value":null}
16:48:05.138 INFO - To downstream: {"sessionId":"","status":6,"value":{"message":"no such session\n (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.3.9600 x86_64)"}}
Can you try using callback argument instead of relying on promises. If it works, then for entering username & password you can make use of Q package to resolve all the promises.
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var {defineSupportCode} = require('cucumber');
var expect = chai.expect;
chai.use(chaiAsPromised);
defineSupportCode(function({Given, When, Then}) {
Given('I go to DSH Login page', function (callback) {
browser.get("http://localhost/myapp");
expect(element(by.buttonText('Login')).isDisplayed()).to.eventually.equal(true).and.notify(callback);
});
When('I login with {string} and {string}', function (username, password, callback) {
element(by.id('username')).sendKeys(username);
element(by.id('password')).sendKeys(password);
element(by.buttonText('Login')).click().then(function() {
callback();
});
});
Then('{string} is displayed', function (headerText, callback) {
expect(element(by.cssContainingText('ng-isolate-scope', headerText)).isDisplayed()).to.eventually.equal(true).notify(callback);
});
});
Since I am kind of getting used to the Javascript, I thought I will post what I am currently doing.
I have stopped using callbacks. Instead I use async and await so that the control waits for the asynchronous operation to be completed.
for example:
When('I login with {string} and {string}', async function (username, password) {
await element(by.id('username')).sendKeys(username);
await element(by.id('password')).sendKeys(password);
await element(by.buttonText('Login')).click();
});
Hope this helps someone.
I'm working on an angular project where we have end to end tests using protractor. We use gulp-protractor to run these tests. Every thing works fine on local. Now we want to increase the number of browsers and devices under tests, so I started to change protractor.conf.js to work with browserstack.
The web application under tests is running locally, so I use browserstack-local as well.
I have a configuration working well for one browser, which test website running on local (inspired from https://github.com/browserstack/protractor-browserstack/blob/master/conf/local.conf.js).
Now, I'm trying to adapt it to run on multi-browsers (following https://github.com/browserstack/protractor-browserstack/blob/master/conf/parallel.conf.js). I end up with that configuration:
exports.config = {
framework: 'jasmine2',
onPrepare: common.onPrepare,
// The address of a running selenium server.
seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub',
commonCapabilities: {
'browserstack.user': 'OUR_USER',
'browserstack.key': 'OUR_KEY',
name: 'Taylor Wimpey e2e tests',
'browserstack.debug': 'true',
'browserName': 'chrome',
'browserstack.local': true
},
multiCapabilities: [{
browserName: 'Chrome'
},{
browserName: 'Safari'
},{
browserName: 'Firefox'
},{
browserName: 'IE'
}],
baseUrl: 'http://localhost:3000',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: [paths.e2e + '/**/*.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
},
// Code to start browserstack local before start of test
beforeLaunch: function(){
console.log("Connecting local");
return new Promise(function(resolve, reject){
exports.bs_local_args = {
key: exports.config.commonCapabilities['browserstack.key'],
force: true
};
exports.bs_local = new browserstack.Local();
exports.bs_local.start(exports.bs_local_args, function(error) {
if (error) return reject(error);
console.log('Connected. Now testing...');
resolve();
});
});
},
// Code to stop browserstack local after end of test
onComplete: function(){
console.log('Stop browserstack local');
return new Promise(function(resolve){
exports.bs_local.stop(resolve);
});
}
};
// Code to support common capabilities
exports.config.multiCapabilities.forEach(function(caps){
for(var i in exports.config.commonCapabilities) {
caps[i] = caps[i] || exports.config.commonCapabilities[i];
}
});
Tests are launched and worked (my reports are generated for each browsers), but it never stop. Here the end of console logs:
...
[BS] Serving files from: .tmp/serve
[BS] Serving files from: src
Connecting local
Connected. Now testing...
[09:05:39] I/launcher - Running 4 instances of WebDriver
......F......FFF^C
so I have to kill them manually, which is not an option as at the end, tests will be running in a continuous integration server.
Does anyone knows how to get e2e tests working on multi-browsers using browserstack with the web application under test running on local?
UPDATE: browserstack support has added an example for multi-capabilities running on local on their github repo: https://github.com/browserstack/protractor-browserstack/blob/master/conf/parallel_local.conf.js
The only difference is to use afterLaunch instead of onComplete
Thanks
I am running my Protractor Test from command npm run e2e
I want a way so that if I pass npm run e2e firefox then my test will get executed on Firefox browser.
Or if I run npm run e2e chrome then it should run on chrome
if I pass both npm run e2e firefox chrome then my test should run on both the browser in parallel.
Is it possible to parametrize protractor config file?
Similarly if I can pass test suite name via command and it should execute only tests under that particular test suite.
Here is my config file and this is what I want to achieve:
`//var HtmlReporter = require('protractor-html-screenshot-reporter');
exports.config = {
allScriptsTimeout: 30000,
//Add parameters for browser names
params:{
pass: {
browserName : 'chrome',
testSuitName : 'e2e/TestSuites/_BVT/*.js',
}
},
suites: {
//Define here List of Sanity Test Scenarios:
BVT : testSuitName,
},
// configure multiple browsers to run tests
multiCapabilities: [
shardTestFiles: true,
maxInstances: 2
{'browserName': browserName}
],
baseUrl: 'http://mytestUrl/',
framework: 'jasmine2',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
browser.driver.manage().window().maximize();
return browser.getProcessedConfig().then(function(config) {
var browserName = config.capabilities.browserName;
var junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'tests/test-results',
filePrefix: browserName + '-xmloutput',
modifySuiteName: function(generatedSuiteName, suite) {
return browserName + '.' + generatedSuiteName;
}
});
jasmine.getEnv().addReporter(junitReporter);
});
},
resultJsonOutputFile: 'tests/test-results/output.json'
};`
Would appreciate any help on this.
Thanks in advance.
I know this post is a bit old now, but this solution may help people having a similar problem.
Use multiple config files, one for each browser type, setup a base config file, and require that into each of the other config files, and then create an npm script for each config file. No need for parameters and everything stacks nicely.
so the base config (called something like "protractor_base.js")would look something like:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
rootElement: '[ng-app]',
allScriptsTimeout: 60000,
framework: 'jasmine',
specs: ['example-spec.js']
};
And then your other configs (ie "protractor_chrome.conf.js") would look something like:
protractor = require('./protractor_base.js');
var config = protractor.config;
config.capabilities: {
'browserName': 'chrome'
};
exports.config = config;
You can then specify a multi browser config, just a chrome one, etc.
--capabilities.chromeOptions.args=headless --capabilities.chromeOptions.args=disable-gpu --capabilities.chromeOptions.args=window-size=1200,600
The above code should work for you.
I was looking for passing parameters from command line to protractor config file and found a way to do this:
npm run e2e -- --baseUrl=http://testurl:8080 --suite=suite_name_defined_in_config --capabilities.browserName=browser_Name
where my npm package.json :
"e2e": "protractor tests/protractor-conf.js",
and config file contains :
suites: {
BVT: 'e2e/TestSuites/_BVT/*.js',
Full: 'e2e/TestSuites/Full/**/*.js',
},
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:8080/',
I am trying to run some protractor tests in Windows but am getting the following error:
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://10.44.10.127:55805/wd/hub
[launcher] Error: TypeError: Object #<Object> has no method 'forEach'
at new Plugins (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\lib\plugins.js:30:20)
at driverprovider_.setupEnv.then.then.then.then.frameworkPath (C:\Users\ueser\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:268:15)
at _fulfilled (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:826:30)
at Promise.promise.promiseDispatch (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:759:13)
at C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:573:44
at flush (C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:419:13)
And then
[launcher] Process exited with error code 100
Has anyone come across this before?
Update:
protractor conf.js file as follows:
'use strict';
var testConfig = require('../../testConfig');
exports.config = {
allScriptsTimeout: 11000,
suites: {
dev: ['domain/**/*Spec.js', 'common/**/*Spec.js'],
oldExtranetIntegration: ['integration/**/*Spec.js']
},
baseUrl: testConfig.baseUrl,
framework: 'jasmine',
onPrepare: function () {
/* global angular: false, browser: false, document: false */
// Disable animations so e2e tests run more quickly
var disableNgAnimate = function () {
angular.module('disableNgAnimate', []).run(function () {
var css = document.createElement('style');
css.type = 'text/css';
css.innerHTML = '* { -webkit-transition-duration: 5ms !important; transition-duration: 5ms !important; -webkit-animation-duration: 5ms !important; animation-duration: 5ms !important; }';
document.body.appendChild(css);
});
};
browser.addMockModule('disableNgAnimate', disableNgAnimate);
},
// Disabled settings for using chromedriver directly
//directConnect: true,
//chromedriver: '/node_modules/chromedriver/lib/chromedriver/chromedriver',
capabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': require('phantomjs').path
},
jasmineNodeOpts: {
defaultTimeoutInterval: 30000,
isVerbose: true
},
plugins: {
timeline: {
path: '../../../node_modules/protractor/plugins/timeline/',
// Output json and html will go in this folder.
outdir: 'timelines'
}
}
};
Also please note that the tests run OK on our Linux boxes. I had to install Windows SDK 7.1 to get Protractor to install successfully (even though I'm running Windows 8)
I have identified that it is the "plugins" section of the configuration file causing the problem. If I comment it out completely the tests run.
If I change it to the following, they also run:
plugins: [{
timeline: {
path: '../../../node_modules/protractor/plugins/timeline/',
// Output json and html will go in this folder.
outdir: 'timelines'
}
}]
The only change is that I've added the plugin into an array object. I did this after looking at the "plugins.js" code for Protractor:
var Plugins = function(config) {
var self = this;
this.pluginConfs = config.plugins || [];
this.pluginObjs = [];
this.pluginConfs.forEach(function(pluginConf) {
var path;
if (pluginConf.path) {
path = ConfigParser.resolveFilePatterns(pluginConf.path, true,
config.configDir)[0];
} else {
path = pluginConf.package;
}
if (!path) {
throw new Error('Plugin configuration did not contain a valid path.');
}
pluginConf.name = path;
self.pluginObjs.push(require(path));
});
};
The tests ran fine on Linux (Ubuntu) without the array, but it was needed for running in Windows.
This was all caused by having protractor v1.5 installed, when the tests and configuration file were for protractor v1.3