I have one file of config which runs tests in one browser using capabilities.
Now I have created one more separate config file which contains multiCapabilites and will run same tests in multiple browsers.
I want to optimize configs so I second config file I write multiCapabilities for first config and used
delete firstConfig['capabilities'];
to ignore the capabilities from first config and use all other params from firstConfig and use multiCapabilities from 2nd config and run.
Expected result:
params in configs should not be duplicated in both configs, only multiCapabilities is the change, rest of config is same.
Use a base configuration file
Having a base configuration file and another file that extends from it might be a better approach. For this example, we will look at my base configuration file:
var env = require('./environment');
// This is the configuration for a smoke test for an Angular TypeScript application.
exports.config = {
seleniumAddress: env.seleniumAddress,
framework: 'jasmine',
specs: [
'ng2/async_spec.js'
],
capabilities: env.capabilities,
baseUrl: env.baseUrl,
allScriptsTimeout: 120000,
getPageTimeout: 120000,
jasmineNodeOpts: {
defaultTimeoutInterval: 120000
}
};
Create a second config from the base config
From there, we did something similar to your question where we removed the capabilities and added multicapabilities. (https://github.com/angular/protractor/blob/master/spec/ciNg2Conf.js). In addition, since we were running on Sauce Labs, we also decided to increase our timeouts.
exports.config = require('./angular2Conf.js').config;
exports.config.sauceUser = process.env.SAUCE_USERNAME;
exports.config.sauceKey = process.env.SAUCE_ACCESS_KEY;
exports.config.seleniumAddress = undefined;
// TODO: add in firefox when issue #2784 is fixed
exports.config.multiCapabilities = [{
'browserName': 'chrome',
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
'build': process.env.TRAVIS_BUILD_NUMBER,
'name': 'Protractor suite tests',
'version': '54',
'selenium-version': '2.53.1',
'chromedriver-version': '2.26',
'platform': 'OS X 10.11'
}];
exports.config.capabilities = undefined;
exports.config.allScriptsTimeout = 120000;
exports.config.getPageTimeout = 120000;
exports.config.jasmineNodeOpts.defaultTimeoutInterval = 120000;
I hope that helps.
Update:
Per comments below, setting the config.capabilities to undefined did not work; however, setting config.capabilities to false did work.
Prepare a capabilities provider to define vary capabilities, and exports a function to return a capabilities array according to the cmd line params.
// capabilities.provider.js
var capabilities = {
chrome: {
browserName: 'chrome'
},
chrome-headless {
browserName: 'chrome',
},
firefox: {
browsername: 'firefox'
},
...
};
exports.evaluate=function(){
var caps = 'chrome';
process.argv.slice(3).forEach(function(kvp){
if(kvp.includes('--caps=')) {
caps = kvp.split('=')[1] || caps;
}
})
var _caps = [];
caps.split(',').forEach(function(cap){
if(Object.keys(capabilities).includes(cap)) {
_caps.push(capabilities[cap])
}
})
return _caps;
};
protractor config.js
var capsProvider = require('./capabilities.provider');
exports.config = {
seleniumAddress: '',
framework: 'jasmine',
specs: [
'ng2/async_spec.js'
],
params: {
},
multiCapabilities: capsProvider.evaluate(),
baseUrl: env.baseUrl,
allScriptsTimeout: 120000,
getPageTimeout: 120000,
jasmineNodeOpts: {
defaultTimeoutInterval: 120000
}
};
Specify caps from cmd line:
protractor config.js --caps=chrome,firefox,ie,safari
Related
Is there any way to debug Webdriverio tests using nodeJS and WebStorm?
I've found some conclusion here and this is actually my problem: Run WebdriverIO tests via Mocha in WebStorm
But this solution doesn't fit to my problem now;
I've set up Babel to compile my BDD tests
I've set tests.config.js
module.exports = { maxInstances: 1,
capabilities: [{ browserName: 'chrome' }],
execArgv: ['--inspect'] : [],
specs: ['**/some/spec.js']
mochaOpts: {
ui: 'bdd',
compilers: ['js:#babel/register'],
timeout: 150000
} }
and babel.conf.js
module.exports = {
presets: [
['#babel/preset-env', {
targets: {
node: 12
}
}]
]
}
then I've created nodeJS configuration like it said here at answer: Run WebdriverIO tests via Mocha in WebStorm
Set breakpoint at test
describe("test", function(){
it ("this is a BDD test",
function(){
breakpoint here>> do_some_action();
})
})
But when I try to launch my tests in debug mode nothing happens and I see "connnected to localhost:port" message. and I can't go to breakpoint; there are no errors;
there was problem with a wdio.conf.js file. If you don't set specs file >> there aren't no errors. But launching is incorrect. I've set config like this:
module.exports =
{
capabilities: [{
maxInstances: 6,
browserName: 'chrome',
baseUrl: "some-url/",
browserVersion: '67.0'}]
specs: [
'./this/is/spec.js']
mochaOpts: {
ui: 'bdd',
require: ['#babel/register'],
timeout: 150000
},
And debug works after this. It's not too har as I though :) If there are some questions - > I'm glad o answer
I'm new to frontend world, I would like to write some test using protractor-image-comparison. I followed installation instructions from https://github.com/wswebcreation/protractor-image-comparison. Also I make configuration according to this page.
When I try to use functions form this lib I get following error: "TypeError: Cannot read property 'checkFullPageScreen' of undefined". I'm getting a warrning in protractor.conf.js in
const protractorImageComparison = require('protractor-image-comparison');
"Could not find a declaration file for module
'protractor-image-comparison'.
'/home/rafa/repos/example/src/example/node_modules/protractor-image-comparison/index.js'
implicitly has an 'any' type. Try npm install
#types/protractor-image-comparison if it exists or add a new
declaration (.d.ts) file containing declare module
'protractor-image-comparison';"
So I did, I made simple *.d.ts file with `declare module protractor-image-comparison' in it, but it didn't solve the problem just the warning disappear. It's propably the config issue, but I can't handle it or maybe I made wrong declaration. This is my config file :
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const reporter = require("cucumber-html-reporter");
const path = require("path");
const jsonReports = path.join(process.cwd(), "/reports/json");
const htmlReports = path.join(process.cwd(), "/reports/html");
const targetJson = jsonReports + "/cucumber_report.json";
const cucumberReporterOptions = {
jsonFile: targetJson,
output: htmlReports + "/cucumber_reporter.html",
reportSuiteAsScenarios: true,
theme: "bootstrap",
};
exports.config = {
allScriptsTimeout: 110000,
restartBrowserBetweenTests: true,
//SELENIUM_PROMISE_MANAGER: false,
specs: [
'./e2e/**/login.feature'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
format: "json:" + targetJson,
require: ['./e2e/steps/*.ts', "./e2e/timeout.ts"],
},
useAllAngular2AppRoots: true,
onPrepare: () => {
browser.ignoreSynchronization = true;
const protractorImageComparison = require('protractor-image-comparison');
browser.protractorImageComparison = new protractorImageComparison(
{
baselineFolder: "report/screens/baseline",
screenshotPath: "report/screens/actual"
}
);
},
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e'
});
},
onComplete: () => {
reporter.generate(cucumberReporterOptions);
}
};
Ok, I solved it. The reason why I was getting this TypeError is that I lunched few test scenarios and onPrepare was lunched only in the begining. I move config of protractor-image-comparison to cucumber befor hook and everything works fine now.
I have a setup of my angular-app and a separate selenium server as docker-compose setup
my protractor setting looks like this
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: false,
baseUrl: 'http://user-frontend:4200/',
seleniumAddress: 'http://selenium:4444/wd/hub',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
now I run the command to run the end2end tests using protractor:
ng e2e --no-serve
All my tests are failing, and when I debug the selenium server and take screenshots, I see it is trying to connect to itself (localhost) instead of back to the application host baseUrl: 'http://user-frontend:4200/',
any Idea what I am doing wrong here?
Are you sure that browser.baseUrl (or browser.get()) is not set elsewhere?
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 am attempting to add Code Coverage for my Karma tests, however although it finds the correct JS files that I'm testing, it does not find the functions inside those files.
From what I have read so far I believe it to be to do with the files not being correctly browserified before being passed to istanbul to do the coverage, but admittedly I am new to this so I'm hoping for some suggestions.
Here is my JS file(common.js):
var applicationSettings = require('./settings');
var common = {
getAjaxBaseUrl: function () {
var strVirtualDirectory = applicationSettings.VirtualDirectory;
if (strVirtualDirectory.length > 1) {
if (!strVirtualDirectory.startsWith("/")) {
strVirtualDirectory = "/" + strVirtualDirectory;
}
}
return strVirtualDirectory;
}
}
module.exports = common;
And here are the tests I have written:
it('Client - Should get correct AjaxBaseUrl with /', function () {
var clientSettings = require('./../client/scripts/settings');
var clientCommon = require('./../client/scripts/common');
clientSettings.VirtualDirectory = '/VD';
expect(clientCommon.getAjaxBaseUrl()).to.equal('/VD');
});
it('Client - Should get correct AjaxBaseUrl without /', function () {
var clientSettings = require('./../client/scripts/settings');
var clientCommon = require('./../client/scripts/common');
clientSettings.VirtualDirectory = 'VD';
expect(clientCommon.getAjaxBaseUrl()).to.equal('/VD');
});
My Karma.conf is below:
// Karma configuration
// Generated on Mon Jan 11 2016 09:43:00 GMT+0000 (GMT Standard Time)
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['phantomjs-shim', 'browserify', 'mocha'],
// list of files / patterns to load in the browser
files: [
'https://code.jquery.com/jquery-2.2.0.min.js',
'http://cdn.kendostatic.com/2015.3.1111/js/kendo.all.min.js',
'test_unit/*Spec.js',
'client/scripts/*.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test_unit/*Spec.js': ['browserify'],
'client/scripts/*.js': ['browserify', 'coverage']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'coverage', 'junit'],
// Configure jUnit reporter
junitReporter: {
outputDir: '', // results will be saved as $outputDir/$browserName.xml
outputFile: undefined, // if included, results will be saved as $outputDir/$browserName/$outputFile
suite: '', // suite will become the package name attribute in xml testsuite element
useBrowserName: true // add browser name to report and classes names
},
// Configure coverage reporter
coverageReporter: {
type: 'html',
dir: 'test_coverage',
subdir: '.',
file: 'coverage.htm'
},
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
browserify: {
configure: function (bundle) {
bundle.transform('reactify', { extensions: ['.jsx'] });
}
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
})
}
This does produce a report, but this shows 100% and the only line found in the common.js file is:
require("C:\\Source\\ProjectName\\client\\scripts\\common.js");
I attempted to add Browerify-Istanbul into the mix, by adding a require for it at the top of the Karma.conf an additional transform in the browserify section
bundle.transform(istanbul)
However this just makes my tests fail and throw several errors:
undefined is not an object (evaluating
'__cov_qQLFhXEMt7fatxiMx0_vQQ.b[' 1'][0]')
getAjaxBaseUrl#C:/Users/CHARLE~1.WIC/AppData/Local/Temp/0d61da722d2838c9
600d83d1cbb4c0b8.browserify:43:1498
C:/Users/CHARLE~1.WIC/AppData/Local/Temp/0d61da722d2838c9600d83d1cbb4c0b
8.browserify:51742:1849
16 02 2016 09:14:08.515:ERROR [coverage]: [TypeError: Cannot read
property 'star t' of undefined] TypeError: Cannot read property
'start' of undefined
at C:\Source\ProjectName\node_modules\istanbul\lib\o bject-utils.js:59:44
at Array.forEach (native)
at Object.addDerivedInfoForFile (C:\Source\ProjectName\node_modules\istanbul\lib\object-utils.js:58:37)
at Object.Collector.fileCoverageFor (C:\Source\ProjectName\node_modules\istanbul\lib\collector.js:94:15)
at C:\Source\ProjectName\node_modules\istanbul\lib\r eport\html.js:558:90
at Array.forEach (native)
at HtmlReport.Report.mix.writeReport (C:\Source\ProjectName\node_modules\istanbul\lib\report\html.js:557:27)
at writeReport (C:\Source\ProjectName\node_modules\k arma-coverage\lib\reporter.js:62:16)
at C:\Source\ProjectName\node_modules\karma-coverage \lib\reporter.js:288:11
at C:\Source\ProjectName\node_modules\karma\lib\help er.js:82:7
at FSReqWrap.oncomplete (fs.js:82:15)
Am I missing something, or going about this the wrong way?
I had the exact same issue. What worked for me was removing "coverage" from the preprocessors section AND using browserify-istanbul. Also, you want to configure browserify-istanbul to ignore your test files.
So your preprocessors should look something like (removed 'coverage'):
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test_unit/*Spec.js': ['browserify'],
'client/scripts/*.js': ['browserify']
},
And your browserify config should look something like:
browserify: {
configure: function (bundle) {
bundle.transform('reactify', { extensions: ['.jsx'] });
bundle.transform(require('browserify-istanbul')({
ignore: ['**/test_unit/**']
}));
}
},
Hope that helps
For me the solution was to:
delete 'coverage' in the array of values of *.js files from preprocessors index into karma.conf
Hope that helps