Gulp-protractor not starting webdriver-manager - selenium

I'm trying to run protractor automatically using gulp-protractor plugin. This whole process works fine when using protractor commands and explicitly running the web drivers individually.
The same works when running using gulp-protractor, provided ie webdriver is started manually in background before triggering the gulp task.
Below is the code snippet of my Gulp task
var protractor = require("gulp-protractor").protractor;
var webdriverupdate = require("gulp-protractor").webdriver_update;;
var webdriver_standalone = require("gulp-protractor").webdriver_standalone;
// This task is to update & run the webdriver
gulp.task('webdriver_standalone', webdriver_standalone);
gulp.task('webdriverUpdate', ['webdriver_standalone'], function () {
browsers: ['chrome', 'ie']
});
//for running protractor E2E test cases
gulp.task('protractor', function (callback) {
gulp
.src(['./e2e/sanity/shared/*.spec.ts',
'./e2e/sanity/app-header/*.spec.ts',
])
.pipe(protractor({
'configFile': 'Protractor.conf.js',
}))
.on('error', function (e) {
console.log(e);
})
.on('end', callback);
});
gulp.task('default',['webdriverUpdate','protractor']);
Below is the code snippet of my protractor.config.js
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 1100,
suites: {
shared: ['./e2e/sanity/shared/*.ts'] ,
appheader: ['./e2e/sanity/app-header/*.spec.ts']
},
multiCapabilities:
[{
seleniumAddress: 'http://localhost:5555/',
'browserName': 'internet explorer',
'platform': 'windows 10',
'version': '11',
'ignoreProtectedModeSettings': true,
},
{
seleniumAddress: 'http://localhost:4444/wd/hub',
'browserName': 'chrome',
'ignoreProtectedModeSettings': true,
}],
};
How do I run webdriver standalone task ahead of protractor task via gulp??

I used gulp with gulp-angular-protractor like below, hope this helps. It will work for gulp-protractor plugin as well.
//Gulpfile
var gulp = require('gulp');
var gulpProtractor = require('gulp-angular-protractor');
var paths = require('../paths.js');
// Execute e2e Tests
gulp.task('e2e-test', function(callback) {
gulp.src(paths.tests)
.pipe((gulpProtractor({
configFile: 'protractor.conf.js'
})).on('error', function(e) {
console.log(e);
}).on('end', callback));
});
gulp.task('webdriver-update', gulpProtractor.webdriver_update);
gulp.task('webdriver-standalone', ['webdriver-update'], gulpProtractor.webdriver_standalone);
//paths.js:
module.exports = {
tests: 'test/e2e/**/*.spec.js'
};

Related

Protractor (5.4.2) hangs when running shardTestFiles: true

When running protractor without sharding, it runs just fine, the tests are passing or failing, and in the end the webdriver / protractor execution stops.
When trying to run protractor with sharding, the execution works but when all the tests are done, the process hangs, the console doesn't display anything.
I stripped down the config file as much as possible to give more visibility.
I'm running protractor using
protractor conf --suite all
Conf file:
'use strict';
require('dotenv').config();
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
let config = {
framework: 'jasmine2',
baseUrl: process.env.CLUSTER_URL,
rootElement: 'body',
onPrepare: function () {
jasmine.getEnv().addReporter(new SpecReporter());
},
suites: {
all: [
'FoH/customerManagement/UI/*.smoke.spec.js',
'Other/logo/logo.*.spec.js'
]
},
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 2
}
};
exports.config = config;

What is the correct config settings to automate test in parallel using Protractor?

Here is my settings. Is there a correct setting for angular/non-angular application test in parallel? Sometimes, either my firefox or chrome hangs while the other one is running. Is it the ignoreSynchronization suppose to be set to true and waitForAngular to be false? I feel like there is too much time syncing problem that is causing one of the browsers to hang?
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 600000,
allScriptsTimeout: 500000,
defaultTimeoutInterval: 30000,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
multiCapabilities:
[{
'browserName': 'firefox',
specs: 'features/firefox/*.feature',
},
{
'browserName': 'chrome',
specs: 'features/chrome/*.feature',
}],
maxSessions: 2,
baseUrl: 'https://localhost:8080',
cucumberOpts: {
strict: true,
require: [
'hooks/hooks.js',
'specs/*Spec.js'
],
tags: [
"#runThis",
"~#ignoreThis"
],
profile: false,
format: 'json:./e2e/reports/cucumber-report.json',
resultJsonOutputFile: './e2e/reports/cucumber-report.json'
},
beforeLaunch: function() {
const fs = require('fs');
const path = require('path');
const directory = './e2e/reports';
//cleans up the json results from the previous build when using node flake
fs.readdir(directory, (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(directory, file), err => {
if (err) throw err;
});
}
});
},
onPrepare: function() {
var chai = require('chai');
chai.use(require('chai-as-promised'));
global.expect = chai.expect;
browser.ignoreSynchronization = true;
browser.manage().window().maximize();
browser.waitForAngular(false);
browser.manage().timeouts().implicitlyWait(30000);
},
ghostMode:false
}
browser.ignoreSynchronization is deprecated so you do not need to set that. However you do need to set browser.waitForAngularEnabled(false) instead of browser.waitForAngular(false) like you have in your conf. waitForAngular is what is called before every action when waitForAngularEnabled is true.
Setup your onPrepare like
onPrepare: function() {
var chai = require('chai');
chai.use(require('chai-as-promised'));
global.expect = chai.expect;
browser.manage().window().maximize();
browser.waitForAngularEnabled(false);
browser.manage().timeouts().implicitlyWait(30000);
},
Your specific situation will depend on what you are trying to achieve from your parallel execution.
This setup will divide your tests across 2 browser types, chrome and firefox, and execute your tests in parallel. It will support 3 chrome and 2 firefox browsers running at any one time. Tests are divided based on whichever finishing first
multiCapabilities: [
{ browserName: "chrome", shardTestFiles: true, maxInstances: 3 },
{ browserName: "firefox", shardTestFiles: true, maxInstances: 2 },
],
maxSessions: 10, //controls the total number of instances, won't be relevant in this case
This setup will execute all your tests on BOTH a chrome and firefox browser. If you are running 5 specs you will have 10 results.
multiCapabilities: [
{ browserName: "firefox" },
{ browserName: "chrome" },
],
Above given answers with adding shardTestFiles: true, and number of maxInstances should work. However I would still want to highlight that if you are using webdriver-manager start to start selenium server (which I think you are based on the selenium address given in config file) then do not expect that it will work as smooth as selenium grid solution to run tests in parallel on different browsers.
Webdriver-manager is designed as a quickest solution to start selenium server and is not a replacement of selenium-grid.

