Multi Remote execution - webdriver-io

I am currently facing issue while trying achieve execution of Chrome Browser and Appium execution from browser stack from a single spec file
Below is the code written with multiple capabilities
Attaching log screensot
require('dotenv').config();
require('ts-node').register({ transpileOnly: true });
import { baseConfig as config } from '../test-android-e2e/config/wdio.base.android.conf';
import { baseConfig as configChrome } from '../test-wms-e2e/config/wdio.base.conf'; // inherits base config file
require('ts-node').register({ transpileOnly: true });
import _ from 'lodash';
import os from 'os';
import { TimelineService } from 'wdio-timeline-reporter/timeline-service';
let suiteName = '';
const overrides = {
updateJob: false,
specs: ['./test/specs/**/*.ts'],
specFileRetries: 4,
runner: process.env.RUNNER,
connectionRetryCount: 3,
framework: process.env.FRAMEWORK,
waitforTimeout: 10000,
connectionRetryTimeout: 90000,
exclude: [],
// ...
user: process.env.BROWSERSTACK_USER,
key: process.env.BROWSERSTACK_ACCESSKEY,
services: ['browserstack', [TimelineService], 'chromedriver'],
reporters: [
[
'allure',
{
outputDir: 'allure-results',
disableWebdriverStepsReporting: true,
disableWebdriverScreenshotsReporting: true,
},
],
['timeline', { outputDir: 'screenshots' }],
],
capabilities: {
Android: {
capabilities: [
{
'platformName': 'Android',
'appium:deviceName': 'Samsung Galaxy S21',
'appium:platformVersion': '11.0',
'appium:app': 'sampleid',
'bstack:options': {
'projectName': 'test-android-e2e',
idleTimeout: '300',
},
/* this locale will set device default location as US.
However it does not update language. Hence added separate capability for language */
'appium:locale': 'En-US',
'appium:language': 'En',
},
],
},
Chrome: {
capabilities: [
{
browserName: 'chrome',
'goog:chromeOptions': {
args: [
// 'user-agent=e2e-agent',
// '--headless',
'--disable-dev-shm-usage', // Force Chrome to use the /tmp directory instead. This may slow down the execution though.
'--disable-gpu',
'--no-sandbox',
'--window-size=1920,1080',
'--verbose',
'--trace-startup=-*,disabled-by-default-memory-infra',
'--trace-startup-file=/screenshots/trace.json',
'--trace-startup-duration=7',
],
},
},
],
},
// path: '/',
},
};
// Send the merged config to wdio
exports.config = _.defaultsDeep(overrides, config);
exports.config = _.defaultsDeep(overrides, configChrome);
Screenshot 1
Screenshot 2

Related

Is There a Problem with my Nightwatch.conf.js file?

