Parallel run in Chrome - node.js

I am trying to implement parallel test execution in Chrome to reduce the test execution time. The framework being used is protractor-cucumber framework with Node JS. The webdriver instances open up in two tabs rather than two separate windows of Chrome.
Used the multicapabilities in the config file to set testsharding as true and maxinstances as 2:
multiCapabilities: [
{
shardTestFiles: true,
maxInstances: 4,
browserName: chrome,
specs: ['*.spec.js']
},
Chrome is opening 2 tabs instead of windows and the tests are not getting distributed across the tabs.

Full config as requested
const path = require("path");
const jsonReports = process.cwd() + "/reports/json";
exports.config = {
seleniumAddress: "http://localhost:4444/wd/hub",
baseUrl: "https://www.google.co.uk",
multiCapabilities: [
{
browserName: "chrome",
shardTestFiles: true,
maxInstances: 2
}
],
framework: "custom",
frameworkPath: require.resolve("protractor-cucumber-framework"),
specs: ["../features/*.feature"],
onPrepare: function() {
browser.ignoreSynchronization = true;
browser.manage().window().maximize();
Reporter.createDirectory(jsonReports);
},
cucumberOpts: {
strict: true,
format: 'json:./reports/json/cucumber_report.json',
require: ["../stepDefinitions/*.js"],
tags: "(#AllureScenario or #CucumberScenario or #ProtractorScenario) and (not #DatabaseTest)" //
},
onComplete: function () {
}
};

Related

Is there any way to run webdriver.io selenium tests against a chrome extension?

I'm thinking something along the lines of
capabilities: [
{
maxInstances: 1,
browser: "Chrome",
name: "Chrome"
},
{
maxInstances: 1,
browser: "Chrome",
options: "myIeExtension",
name: "IE"
}
]
The name bit is optional but would be really handy.
Edit:
Currently I've got
const fs = require('fs');
function encode(file) {
const stream = fs.readFileSync(file);
return Buffer.from(stream).toString('base64');
}
capabilities: [
{
maxInstances: 1,
browserName: 'chrome',
chromeOptions: { extensions: [encode('path_to_my_crx_file/my_extension.crx')] },
}
],
which works, but each time I run the selenium tests I have to go through the extension intro - enter email, password, select this that and launch. Is there any way to get round having to have selenium enter all these values as part of the test?
So you can do it as above specifying the path to the chrome extension in ChromeOptions. However you have to set it up every time.
Alternatively just use the default profile:
capabilities: [
{
maxInstances: 1,
browserName: 'chrome',
chromeOptions: { args: ['user-data-dir=/home/<username>/.config/google-chrome'] },
},
You won't have to set up the extension every time you use it, you just have to do it once and then it'll just be there.

protractor-jasmine2-screenshot-reporter not generating screenshots in the required folder

My protractor.conf.js has the following content. I was unable to find out whats wrong here. I have manually created target/screenshots in my root folder of angular-cli. When i run protractor conf.js the protractor tests in browser window but the screenshots aren't being generated. Can anyone help me resolve this?
// Protractor configuration file
const { SpecReporter } = require('jasmine-spec-reporter');
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var fs = require('fs');
var reporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'my-report.html',
cleanDestination: false,
showSummary: true,
showConfiguration: false,
reportTitle: null,
ignoreSkippedSpecs: false,
captureOnlyFailedSpecs: false,
reportOnlyFailedSpecs: false
});
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: false,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
chromeOnly: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(reporter);
},
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
Thanks in Advance!
You can check by adding the 'protractor-screenshoter-plugin'
plugins: [{
package: 'protractor-screenshoter-plugin',
screenshotPath: <specify the path>,
screenshotOnExpect: 'failure',
screenshotOnSpec: 'failure+success',
withLogs: 'true',
writeReportFreq: 'asap',
imageToAscii: 'failure',
htmlReport:'true',
verbose:'info',
clearFoldersBeforeTest: true,
failTestOnErrorLog: {
failTestOnErrorLogLevel: 900
}
},
Can also check https://www.npmjs.com/package/protractor-screenshoter-plugin
protractor-jasmine2-screenshot-reporter compatible with jasmine2, so change to framework: 'jasmine2' in your conf.js
And you need to use higher version of Protractor which includes jasmine2
I did a quick test with your conf(did little changes) and it worked.
conf.js
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
// var fs = require('fs');
var reporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'my-report.html',
cleanDestination: false,
showSummary: true,
showConfiguration: false,
reportTitle: null,
ignoreSkippedSpecs: false,
captureOnlyFailedSpecs: false,
reportOnlyFailedSpecs: false
});
exports.config = {
allScriptsTimeout: 11000,
// specs: [
// './e2e/**/*.e2e-spec.ts'
// ],
capabilities: {
'browserName': 'chrome'
},
directConnect: false,
// baseUrl: 'http://localhost:4200/',
framework: 'jasmine2',
// chromeOnly: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
jasmine.getEnv().addReporter(reporter);
},
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
spec.js
describe('xxx', function(){
it('yyy', function(){
browser.get('https://angular.io/');
});
});
target/screenshots folder and HTML report,
(I run for twice, so there are two screenshots.)
click the yyy will open the screenshot
protractor-jasmine2-screenshot-reporter will create target/screenshots folder if not exist, no need to create in advance.
Version I used:
protractor 5.3.0
protractor-jasmine2-screenshot-reporter 0.5.0