What is the command to run protractor tests in saucelabs

I am trying to run my protractor tests in saucelabs and cannot figure out what commands to use to run the tests. I have my sauceUser and sauceKey in the conf.js.
This is the command I usually use to run the test locally
export TEST_ENV='dev'; ./node_modules/.bin/protractor e2e/conf.js
exports.config = {
sauceUser: '<user>',
sauceKey: '<key>',
directConnect: true,
framework: 'mocha',
onComplete: function () {
},
onPrepare: function () {
// Declaring chai here so it can be accessed through out the tests and
// there is no need to declare it in every test.
var chai = require('chai');
chai.use(require('chai-smoothie'));
var chaiAsPromised = require('chai-as-promised');
var chaiSmoothie = require('chai-smoothie')
chai.use(chaiAsPromised);
chai.use(chaiSmoothie);
var expect = chai.expect;
global.chai = chai;
browser.manage().deleteAllCookies();
},
mochaOpts: {
timeout: 30000,
reporter: 'mochawesome-screenshots',
reporterOptions: {
reportDir: 'e2e/reports', //The directory which stores the reports
reportName: 'TestExecutionReport',
reportTitle: 'Reports',
reportPageTitle: 'customReportPageTitle',
clearOldScreenshots: false,
jsonReport: false,
multiReport: true,
overwrite: true
}
},
specs: [
'test-spec.js'
],
capabilities: {
'browserName': 'chrome',
'shardTestFiles': true,
'maxInstances': 1,
'chromeOptions': {
'args': ['show-fps-counter=true', 'incognito', '--window-size=1200,800', 'use-fake-ui-for-media-stream']
}
},
allScriptsTimeout: 12000,
getPageTimeout: 12000,
};

Pass parameters for each browser using Protractor

Just got started with Protractor for E2E testing.
I want to pass parameters (login and password) for each instance of chrome selenium server.
I want test the same spec file with different user account in parallel.
This is my conf.js :
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['--disable-web-security']
},
count: 10
},
You can use the onPrepare-method of Protractor for that. If multiple capabilities are being run, this will run once per capability. You can add data to the browser-object that you can use during your execution.
What you can do is something like this
// A JSON file or something
var login = {
"chrome": {
"user": "usernameChrome",
"pass": "passwordChrome"
},
"firefox": {
"user": "usernameFirefox",
"pass": "passwordFirefox"
}
};
// in your config
// An example configuration file.
exports.config = {
directConnect: true,
// Capabilities to be passed to the webdriver instance.
multiCapabilities: [{
'browserName': 'chrome'
},
{
'browserName': 'firefox'
}
],
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['example_spec.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
onPrepare: function() {
return browser.getCapabilities()
.then((capabilities) => {
// Get the current browser you are using
browser.browserName = capabilities.get('browserName').toLowerCase();
// Add the user and pass to the browser-object
browser.user = login[browser.browserName].user;
browser.pass = login[browser.browserName] pass;
});
}
};
// In your spec
describe('logon', function() {
it('should logon', function() {
browser.get('http://www.example.com');
element(by.model('user')).sendKeys(browser.user);
element(by.model('pass')).sendKeys(browser.pass);
element(by.tagName('button')).click();
});
});
You can handle this with Protractor's params on the command line. For example, you can start each test with a different username/password like this:
protractor conf.js --params.username user1 --params.password password1
Then, in your test, you would use them something like this:
logIntoMyApp(browser.params.username, browser.params.password);
You can also set defaults in your config file (see the docs for details).

Debugging protractor test in intellij idea

I have project and I use protractor test. But I would like use debugging but I don't know how to create config for him.
It is my protractor.conf.js
'use strict';
var paths = require('./.yo-rc.json')['generator-gulp-angular'].props.paths;
exports.config = {
capabilities: {
'browserName': 'chrome'
},
specs: [paths.e2e + '/**/*.js'],
mochaOpts: {
timeout: 5000
},
framework: 'mocha'
};
And e2e-tests.js gulp file:
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
module.exports = function(options) {
gulp.task('webdriver-update', $.protractor.webdriver_update);
gulp.task('webdriver-standalone', $.protractor.webdriver_standalone);
function runProtractor (done) {
gulp.src(options.e2e + '/**/**.js')
.pipe($.protractor.protractor({
configFile: 'protractor.conf.js'
}))
.on('error', function (err) {
// Make sure failed tests cause gulp to exit non-zero
throw err;
})
.on('end', function () {
// Close browser sync server
browserSync.exit();
done();
});
}
gulp.task('protractor', ['protractor:src']);
gulp.task('protractor:src', ['serve:e2e', 'webdriver-update'], runProtractor);
gulp.task('protractor:dist', ['serve:e2e-dist', 'webdriver-update'], runProtractor);
};
Help me please fix this issue because write code without quick watch and other good components not very well.