I have been attempting to setup an automated testing framework for my job, and nodejs testing has seemed to be the best option for future scalability. Plus, I am attempting to stretch myself into new areas of QA.
I have setup my Nightwatch framework with npm install commands and manually installed the most up-to-date chrome drivers, and selenium standalone executables. I have attempted to ensure that my nightwatch.conf.js file is completely setup to run my first test with google chrome, but I get this error:
⚠ Error connecting to localhost on port 4444.
_________________________________________________
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (249ms)
✖ GoogleTest
An error occurred while retrieving a new session
Error: An error occurred while retrieving a new session
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Error: An error occurred while retrieving a new session
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
SKIPPED:
- Basic Google search
Which seems to be pretty generic. As per normal Nightwatch setup, I created a root folder called 'Automation' where I stuck my bin folder for the drivers and selenium framework. Inside of the 'Automation' folder I also have my nightwatch.conf.js file that I've setup (Let me know if its more helpful if I paste its code in here). In order to run my test, I use the npx nightwatch command, but I continue to get this error.
From what I can tell it may be due to me trying to run the tests locally, but I can't think of a way that I would configure the selenium service to accept local ports other than how it's been setup.
I don't know if this is a well formatted description of the problem, so I apologize in advance if this is super vague. If there's anything else I can do to help clear it up let me know.
Thank you!
Update Conf.js File
// Autogenerated by Nightwatch
// Refer to the online docs for more details: https://nightwatchjs.org/gettingstarted/configuration/
const Services = {}; loadServices();
module.exports = {
// An array of folders (excluding subfolders) where your tests are located;
// if this is not specified, the test source must be passed as the second argument to the test runner.
src_folders: ["tests"],
// See https://nightwatchjs.org/guide/working-with-page-objects/
page_objects_path: '',
// See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
custom_commands_path: '',
// See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-assertions
custom_assertions_path: '',
// See https://nightwatchjs.org/guide/#external-globals
globals_path : '',
webdriver: {},
test_settings: {
default: {
disable_error_log: false,
launch_url: 'https://nightwatchjs.org',
screenshots: {
enabled: false,
path: 'screens',
on_failure: true
},
desiredCapabilities: {
browserName : 'chrome'
},
webdriver: {
start_process: true,
server_path: (Services.chromedriver ? Services.chromedriver.path : '.Automation/bin/chromedriver.exe')
}
},
safari: {
desiredCapabilities : {
browserName : 'safari',
alwaysMatch: {
acceptInsecureCerts: false
}
},
webdriver: {
port: 4444,
start_process: true,
server_path: '/usr/bin/safaridriver'
}
},
firefox: {
desiredCapabilities : {
browserName : 'firefox',
alwaysMatch: {
// Enable this if you encounter unexpected SSL certificate errors in Firefox
// acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: [
// '-headless',
// '-verbose'
],
}
}
},
webdriver: {
start_process: true,
port: 4444,
server_path: (Services.geckodriver ? Services.geckodriver.path : './Automation/bin/geckodriver.exe'),
cli_args: [
// very verbose geckodriver logs
// '-vv'
]
}
},
chrome: {
desiredCapabilities : {
browserName : 'chrome',
chromeOptions : {
// This tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78)
w3c: true,
//More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
args: ['disable-gpu', 'no-sandbox', 'headless']
}
},
webdriver: {
start_process: true,
port: 9515,
server_path: (Services.chromedriver ? Services.chromedriver.path : './Automation/bin/chromedriver.exe'),
cli_args: [
// --verbose
]
}
},
//////////////////////////////////////////////////////////////////////////////////
// Configuration for when using the browserstack.com cloud service |
// |
// Please set the username and access key by setting the environment variables: |
// - BROWSERSTACK_USER |
// - BROWSERSTACK_KEY |
// .env files are supported |
//////////////////////////////////////////////////////////////////////////////////
browserstack: {
selenium: {
host: 'hub-cloud.browserstack.com',
port: 443
},
// More info on configuring capabilities can be found on:
// https://www.browserstack.com/automate/capabilities?tag=selenium-4
desiredCapabilities: {
'bstack:options' : {
local: 'false',
userName: '${BROWSERSTACK_USER}',
accessKey: '${BROWSERSTACK_KEY}',
}
},
disable_error_log: true,
webdriver: {
keep_alive: true,
start_process: false
}
},
'browserstack.chrome': {
extends: 'browserstack',
desiredCapabilities: {
browserName: 'chrome',
chromeOptions : {
// This tells Chromedriver to run using the legacy JSONWire protocol
// More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
w3c: true,
args: ['disable-gpu', 'no-sandbox', 'headless']
}
}
},
'browserstack.firefox': {
extends: 'browserstack',
desiredCapabilities: {
browserName: 'firefox'
}
},
'browserstack.ie': {
extends: 'browserstack',
desiredCapabilities: {
browserName: 'IE',
browserVersion: '11.0',
'bstack:options' : {
os: 'Windows',
osVersion: '10',
local: 'false',
seleniumVersion: '3.5.2',
resolution: '1366x768'
}
}
},
//////////////////////////////////////////////////////////////////////////////////
// Configuration for when using the Selenium service, either locally or remote, |
// like Selenium Grid |
//////////////////////////////////////////////////////////////////////////////////
selenium: {
// Selenium Server is running locally and is managed by Nightwatch
selenium: {
start_process: true,
port: 4444,
server_path: (Services.seleniumServer ? Services.seleniumServer.path : './Automation/bin/selenium-server-standalone-3.141.59.jar'),
cli_args: {
'webdriver.gecko.driver': (Services.geckodriver ? Services.geckodriver.path : './Automation/bin/geckodriver.exe'),
'webdriver.chrome.driver': (Services.chromedriver ? Services.chromedriver.path : './Automation/bin/chromedriver.exe')
}
}
},
'selenium.chrome': {
extends: 'selenium',
desiredCapabilities: {
browserName: 'chrome',
chromeOptions : {
w3c: true,
args: ['disable-gpu', 'no-sandbox', 'headless']
}
}
},
'selenium.firefox': {
extends: 'selenium',
desiredCapabilities: {
browserName: 'firefox',
'moz:firefoxOptions': {
args: [
// '-headless',
// '-verbose'
]
}
}
}
}
};
function loadServices() {
try {
Services.seleniumServer = require('selenium-server');
} catch (err) {}
try {
Services.chromedriver = require('chromedriver');
} catch (err) {}
try {
Services.geckodriver = require('geckodriver');
} catch (err) {}
}
What I will suggest is to create a create a new file for Nightwatch.conf.js and then start adding rest of the configuration from there. Below is an example which works for me:
module.exports = {
src_folders: ["tests"],
skip_testcases_on_fail: false,
page_objects_path: "pageObjects",
custom_commands_path: "./commands",
screenshots: {
enabled: true,
path: "./screenshots",
on_failure: true,
on_error: true
},
test_settings: {
default: {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
prefs: {
download: {
default_directory: require('path').resolve(__dirname + '/download')
}
}
},
},
webdriver: {
start_process: true,
port: 4444,
server_path: require('chromedriver').path,
}
},
test_workers: {
enabled: true,
workers: 'auto'
},
safari: {
desiredCapabilities: {
browserName: 'safari',
alwaysMatch: {
acceptInsecureCerts: false
}
},
webdriver: {
port: 4445,
start_process: true,
server_path: '/usr/bin/safaridriver'
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox'
},
webdriver: {
start_process: true,
port: 4446,
server_path: require('geckodriver').path
}
}
}
}
The Nightwatch JS, chromedriver, geckodriver are installed using the npm commands. Since I am using a mac I just needed to enable the safari webdriver.
npm install nightwatch --save-dev
npm install geckodriver --save-dev
npm install chromedriver --save-dev
safaridriver --enable
This is the full repo if you want to have a look: https://github.com/alapanme/NightwatchJS
Also if you need the detailed steps how I setup Nightwatch on my machine you can refer: https://testersdock.com/nightwatch-js-installation/