Error while using "Protractor jasmine 2 screen shot reporter"

I am trying to take the "Screen shot" of the web page when the "test case fails".
I installed "protractor-jasmine2-screenshot-reporter" using "npm".
I am using below data.
1.Node -- v6.11.4
2.NPM -- 3.10.10
3.Protractor -- 5.1.2
My "Protractor.conf.js" file code below.
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: 'C:/Users/agudla/Desktop/VSCodeWorkSpace/my-app/screenshots',
filename: 'my-report.html'
});
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
multiCapabilities: [{
'browserName': 'chrome',
'seleniumAddress':'http://localhost:4444/wd/hub'
},
{'browserName': 'firefox',
'marionette': 'false',
'seleniumAddress':'http://localhost:4444/wd/hub'
}
],
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
beforeLaunch: function() {
return new Promise(function(resolve){
reporter.beforeLaunch(resolve);
});
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(reporter);
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
I am getting below error message while running the test script.
ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444
Can any one help me to solve this issue.
It is working now , i run "Selenium server" and i changed the var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter'); as
var Jasmine2HtmlReporter = require('C:/Users/agudla/AppData/Roaming/npm/node_modules/protractor-jasmine2-html-reporter');
Should have to provide complete "path" for the "protractor jasmine2 html reporter".
To know the "protractor jasmine2 html reporter" path in your system , type below command in command prompt.
npm link protractor-jasmine2-html-reporter
It will print the complete path .

Protractor + RequireJS

Please, show me how to use Protractor with RequireJS.
code works
var dentalConfig = require('./conf/dentalConfig.js');
var login = require('./pages/login.js');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: dentalConfig.baseUrl,
specs: [
'pages/company.js'
],
onPrepare: function () {
login();
}
};
but if i put exports.config inside of requirejs()
protractor throw error:
c:\Users\UserName\AppData\Roaming\npm\node_modules\protractor\lib\configParser.js:184
fileConfig.configDir = path.dirname(filePath);
TypeError: Cannot set property 'configDir' of undefined.
this doesn't work
var requirejs = require('requirejs');
requirejs.config({
baseUrl: './',
nodeRequire: require
});
requirejs([
'conf/dentalConfig',
'pages/login'
],
function (dentalConfig, login) {
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: dentalConfig.baseUrl,
specs: [
'pages/company.js'
],
onPrepare: function () {
login();
}
};
}
);
Your config file should look something like this..
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect: true,
framework: 'jasmine',
specs: ['TestScript name that has to be executed.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose:true,
includeStackTrace:true
},
capabilities: {
'browserName': 'chrome',
},
}

angular-phonecat tutorial: protractor.js unexpected behavior under Chrome Canary

I’m setting things up in order to run the angular-phonecat tutorial using Chrome Canary under OS X as a testing browser.
I got everything working, except when I input npm run protractor the e2e test runs on SAFARI of all browsers, despite the fact that I’ve specified Chrome Canary as the browser name in the protractor-conf.js file. Here’s the code:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/*.js'
],
capabilities: {
'browserName': 'ChromeCanary',
'ChromeOptions': {
'binary': '/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary'
}
},
chromeOnly: false,
baseUrl: 'http://localhost:8000/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
When I set chromeOnly: true, the test returns an ELIFECYCLE error. I find this very awkward since the same browser name is specified in the Karma configuration file and the unit test runs on Canary as expected. Here’s the karma.conf.js code:
module.exports = function(config){
config.set({
basePath : '../',
files : [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-resource/angular-resource.js',
'app/bower_components/angular-animate/angular-animate.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/js/**/*.js',
'test/unit/**/*.js'
],
autoWatch : true,
frameworks: ['jasmine'],
browsers : ['ChromeCanary'],
plugins : [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine'
],
junitReporter : {
outputFile: 'test_out/unit.xml',
suite: 'unit'
}
});
};
Two questions:
What could be causing this behavior?
What else could I tinker with to get the e2e test to run on Canary?
I was able to get this working with Chrome Canary by simply reusing the Chrome browserName but providing an alternate binary path. Here's the snippet that will work for your example above.
capabilities: {
'browserName': 'Chrome',
'ChromeOptions': {
'binary': '/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary'
}
Probably easier to abstract this into a separate browsers.js file so you can use both canary and chrome like this.
exports.chrome = {
name: 'Chrome',
browserName: 'chrome',
chromeOptions: {
'args': [
'incognito',
'disable-extensions',
'start-maximized',
'enable-crash-reporter-for-testing'
]
}
};
exports.chromeCanary = {
name: 'ChromeCanary',
browserName: 'chrome',
chromeOptions: {
'binary': 'C:/Users/gattridg/AppData/Local/Google/Chrome SxS/Application/chrome.exe',
'args': [
'incognito',
'disable-extensions',
'start-maximized',
'enable-crash-reporter-for-testing'
]
}
};
Then in your protractor.conf.js
var browsers = require('./browsers'),
multiCapabilities: [
browsers.chrome
browsers.chromeCanary
],

Resources