How to generate multiple cucumber reports for protractor with multicapabilities? - protractor

I am running protractor against BrowserStack with multiple browser in parallel. Please refer to 'Speed up testing section in 'https://www.browserstack.com/automate/protractor.
It works great, however if I use 4 instances of webdriver to run the same feature files in parallel, it will 1 html cucumber report.
I've googled this: https://github.com/wswebcreation/protractor-multiple-cucumber-html-reporter-plugin, which seems to be able to generate multiple json file, but no html files.
I am new to protractor. Could anyone give some suggestions, or some code change or plugin that can make this happen?
Thank,

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var JasmineReporters = require('jasmine-reporters');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine2',
multiCapabilities: [
{
browserName: 'chrome',
shardTestFiles: false,
maxInstances: 1,
specs: [
'./tmp/specs1.spec.js',
'./tmp/specs2.spec.js'
],
chromeOptions: {
args: [
'--window-size=1920,1080'],
prefs: {
download: {
prompt_for_download: false,
default_directory: './downloads',
}
}
}
},
{
browserName: 'chrome',
shardTestFiles: false,
maxInstances: 1,
specs: [
'./tmp/specs3.spec.js',
'./tmp/specs4.spec.js'
],
chromeOptions: {
args: [
'--window-size=1920,1080'],
prefs: {
download: {
prompt_for_download: false,
default_directory: './downloads',
}
}
}
}
],
allScriptsTimeout: 600000,
jasmineNodeOpts: {
defaultTimeoutInterval: 600000,
showColors: true
},
onPrepare: function() {
browser.driver.getCapabilities().then(function(caps) {
browser.browserName = caps.get('browserName');
});
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
browser.getProcessedConfig().then(function(config) {
var capabilities = config.capabilities;
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: './reports/',
takeScreenshots: true,
screenshotsFolder: './screenshots',
filePrefix: 'protractor-demo-tests-report-' + capabilities.platform + '-' + capabilities.browserName,
consolidateAll: false,
takeScreenshotsOnlyOnFailures: true,
})
);
});
var jasmineReporters = require('jasmine-reporters');
return browser.getProcessedConfig().then(function(config) {
// you could use other properties here if you want, such as platform and version
var browserName = config.capabilities.browserName;
var junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: false,
savePath: 'reports/jUnitXmlReporter',
modifyReportFileName: function(generatedFileName, suite) {
return browserName + '.' + generatedFileName;
}
});
jasmine.getEnv().addReporter(junitReporter);
//set window size to max available
setTimeout(function() {
browser.driver.executeScript(function() {
return {
width: window.screen.availWidth,
height: window.screen.availHeight
};
}).then(function(result) {
browser.driver.manage().window().setPosition(0,0);
browser.driver.manage().window().setSize(result.width, result.height);
});
});
});
}
};

Related

Protractor - headless execution for parallel test is failing

Trying to run two instances of webdriver with headless chrome browser.
Getting below error when ran with protractor-beautiful-reporter
I/runnerCli - ENOENT: no such file or directory, unlink 'Results/Jsons/000000d8-003c-0046-00f3-00a30045006c.json'
conf.js
let HtmlReporter = require('protractor-beautiful-reporter');
exports.config = {
framework: 'jasmine',
directConnect: true,
allScriptsTimeout: 900000,
getPageTimeout: 120000,
onPrepare: function () {
jasmine.getEnv().addReporter(new HtmlReporter({
filename: 'MVP.html',
baseDirectory: 'Results',
preserveDirectory: false,
takeScreenShotsOnlyForFailedSpecs: true,
screenshotsSubfolder: 'Screenshots',
jsonsSubfolder: 'Jsons',
docTitle: 'PM UI Test Result',
sortFunction: function sortFunction(a, b) {
if (a.instanceId < b.instanceId) return -1;
else if (a.instanceId > b.instanceId) return 1;
if (a.timestamp < b.timestamp) return -1;
else if (a.timestamp > b.timestamp) return 1;
return 0;
},
clientDefaults: {
showTotalDurationIn: 'belowHeader',
totalDurationFormat: 'hms'
}
}).getJasmine2Reporter());
},
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ["--headless", "--window-size=1920,1200"]
},
acceptSslCerts: true,
trustAllSSLCertificates: true,
acceptInsecureCerts: true,
ACCEPT_SSL_CERTS: true,
maxInstances: 2,
shardTestFiles: true
},
jasmineNodeOpts: {
defaultTimeoutInterval: 900000,
},
specs: ['../tests/abc.js',
'../tests/xyz.js'
],
};

Wait and Sleep does not work on protractor

