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,
};
Related
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.
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'
};
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).
As the question states, the requiring/importing of the module works fine in these cases:
const Session = require('../session.js').default;
or
import Session from '../session.js');
But I want to replace a module that is required inside session.js, so I tried to do that in a test with Proxyquireify:
const proxyquire = require('proxyquireify')(require);
const someStub = () => { return {}; };
someStub['#noCallThru'] = true;
const Session = proxyquire('../session.js', {
'some': someStub
}).default;
Then I get an error stating that the module '../session.js' cannot be found.
PhantomJS 1.9.8 (Linux 0.0.0) ERROR
Error: Cannot find module '../session.js'
My karma config is this:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['browserify', 'jasmine'],
files: [
'spec/**/*Spec.js'
],
exclude: [
'spec/**/PlayerSpec.js'
],
preprocessors: {
'spec/**/*Spec.js': ['browserify']
},
browserify: {
debug: true,
transform: ['babelify']
},
reporters: ['progress', 'dots'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false,
concurrency: Infinity
})
};
What could be wrong? Do you need any more information?
Just stumbled onto the same issue.
Noticed that proxyquireify did not inject require calls next to proxyquire ones for some reason, so I just ended up simply doing it myself, at least for now.
Try using something like this:
require('../session.js');
const Session = proxyquire('../session.js', ...);
I spent few hours on this issue and can't find what's wrong, I'm using karma/jasmine to create test in my angular app. I use, or at least try to use angular-mock to inject and test my controllers but I get this error :
Error: [$injector:unpr] Unknown provider: ENVProvider <- ENV
http://errors.angularjs.org/1.3.17/$injector/unpr?p0=ENVProvider%20%3C-%20ENV
in my test
describe('controllers', function(){
beforeEach(module('myModule'));
var $controller;
beforeEach(inject(function(_$controller_){
$controller = _$controller_;
}));
describe('$scope.testMessage', function() {
it('check the test message is ok', function() {
//TODO
});
});
});
So I suppose it's the inject call which cause the issue
here is my karma.conf.js
'use strict';
module.exports = function(config) {
var configuration = {
autoWatch : true,
frameworks: ['jasmine'],
ngHtml2JsPreprocessor: {
stripPrefix: 'src/',
moduleName: 'hematiteFront'
},
browsers : ['PhantomJS'],
plugins : [
'karma-phantomjs-launcher',
'karma-chrome-launcher',
'karma-jasmine',
'karma-ng-html2js-preprocessor'
],
files: [
'bower_components/jquery/dist/jquery.js',
'bower_components/angular/*.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-touch/angular-touch.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-ui-router/release/angular-ui-router.js',
'bower_components/angular-materialize/js/*.js',
'bower_components/angular-materialize/src/*.js',
'bower_components/angular-translate/angular-translate.js',
'bower_components/angular-translate-loader-partial/angular-translate-loader-partial.js',
'bower_components/angular-translate-storage-cookie/angular-translate-storage-cookie.js',
'bower_components/angular-mocks/angular-mocks.js',
'src/**/*.js'
],
logLevel: 'LOG_ERROR',
exclude: [
'src/app/app.constants.js',
'bower_components/**/index.js',
'bower_components/**/*.min.js'
],
preprocessors: {
'src/**/*.html': ['ng-html2js']
}
};
config.set(configuration);
};
Any idea or piece of advice would be more than wellcome
thanks