Webdriverio selenium standalone doesn't update driver version

I made little demo projects with WebdriverIO 6, Typescript and cucumber.
I have put this in the configuration file wdio.CHROME.conf.ts:
import { config } from './wdio.conf';
import { CHROME_ARGS } from './chrome-args';
const seleniumConfig = {
version: '3.141.59',
drivers: { chrome: { version: '87.0.4280.20' } },
};
const browserOptions: WebDriver.ChromeOptions & { args: Array<string> } = {
args: [
...CHROME_ARGS,
...(process.argv.includes('--headless') ? ['--headless', '--no-sandbox'] : []),
'--window-size=1920,1080',
],
};
const seleniumOpts = config.services?.find(
(service) => Array.isArray(service) && service[0] === 'selenium-standalone'
) as SeleniumStandaloneOptions;
seleniumOpts.args = { ...seleniumConfig };
seleniumOpts.installArgs = { ...seleniumConfig };
console.log(seleniumOpts);
const browserConfig: WebdriverIO.Config = {
...config,
capabilities: [
{
browserName: 'chrome',
'goog:chromeOptions': browserOptions,
},
],
};
exports.config = browserConfig;
And this in wdio.conf.ts:
import * as path from 'path';
import * as appRoot from 'app-root-path';
import { commandsFactory } from './commands-factory';
export const config: WebdriverIO.Config = {
specs: [
'./src/features/**/*.feature',
// './src/features/login.feature',
// './src/features/dashboard.feature'
],
exclude: [
],
maxInstances: 1,
logLevel: 'trace',
bail: 0,
baseUrl: 'http://automationpractice.com',
waitforTimeout: 10000,
connectionRetryTimeout: 90000,
connectionRetryCount: 3,
services: [
[
'selenium-standalone',
{
logs: 'logs',
},
],
],
outputDir: path.join(appRoot.path, '/logs'),
framework: 'cucumber',
reporters: [
'spec',
[
'allure',
{
outputDir: 'allure-results',
disableWebdriverStepsReporting: true,
disableWebdriverScreenshotsReporting: false,
useCucumberStepReporter: true,
},
],
],
cucumberOpts: {
backtrace: false,
failAmbiguousDefinitions: true,
failFast: false,
ignoreUndefinedDefinitions: false,
name: [],
snippets: false,
source: true,
profile: [],
require: [
'./src/step_definitions/*.ts',
],
snippetSyntax: undefined,
strict: true,
tagExpression: 'not #Login',
tagsInTitle: false,
timeout: 60000,
},
before(capabilities, specs) {
const commands = commandsFactory({ waitForTimeout: this.waitforTimeout });
/* eslint-disable */
const chai = require('chai');
global.should = chai.should();
// Sample command
function browserCustomCommandExample(text) {
console.log(text);
}
browser.addCommand('browserCustomCommandExample', browserCustomCommandExample);
Object.keys(commands).forEach((key) => {
browser.addCommand(key, commands[key]);
});
},
afterStep(step, context, { error, result, passed, duration }) {
if (error) {
browser.takeScreenshot();
}
},
};
But after I do npm install and try to run tests npm run test:chrome:headless, I get this error:
[0-0] Error: Failed to create session.
session not created: This version of ChromeDriver only supports Chrome version 85
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'LAPTOP-QUTK6LBV', ip: '192.168.1.8', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_271'
Driver info: driver.version: unknown
I have tried to update version of the driver in wdio.CHROME.conf.ts to 87, but it didn't help.
It just doesn't download version 87 of chrome driver, instead it is stuck with version 85.
When I look at the node_modules\selenium-standalone\.selenium\chromedriver there is only version 85 and it wouldn't download the version 87 (85 was previous version I had in configuration file).
On my machine, chrome browser version is 87 and it needs the same version of chrome driver in order to work (from my understanding :D )
I tried deleting node_modules and doing it from scratch but with no success.
This is link to my repo https://github.com/mareru/webdriverIO-shop-demo
Can someone please help :)
Thanks!
I replaced these lines:
const seleniumOpts = config.services?.find(
(service) => Array.isArray(service) && service[0] === 'selenium-standalone'
) as SeleniumStandaloneOptions;
seleniumOpts.args = { ...seleniumConfig };
seleniumOpts.installArgs = { ...seleniumConfig };
With these ones
config.services = [
[
'selenium-standalone',
{
logs: 'logs',
args: seleniumConfig,
installArgs: seleniumConfig,
},
],
];
And it worked. It seems like previous code didn't generate the curly braces well.
Parameters logs, args, installArgs should have been in joint curly brace not in separate curly braces.
It generated this:
[
'selenium-standalone',
{ logs: 'logs' },
args: { version: '3.141.59', drivers: [Object] },
installArgs: { version: '3.141.59', drivers: [Object] }
]
]
While it should have been like this
[
[
'selenium-standalone',
{ logs: 'logs', args: [Object], installArgs: [Object] }
]
]

