Protractor multiCapabilities on single browser - protractor

I am trying to write a single Protractor config file to test a website on desktop/laptop, Android, and iPhone cases.
The following works:
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: process.env.JHI_E2E_HEADLESS
? ['--headless', '--disable-gpu', '--window-size=800,600']
: ['--disable-gpu', '--window-size=800,600'],
},
},
The following also works:
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: process.env.JHI_E2E_HEADLESS
? ['--headless', '--disable-gpu', '--window-size=800,600']
: ['--disable-gpu', '--window-size=800,600'],
mobileEmulation: {
deviceName: 'iPhone 6/7/8 Plus'
},
},
},
However, the following fails with the error
[chrome #01] [16:06:44] I/direct - Using ChromeDriver directly...
[chrome #01] [16:06:45] I/runnerCli - Unexpected token {
multiCapabilities: [
{
name: 'ChromeDesktop',
browserName: 'chrome',
chromeOptions: {
args: process.env.JHI_E2E_HEADLESS
? ['--headless', '--disable-gpu', '--window-size=800,600']
: ['--disable-gpu', '--window-size=800,600'],
},
},
{
name: 'ChromeAndroid',
browserName: 'chrome',
chromeOptions: {
args: process.env.JHI_E2E_HEADLESS
? ['--headless', '--disable-gpu', '--window-size=360,640']
: ['--disable-gpu', '--window-size=360,640'],
mobileEmulation: {
deviceName: 'Galaxy S5'
},
},
},
],
Can anyone kindly explain what I am doing wrong?

Adding below in protractor conf should work -
onPrepare: function () { require('ts-node').register({ project: 'e2e' }); }
Link To Related GitHub Issue with Accepted Solution -> It has the details why onPrepare should be used instead of default beforeLaunch for enabling multiple capabilities for browsers.

Related

Using protractor with directconnect=true - how to fix - This version of ChromeDriver only supports Chrome version

package.json
{
"name": "test1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "npm run webdriver-update && npm run test-protractor",
"test-protractor": "protractor protractor.conf.js",
"webdriver-update": "webdriver-manager update"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cucumber": "^6.0.5",
"jasmine-spec-reporter": "^4.2.1",
"protractor": "^5.4.2",
"protractor-cucumber-framework": "^6.2.0",
"rimraf": "^3.0.1"
}
}
protractor.conf.js
const protractor = require('protractor');
// console.log('browser = ', browser);
exports.config = {
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
getPageTimeout: 60000,
allScriptsTimeout: 500000,
specs: ['features/*.feature'],
baseURL: 'http://www.google.com/',
cucumberOpts: {
require: [
'./features/step_definitions/stepDefinitions.js'
],
tags: false,
profile: false,
'no-source': true
},
onPrepare: function() {
// browser.ignoreSynchronization = true;
// browser.manage().window().maximize();
// browser.manage().timeouts().implicitlyWait(5000);
},
capabilities: {
browserName: "chrome",
chromeOptions: {
args: [
'--headless',
'--disaple-gpu',
'--window-size=1920,1080',
'--no-sandbox',
'--disable-dev-shm-usage'
],
prefs: {
download: {
prompt_for_download: false,
extensions_to_open: ''
},
profile: {
default_content_settings: {
popups: 0
}
},
directory_upgrade: true
},
useAutomationExtension: false
}
},
// connec direct to webdriver, instead of local selenium server!
directConnect: true,
ignoreUncaughtException: true,
onComplete: () => {
// Reporter.createHtmlReport();
}
}
Error
Session not created: This version of ChromeDriver only supports Chrome version 80
I can manually set update-config.json andhave downloaded many different chromedriver versions, but I still get the same error.
Example:
update-config.json
{"standalone":{"last":"node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar","all":["node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar"]},"gecko":{"last":"node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.26.0.exe","all":["node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.26.0.exe"]},"chrome":{"last":"node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_75.0.3770.8.exe","all":["node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_75.0.3770.8.exe","node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_75.0.3770.8.exe"]}}
Error
E/launcher - session not created: This version of ChromeDriver only supports Chrome version 75
This is version 75, so what is happening exactly?
I am not using angular. I am using directconnect=true, and set everything to be headless. I did have it working at one point but lost the code and stuck in this loop.
ok, so I have followed the advice from this thread:
- protractor 2.5.4 E/launcher - session not created: This version of ChromeDriver only supports Chrome version 79
I am now using chromedriver version: 78.0.3904.105.
node node_modules/protractor/bin/webdriver-manager clean
node node_modules/protractor/bin/webdriver-manager update
node node_modules/protractor/bin/webdriver-manager --versions.chrome=78.0.3904.105
Ensure this version - chromedriver_78.0.3904.105 - is updated in all references in update-config.json file.
update-config.json
{
"standalone":{
"last":"node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar",
"all":[
"node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar"
]
},
"gecko":{
"last":"node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.26.0.exe",
"all":[
"node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.26.0.exe"
]
},
"chrome":{
"last":"node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_78.0.3904.105.exe",
"all":[
"node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_78.0.3904.105.exe",
"node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_78.0.3904.105.exe"
]
}
}
run protractor with option: --no-webdriver-update
"scripts": {
"test": "npm run test-protractor --no-webdriver-update"
},
Now it works!

Protractor tests Azure Pipelines - using Internet Explorer

We have a big set of automated tests using Protractor/Jasmine which work like a dream on Azure Pipelines. However, so far we've only used Chrome as the browser.
Now i have to run the same tests using Internet Explorer (11) but am getting no joy at all!!
Here's a part of my conf.js file that deals with the browser:
var HtmlReporter = require('protractor-beautiful-reporter');
var {SpecReporter} = require("jasmine-spec-reporter");
var jasmineReporters = require("jasmine-reporters");
exports.config = {
//seleniumAddress: `http://localhost:4444/wd/hub`,
framework: "jasmine2",
specs: ['specs/secureTrading/01_SecureTrading.js',
'specs/secureTrading/02_ST_Payments.js'
],
getPageTimeout: 40000,
allScriptsTimeout: 60000,
capabilities: {
'browserName': 'internet explorer',
'ignoreProtectedModeSettings': true,
'platform': 'ANY',
'version': '11',
args: ['--silent', '--no-sandbox', '--test-type=browser', '--lang=US', '--start-maximized'], //,'--headless', '--disable-gpu'
prefs: {
'download': {
'prompt_for_download': false,
'directory_upgrade': true,
'extensions_to_open': '',
'default_directory': process.cwd() + '/downloads/'
},
}
},
localSeleniumStandaloneOpts: {
jvmArgs: [
'-Dwebdriver.ie.driver=node_modules/protractor/node_modules/webdriver-manager/selenium/IEDriverServer3.14.0.exe'
]
},
directConnect: false,
seleniumArgs: ['-Dwebdriver.ie.driver=node_modules/protractor/node_modules/webdriver-manager/selenium/IEDriverServer3.14.0.exe'],
ignoreUncaughtExceptions: true,
onPrepare: function() {
Having looked at other postings, I've tried removing // from seleniumAddress:http://localhost:4444/wd/hub,` still errors, Changing DirectConnect makes no difference.
With the settings as above, this is the error message.
Any advice please?
Thanks
Additional Logs as per comment below.
Local:

How to pass arguments by command line for multicapabilities on protractor?

I need to pass headless arguments by command line.
In the begining I was working just with Chrome and I was using the following code to pass these arguments:
./node_modules/.bin/protractor "conf.js" --capabilities.chromeOptions.args=headless --capabilities.chromeOptions.args=disable-gpu --capabilities.chromeOptions.args=window-size=1248,1024
This is working properly, the problem is when I added firefox capabilities.
The qwestion: How can I pass this "headless" argument by command line with multiCapabilities?
I tried with:
./node_modules/.bin/protractor "conf.js" --multiCapabilities.1.chromeOptions.args=headless --multiCapabilities.1.chromeOptions.args=disable-gpu --multiCapabilities.1.chromeOptions.args=window-size=1248,1024 --multiCapabilities.0.moz:firefoxOptions=headless
But didn't work.
My config file:
exports.config = {
onPrepare: async function () {
console.log("Let's Start")
},
seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 100000,
allScriptsTimeout: 100000,
restartBrowserBetweenTests: true,
maxSessions: 2,
multiCapabilities: [{
browserName: 'firefox',
parallelCapability: false,
marionette: true,
"moz:firefoxOptions":{
//args: [ "--headless" ],
prefs:{
'pdfjs.disabled': true
}
},
'safebrowsing': {
'enabled': true,
}
}
,{
browserName: 'chrome',
parallelCapability: false,
'chromeOptions': {
prefs: {
download: {
'prompt_for_download': false,
'directory_upgrade': true,
'default_directory': process.cwd() + '/download/'
},
'safebrowsing': {
'enabled': true,
}
}
},
},
],
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
specs: [
'features/happyPath.feature'
],
cucumberOpts: {
require: [
'features/step_definitions/**/*.js',
'lib/hooks.js'],
profile: false,
'no-source': true
}
};
You have to specify the browser name
--multiCapabilities.0.browserName chrome
--multiCapabilities.1.browserName firefox

How to read file that has been downloaded on selenium grid for protractor e2e tests?

Here is my capabilities settings :
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--no-sandbox'],
prefs: {
'download': {
prompt_for_download: false,
directory_upgrade: true,
default_directory: process.cwd()
}
}
}
}
and it fails when I am trying to read this file
also I tried adding '/temp to the default directory please advise

unexpected token import using karma with webpack and babel

I'm trying to run karma tests using karma, webpack and babel. I feel like I've configured properly but it seems that the test files are not being transpiled.
karma.conf:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha', 'chai'],
files: [
{pattern: 'src/**/*-test.js', watched: false}
],
exclude: [
],
preprocessors: {
'src/**/*-test.js': ['webpack']
},
webpack: require("./webpack.config.js"),
webpackMiddleware: {
stats: 'errors-only'
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
}
webpack.config:
module.exports = {
entry: [
'react-hot-loader/patch',
'webpack/hot/only-dev-server',
path.resolve(__dirname, 'src/index.js')
],
output: {
filename: 'bundle.js'
},
module: {
rules: [
{ test: /\.(js|jsx)$/, exclude: /(\/node_modules\/|test\.js$)/, use: 'babel-loader'},
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
{ test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader'] },
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, use: 'url-loader?limit=100000' }
]
},
resolve: {
extensions: ['.js', '.jsx']
}
};
My test file uses import syntax to import expect from chai and runs a simple test taht expects true is equal true but when I run the karma I'm getting
uncaught syntaxerror: unexpected token import
I've had a look at similar question:
Karma + Webpack (babel-loader) + ES6 "Unexpected token import"
but no luck. I'm sure it's something simple in my configs. Has anyone seen similar?
this is a new project so using latest packages, webpack2 etc.
Any ideas greatly appreciated
C