I'm having trouble testing a screen with automated tests, I'm filling in all input fields and then pushing the submit button, but wait / sleep doesn't seem to be working this causes the button to be pressed before the input is filled.
Why is my sleep / wait not working?
describe('Wizard - Organizacional data - Test Plan - 150454', function () {
const functionsPage = new functionObjectPage();
it('148454 - Incluir informações do administrador e Escritório.', function() {
browser.wait(until.presenceOf(element(by.id('openWizard'))), 30000, '');
browser.executeScript("document.querySelector('#openWizard').click()");
browser.executeScript("document.querySelector('#usuarioPrincipal').value = 'User master'");
browser.executeScript("document.querySelector('#emailUsuarioPrincipal').value = 'master#master.com'");
browser.executeScript("document.querySelector('#officeName').value = 'Office Name'");
browser.executeScript("document.querySelector('#cnpj').value = '57375882000197'");
browser.sleep(5500);
browser.executeScript("document.querySelector('#btnNextStep').click()");
});
});
I don't know if browser.ignoreSynchronization = true; influences how sleep / wait works, or if any other config can influence it.
This is my protactor config:
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
var env = process.env.env || 'local';
var config = require('./e2e/src/helper/config')[env];
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
directConnect: true,
capabilities: {
browserName: 'chrome'
},
SELENIUM_PROMISE_MANAGER: false,
framework: 'jasmine',
specs: [
'./e2e/src/*_spec.js',
],
suites: {
pages: './e2e/src/*_spec_suite.js',
},
baseUrl: config.baseUrl,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 2000000,
print: function () {}
},
onPrepare: function () {
require('jasmine2-custom-message');
var jasmineReporters = require('jasmine-reporters');
var junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'testresults',
filePrefix: 'reportXMLoutput'
});
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: 'testresults/screenshots'
}));
jasmine.getEnv().addReporter(junitReporter);
jasmine.getEnv().addReporter(new SpecReporter({
suite: {
displayNumber: true
},
spec: {
displayStacktrace: true,
displayErrorMessages: true,
displaySuccessful: true,
displayFailed: true,
displayPending: true,
displayDuration: true
}
}));
browser.ignoreSynchronization = true;
browser.driver.manage().timeouts().implicitlyWait(15000);
browser.driver.manage().window().maximize();
}
};
You have SELENIUM_PROMISE_MANAGER: false in your config which means you need to use async/await to perform step synchronously
describe('Wizard - Organizacional data - Test Plan - 150454', () => {
const functionsPage = new functionObjectPage();
it('148454 - Incluir informações do administrador e Escritório.', async () => {
await browser.wait(until.presenceOf(element(by.id('openWizard'))), 30000, '');
await browser.executeScript("document.querySelector('#openWizard').click()");
etc..
etc..

TypeError: protractorImageComparison is not a constructor

I try to run comparison tests and get Error: TypeError: protractorImageComparison is not a constructor. please advice
The same code worked in the full angular project but i needed to sperated the testing from the code.
i added my conf.file and the spec file
//protractor.conf.js:
const { SpecReporter } = require('jasmine-spec-reporter').SpecReporter;
exports.config = {
allScriptsTimeout: 15000,
specs: [
'src/tests/*.e2e-spec.js'
],
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['no-sandbox']
}
},
directConnect: true,
baseUrl: 'https://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare: function() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json')
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
const protractorImageComparison =require('protractor-image-comparison');
browser.driver.manage().window().setSize(1366, 768);
browser.protractorImageComparison = new protractorImageComparison({
baselineFolder: '.\\e2e\\src\\screenshots\\baseline',
screenshotPath: '.\\e2e\\src\\screenshots\\actual_screenshots',
autoSaveBaseline: true
});
},
};
//test
import {browser } from 'protractor';
import {LoginPage} from '../pages/login.po';
describe('login page', function() {
beforeEach(function()
{
LoginPage.navigateTo();
});
it('login page should match the design', () => {
expect(browser.protractorImageComparison.checkScreen('login_Page')).toEqual(0);
});
});
If you are using the latest protractor-image-comparison, it appears that it says you should use it as a plugin. The constructor itself has been moved to https://github.com/wswebcreation/protractor-image-comparison/blob/master/lib/index.ts#L9 and is not exported.
The plugin should be added in your Protractor config per the readme file:
plugins: [
{
// The module name
package: 'protractor-image-comparison',
// Some options, see the docs for more
options: {
baselineFolder: join(process.cwd(), './baseline/'),
formatImageName: `{tag}-{logName}-{width}x{height}`,
screenshotPath: join(process.cwd(), '.tmp/'),
savePerInstance: true,
// ... more options
},
},
],

Protractor E/launcher - Process exited with error code 199