Can not load reporter "coverage-istanbul"

I am trying to run code coverage using https://webpack.js.org/loaders/istanbul-instrumenter-loader/
Here is the karma.conf.js
var testWebpackCfg = require('../webpack/webpack.config.test.js');
module.exports = function(config) {
config.set({
basePath: '../../',
frameworks: ['jasmine'],
plugins: [ 'karma-webpack', 'karma-jasmine-jquery', 'karma-jasmine', 'karma-chrome-launcher','karma-firefox-launcher', 'karma-coverage','karma-spec-reporter', 'karma-jasmine-html-reporter'],
preprocessors: {
'client/test/index.js': ['webpack']
},
reporters: [ 'spec', 'coverage-istanbul'],
coverageIstanbulReporter: {
reports: [ 'text-summary' ],
dir: './coverage',
fixWebpackSourcePaths: true
},
files: [
'client/test/index.js'
],
webpack: testWebpackCfg,
// web server port
port: 9876,
runnerPort: 9100,
urlRoot: '/',
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
browsers: ['Chrome'],
singleRun: true
});
};
Webpack config
{
test: /\.js$/i,
exclude: [
paths.appNodeModules
],
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: ['#babel/preset-env']
}
},
{
loader: require.resolve('istanbul-instrumenter-loader'),
options: {
esModules: true
}
}
]
}
On running the Karma I see this error
'Can not load reporter "coverage-istanbul", it is not registered!
Perhaps you are missing some plugin?'
The error got resolved by adding karma-coverage-istanbul-reporter in the karma config plugin.
npm i karma-coverage-istanbul-reporter --save-dev
karma.conf.js
{
...
plugins: ['karma-coverage-istanbul-reporter']
...
}
I faced the same problem after upgrading to Angular 14 from 11. Adding the Istanbul reporter compared to the Karma reporter solved my issue.
So simply add coverage-istanbul to your reporters in karma.conf.js
Like:
reporters: ['progress', 'kjhtml', 'coverage-istanbul'],
For example:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '#angular-devkit/build-angular'],
plugins: [
...
],
client: {
...
},
coverageIstanbulReporter: {
...
},
reporters: ['progress', 'kjhtml', 'coverage-istanbul'],
})
}
Nishant gives the essential answer, but I found I also got this message when I had not specified the karma config file explicitly, as per this answer:
cant get junit running with Karma

Webdriver cannot connect to Selenium server

I am currently trying to set up webdriver and selenium together to run my automation tests through docker but am facing issues. Each time i try to run the tests I get the following error ERROR wdio-runner: Error: connect ECONNREFUSED 127.0.0.1:4444
I am using the selenium/standalone-chrome from docker and can see that the server is configured correctly and running at 127.0.0.1:4444 as I can hit it.
When I try to run webdriver however I seem to face the issue mentioned above. I believe the issue must be something in my webdriver config but having followed the documentation I can't see what's wrong...
const chai = require('chai');
const chaiWebdriver = require('chai-webdriverio').default;
const debug = process.env.DEBUG;
exports.config = {
runner: 'local',
host: '127.0.0.1',
port: 4444,
path: '/wd/hub',
specs: ['specs/**/*.js'],
suites: {
smoke: ['specs/smoke-spec.js']
},
maxInstances: 10,
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {}
},
sync: true,
logLevel: 'error',
coloredLogs: true,
deprecationWarnings: false,
bail: 0,
debug,
execArgv: debug ? ['--inspect'] : [],
screenshotOnReject: true,
screenshotPath: './error-screenshots',
baseUrl: https://localhost:443,
waitforTimeout: 30000,
connectionRetryTimeout: 90000,
connectionRetryCount: 3,
seleniumLogs: './selenium-logs',
framework: 'mocha',
reporters: [
[
'allure',
{
outputDir: 'test-output',
disableWebdriverStepsReporting: true,
disableWebdriverScreenshotsReporting: false
}
],
['spec', {}]
],
mochaOpts: {
ui: 'bdd',
timeout: 400000,
compilers: ['js:babel-register']
},
before() {
chai.use(chaiWebdriver(browser));
global.expect = chai.expect;
},
afterTest: test => {
if (!test.passed) {
browser.takeScreenshot();
}
}
};

How to disable custom protocol handler for protractor?

I have a Protractor test suite for an application that uses a custom protocol handler to pass messages out of an iOS web view.
When testing it with protractor, how do I prevent the custom window.location = "app://doThing"; message from breaking my tests? It shows the "Open xdg-open?" popup and doesn't continue with tests.
My protractor configuration looks like this:
exports.config = {
...,
multiCapabilities: [ {
browserName: 'chrome',
chromeOptions: {
args: [ '--lang=en', '--window-size=1024x768' ]
},
specs: 'test-*.js',
} ]
};
I achieved this in Chrome 60 by setting the preferences inside the chromeOptions block.
exports.config = {
...,
multiCapabilities: [ {
browserName: 'chrome',
chromeOptions: {
args: [ '--lang=en', '--window-size=1024x768' ],
// Replace "app" with your app's custom scheme.
prefs: {
protocol_handler: {
excluded_schemes: {
"app": true
}
}
},
},
specs: 'test-*.js',
} ]
};
Before Chrome 60, I enforced a profile folder for the Chrome runner. You can do that by having a folder named "/chrome-profile" in the Chrome docker container for example, and adding one file in it named "Default State" with the following content:
{
"protocol_handler": {
"excluded_schemes": {
"app": true
}
}
}
And after that, setting the Chrome user-data-dir flags as such:
exports.config = {
...,
multiCapabilities: [{
'browserName': 'chrome',
'chromeOptions' : {
args: ['--lang=en',
'--window-size=1024,768',
'--user-data-dir=/chrome-profile/']
},
specs: ['test-*.js']
}]
};