when i run gulp to start protractor i got this error
E/launcher - unknown error: cannot parse capability: proxy
from unknown error: proxyType is 'manual' but no manual proxy capabilities were found
(Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299
x86_64)
protractor version 5.1.1
gulpfile
ar gulp = require('gulp');
var path = require('path');
var child_process = require('child_process');
var requireDir = require('require-dir');
requireDir('./config/gulp/tasks');
var runSequence = require('run-sequence');
var open = require('gulp-open');
gulp.task('default', [
//'complete'
'protractor-test'
]);
function getBinary(packageName, binaryLocation) {
var pkgPath = require.resolve(packageName);
return path.resolve(path.join(path.dirname(pkgPath), '..', binaryLocation));
}
gulp.task('protractor-install', function(done) {
var binary = getBinary('webdriver-manager', '../bin/webdriver-manager');
child_process.spawn('node', [binary, 'update --versions.chrome 2.29'], {
stdio: 'inherit'
}).once('close', function() {
done();
});
});
gulp.task('protractor-start', function(done) {
var binary = getBinary('protractor', 'bin/protractor');
child_process.spawn('node', [binary, 'protractor.conf.js'], {
stdio: 'inherit'
}).once('close', function() {
gulp.src('protractor-results/report.html')
.pipe(open({ app: 'chrome' }));
done();
});
});
gulp.task('t', function() {
runSequence('start-server',
'start-proxy',
'protractor-start',
'stop-servers');
});
gulp.task('debug-proxy', function(done) {
child_process.spawn('C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe', ['--proxy-server=http=localhost:8080', '--user-data-dir=C:\\tmp', 'http://localhost:49852'], {
stdio: 'inherit'
}).once('close', function() {
done();
});
});
and the config of protractor
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
}
}
},
'proxy': {
'proxyType': 'manual',
'httpsProxy': 'localhost:3000'
}
},
framework: 'jasmine',
specs: [
'Tests/Common/common-e2e-spec.js',
// 'Tests/S4B/skype4-business-e2e-spec.js',
// 'Tests/CM/client-management-e2e-spec.js',
// 'Tests/MC/manage-compute-e2e-spec.js'
],
useAllAngular2AppRoots: true,
baseUrl: 'https://localhost:44300',
beforeLaunch: function() {
return new Promise(function(resolve) {
screenshotreporter.beforeLaunch(resolve);
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(screenshotreporter);
jasmine.getEnv().addReporter(xmlreporter1);
jasmine.getEnv().addReporter(xmlreporter2);
},
afterLaunch: function(exitCode) {
return new Promise(function(resolve) {
screenshotreporter.afterLaunch(resolve.bind(this, exitCode));
});
},
jasmineNodeOpts: {
//1 minute timeout
defaultTimeoutInterval: 60000,
showTiming: true,
print: function() {}
}
};
Make sure to run gulp without sudo!!!

Unable to take test report from multiple browsers at a time using protractor

I am unable to take Test report for Multiple browsers at a time using protractor.
I tried below code
var Jasmine2HtmlReporter = require('C:/Users/agudla/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
exports.config = {
allScriptsTimeout: 11000,
seleniumAddress : 'http://localhost:4444/wd/hub',
multiCapabilities : [
{'browserName' : 'firefox'},
{'browserName' : 'chrome'}
],
suites : {
jobs : [
'e2e/Jobs/Manage Jobs/ApplyJobs/ApplyJobs.e2e-spec.ts',]
},
baseUrl : 'http://localhost:4200/',
framework : 'jasmine2',
jasmineNodeOpts : {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
//jasmine.getEnv().addReporter(reporter);
browser.getProcessedConfig().then(function(config){
var capabilities = config.capabilities;
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath : '',
fileName : 'protractor-report-'+capabilities.platform+'-'+capabilities.browserName,
takeScreenshotOnlyOnFailure : true
})
);
});
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
I run "selenium webdriver server" from the command prompt and run the test scripts . The Jasmine html report is always displaying the latest browser result , in this case it is always displaying "firefox" browser related test report.
I want to take test report from both "chrome and fire fox" browsers at a time. Can any one suggest me how to do this?
Use below code for multi-capability reporting. you can refer my repo on github for more details.
Click here
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var log4js = require('log4js');
var params = process.argv;
var args = process.argv.slice(3);
exports.config = {
//seleniumServerJar: './node_modules/gulp-protractor/node_modules/protractor/selenium/selenium-server-standalone-2.48.2.jar',
seleniumAddress: 'http://localhost:4444/wd/hub',
allScriptsTimeout: 10000,
framework: 'jasmine2',
onPrepare: function () {
return new Promise(function(fulfill, reject) {
browser.getCapabilities().then(function(value) {
reportName = 'protractor-report-' + '_' + value.get('browserName') + '_' + Math.floor(Math.random()*1E16);
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: __dirname+'/target',
docTitle: 'Web UI Test Report',
screenshotsFolder: '/image',
//takeScreenshots: true,
takeScreenshotsOnlyOnFailures: true,
consolidate: true,
consolidateAll: true,
preserveDirectory: true,
//cleanDirectory: false,
//fixedScreenshotName: true,
fileName: "my-report.html",
fileNamePrefix: reportName
})
);
fulfill();
});
});
},
afterLaunch: function afterLaunch() {
var fs = require('fs');
var output = '';
fs.readdirSync('target/').forEach(function (file) {
if (!(fs.lstatSync('target/' + file).isDirectory()))
output = output + fs.readFileSync('target/' + file);
});
fs.writeFileSync('target/ConsolidatedReport.html', output, 'utf8');
},
suites:{
example:['./test/e2e/specs/**/*Spec.js',]
},
multiCapabilities: [
{
'browserName': 'chrome'
},
{
'browserName': 'firefox'
}
],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 200000
}
};