ERROR #wdio/cli:utils: A service failed in the 'onPrepare' hook - appium

Facing this issue and already post of similar doesn't have solution, So re-posting this again with more logs and info.
Below is my wdio.conf.js file.
const path = require('path')
exports.config = {
//
// ====================
// Runner Configuration
// ====================
//
port: 4723,
path: '/wd/hub',
//
// ==================
// Specify Test Files
// ==================
// Define which test specs should run. The pattern is relative to the directory
// from which `wdio` was called.
//
// The specs are defined as an array of spec files (optionally using wildcards
// that will be expanded). The test for each spec file will be run in a separate
// worker process. In order to have a group of spec files run in the same worker
// process simply enclose them in an array within the specs array.
//
// If you are calling `wdio` from an NPM script (see https://docs.npmjs.com/cli/run-script),
// then the current working directory is where your `package.json` resides, so `wdio`
// will be called from there.
//
specs: [
'./test/specs/**/*.js'
],
// Patterns to exclude.
exclude: [
// 'path/to/excluded/files'
],
//
// ============
// Capabilities
// ============
// Define your capabilities here. WebdriverIO can run multiple capabilities at the same
// time. Depending on the number of capabilities, WebdriverIO launches several test
// sessions. Within your capabilities you can overwrite the spec and exclude options in
// order to group specific specs to a specific capability.
//
// First, you can define how many instances should be started at the same time. Let's
// say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have
// set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec
// files and you set maxInstances to 10, all spec files will get tested at the same time
// and 30 processes will get spawned. The property handles how many capabilities
// from the same test should run tests.
//
maxInstances: 1,
//
// If you have trouble getting all important capabilities together, check out the
// Sauce Labs platform configurator - a great tool to configure your capabilities:
// https://saucelabs.com/platform/platform-configurator
//
capabilities: [{
"platformName": "Android",
"appium:udid": "emulator-5554",
"appium:automationName": "UiAutomator2",
"appium:app": "C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk"
}],
//
// ===================
// Test Configurations
// ===================
// Define all options that are relevant for the WebdriverIO instance here
//
// Level of logging verbosity: trace | debug | info | warn | error | silent
logLevel: 'info',
//
// Set specific log levels per logger
// loggers:
// - webdriver, webdriverio
// - #wdio/browserstack-service, #wdio/devtools-service, #wdio/sauce-service
// - #wdio/mocha-framework, #wdio/jasmine-framework
// - #wdio/local-runner
// - #wdio/sumologic-reporter
// - #wdio/cli, #wdio/config, #wdio/utils
// Level of logging verbosity: trace | debug | info | warn | error | silent
// logLevels: {
// webdriver: 'info',
// '#wdio/appium-service': 'info'
// },
//
// If you only want to run your tests until a specific amount of tests have failed use
// bail (default is 0 - don't bail, run all tests).
bail: 0,
//
// Set a base URL in order to shorten url command calls. If your `url` parameter starts
// with `/`, the base url gets prepended, not including the path portion of your baseUrl.
// If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
// gets prepended directly.
baseUrl: 'http://localhost',
//
// Default timeout for all waitFor* commands.
waitforTimeout: 10000,
//
// Default timeout in milliseconds for request
// if browser driver or grid doesn't send response
connectionRetryTimeout: 120000,
//
// Default request retries count
connectionRetryCount: 3,
//
// Test runner services
// Services take over a specific job you don't want to take care of. They enhance
// your test setup with almost no effort. Unlike plugins, they don't add new
// commands. Instead, they hook themselves up into the test process.
// services: [
// 'appium'
// ],
services: [
['appium', {
args: {
address: 'localhost',
port: 4723
},
logPath:'./',
}]
],
// Framework you want to run your specs with.
// The following are supported: Mocha, Jasmine, and Cucumber
// see also: https://webdriver.io/docs/frameworks
//
// Make sure you have the wdio adapter package for the specific framework installed
// before running any tests.
framework: 'mocha',
//
// The number of times to retry the entire specfile when it fails as a whole
// specFileRetries: 1,
//
// Delay in seconds between the spec file retry attempts
// specFileRetriesDelay: 0,
//
// Whether or not retried specfiles should be retried immediately or deferred to the end of the queue
// specFileRetriesDeferred: false,
//
// Test reporter for stdout.
// The only one supported by default is 'dot'
// see also: https://webdriver.io/docs/dot-reporter
reporters: ['spec'],
//
// Options to be passed to Mocha.
// See the full list at http://mochajs.org/
mochaOpts: {
ui: 'bdd',
timeout: 60000
},
//
// =====
// Hooks
// =====
// WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
// it and to build services around it. You can either apply a single function or an array of
// methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
// resolved to continue.
/**
* Gets executed once before all workers get launched.
* #param {Object} config wdio configuration object
* #param {Array.<Object>} capabilities list of capabilities details
*/
// onPrepare: function (config, capabilities) {
// },
/**
* Gets executed before a worker process is spawned and can be used to initialise specific service
* for that worker as well as modify runtime environments in an async fashion.
* #param {String} cid capability id (e.g 0-0)
* #param {[type]} caps object containing capabilities for session that will be spawn in the worker
* #param {[type]} specs specs to be run in the worker process
* #param {[type]} args object that will be merged with the main configuration once worker is initialized
* #param {[type]} execArgv list of string arguments passed to the worker process
*/
// onWorkerStart: function (cid, caps, specs, args, execArgv) {
// },
/**
* Gets executed just after a worker process has exited.
* #param {String} cid capability id (e.g 0-0)
* #param {Number} exitCode 0 - success, 1 - fail
* #param {[type]} specs specs to be run in the worker process
* #param {Number} retries number of retries used
*/
// onWorkerEnd: function (cid, exitCode, specs, retries) {
// },
/**
* Gets executed just before initialising the webdriver session and test framework. It allows you
* to manipulate configurations depending on the capability or spec.
* #param {Object} config wdio configuration object
* #param {Array.<Object>} capabilities list of capabilities details
* #param {Array.<String>} specs List of spec file paths that are to be run
* #param {String} cid worker id (e.g. 0-0)
*/
// beforeSession: function (config, capabilities, specs, cid) {
// },
/**
* Gets executed before test execution begins. At this point you can access to all global
* variables like `browser`. It is the perfect place to define custom commands.
* #param {Array.<Object>} capabilities list of capabilities details
* #param {Array.<String>} specs List of spec file paths that are to be run
* #param {Object} browser instance of created browser/device session
*/
// before: function (capabilities, specs) {
// },
/**
* Runs before a WebdriverIO command gets executed.
* #param {String} commandName hook command name
* #param {Array} args arguments that command would receive
*/
// beforeCommand: function (commandName, args) {
// },
/**
* Hook that gets executed before the suite starts
* #param {Object} suite suite details
*/
// beforeSuite: function (suite) {
// },
/**
* Function to be executed before a test (in Mocha/Jasmine) starts.
*/
// beforeTest: function (test, context) {
// },
/**
* Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
* beforeEach in Mocha)
*/
// beforeHook: function (test, context) {
// },
/**
* Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
* afterEach in Mocha)
*/
// afterHook: function (test, context, { error, result, duration, passed, retries }) {
// },
/**
* Function to be executed after a test (in Mocha/Jasmine only)
* #param {Object} test test object
* #param {Object} context scope object the test was executed with
* #param {Error} result.error error object in case the test fails, otherwise `undefined`
* #param {Any} result.result return object of test function
* #param {Number} result.duration duration of test
* #param {Boolean} result.passed true if test has passed, otherwise false
* #param {Object} result.retries informations to spec related retries, e.g. `{ attempts: 0, limit: 0 }`
*/
// afterTest: function(test, context, { error, result, duration, passed, retries }) {
// },
/**
* Hook that gets executed after the suite has ended
* #param {Object} suite suite details
*/
// afterSuite: function (suite) {
// },
/**
* Runs after a WebdriverIO command gets executed
* #param {String} commandName hook command name
* #param {Array} args arguments that command would receive
* #param {Number} result 0 - command success, 1 - command error
* #param {Object} error error object if any
*/
// afterCommand: function (commandName, args, result, error) {
// },
/**
* Gets executed after all tests are done. You still have access to all global variables from
* the test.
* #param {Number} result 0 - test pass, 1 - test fail
* #param {Array.<Object>} capabilities list of capabilities details
* #param {Array.<String>} specs List of spec file paths that ran
*/
// after: function (result, capabilities, specs) {
// },
/**
* Gets executed right after terminating the webdriver session.
* #param {Object} config wdio configuration object
* #param {Array.<Object>} capabilities list of capabilities details
* #param {Array.<String>} specs List of spec file paths that ran
*/
// afterSession: function (config, capabilities, specs) {
// },
/**
* Gets executed after all workers got shut down and the process is about to exit. An error
* thrown in the onComplete hook will result in the test run failing.
* #param {Object} exitCode 0 - success, 1 - fail
* #param {Object} config wdio configuration object
* #param {Array.<Object>} capabilities list of capabilities details
* #param {<Object>} results object containing test results
*/
// onComplete: function(exitCode, config, capabilities, results) {
// },
/**
* Gets executed when a refresh happens.
* #param {String} oldSessionId session ID of the old session
* #param {String} newSessionId session ID of the new session
*/
// onReload: function(oldSessionId, newSessionId) {
// }
}
I have the config which I want to highlight in this above file.
{
port: 4723,
path: '/wd/hub',
capabilities: [{
"platformName": "Android",
"appium:udid": "emulator-5554",
"appium:automationName": "UiAutomator2",
"appium:app": "C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk"
}],
services: [
['appium', {
args: {
address: 'localhost',
port: 4723
},
logPath:'./',
}]
],
}
Now running the command npx wdio .\wdio.conf.js gives me the error.
PS C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio> npx wdio .\wdio.conf.js
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
Execution of 1 workers started at 2022-06-07T10:58:18.805Z
2022-06-07T10:58:18.820Z INFO #wdio/cli:launcher: Run onPrepare hook
2022-06-07T10:58:27.952Z ERROR #wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: Appium exited before timeout (exit code: 1)
at ChildProcess.<anonymous> (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\#wdio\appium-service\build\launcher.js:110:22)
at Object.onceWrapper (node:events:642:26)
at ChildProcess.emit (node:events:527:28)
at ChildProcess.emit (node:domain:475:12)
at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
Continue...
2022-06-07T10:58:27.956Z INFO #wdio/cli:launcher: Run onWorkerStart hook
2022-06-07T10:58:27.957Z INFO #wdio/local-runner: Start worker 0-0 with arg: .\\wdio.conf.js
[0-0] 2022-06-07T10:58:28.404Z INFO #wdio/local-runner: Run worker command: run
[0-0] RUNNING in Android - C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\test\specs\example.e2e.js
[0-0] 2022-06-07T10:58:28.583Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2022-06-07T10:58:28.646Z INFO webdriver: [POST] http://localhost:4723/session
[0-0] 2022-06-07T10:58:28.646Z INFO webdriver: DATA {
[0-0] capabilities: {
[0-0] alwaysMatch: {
[0-0] platformName: 'Android',
[0-0] 'appium:udid': 'emulator-5554',
[0-0] 'appium:automationName': 'UiAutomator2',
[0-0] 'appium:app': 'C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk'
[0-0] },
[0-0] firstMatch: [ {} ]
[0-0] },
[0-0] desiredCapabilities: {
[0-0] platformName: 'Android',
[0-0] 'appium:udid': 'emulator-5554',
[0-0] 'appium:automationName': 'UiAutomator2',
[0-0] 'appium:app': 'C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk'
[0-0] }
[0-0] }
[0-0] 2022-06-07T10:58:28.686Z WARN webdriver: Request failed with status 404 due to The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
[0-0] 2022-06-07T10:58:28.686Z INFO webdriver: Retrying 1/3
[0-0] 2022-06-07T10:58:28.686Z INFO webdriver: [POST] http://localhost:4723/session
[0-0] 2022-06-07T10:58:28.686Z INFO webdriver: DATA {
[0-0] capabilities: {
[0-0] alwaysMatch: {
[0-0] platformName: 'Android',
[0-0] 'appium:udid': 'emulator-5554',
[0-0] 'appium:automationName': 'UiAutomator2',
[0-0] 'appium:app': 'C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk'
[0-0] },
[0-0] firstMatch: [ {} ]
[0-0] },
[0-0] desiredCapabilities: {
[0-0] platformName: 'Android',
[0-0] 'appium:udid': 'emulator-5554',
[0-0] 'appium:automationName': 'UiAutomator2',
[0-0] 'appium:app': 'C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk'
[0-0] }
[0-0] }
[0-0] 2022-06-07T10:58:28.693Z WARN webdriver: Request failed with status 404 due to The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
[0-0] 2022-06-07T10:58:28.693Z INFO webdriver: Retrying 2/3
[0-0] 2022-06-07T10:58:28.693Z INFO webdriver: [POST] http://localhost:4723/session
[0-0] 2022-06-07T10:58:28.693Z INFO webdriver: DATA {
[0-0] capabilities: {
[0-0] alwaysMatch: {
[0-0] platformName: 'Android',
[0-0] 'appium:udid': 'emulator-5554',
[0-0] 'appium:automationName': 'UiAutomator2',
[0-0] 'appium:app': 'C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk'
[0-0] },
[0-0] firstMatch: [ {} ]
[0-0] },
[0-0] desiredCapabilities: {
[0-0] platformName: 'Android',
[0-0] 'appium:udid': 'emulator-5554',
[0-0] 'appium:automationName': 'UiAutomator2',
[0-0] 'appium:app': 'C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk'
[0-0] }
[0-0] }
[0-0] 2022-06-07T10:58:28.700Z WARN webdriver: Request failed with status 404 due to The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
[0-0] 2022-06-07T10:58:28.701Z INFO webdriver: Retrying 3/3
[0-0] 2022-06-07T10:58:28.701Z INFO webdriver: [POST] http://localhost:4723/session
[0-0] 2022-06-07T10:58:28.701Z INFO webdriver: DATA {
[0-0] capabilities: {
[0-0] alwaysMatch: {
[0-0] platformName: 'Android',
[0-0] 'appium:udid': 'emulator-5554',
[0-0] 'appium:automationName': 'UiAutomator2',
[0-0] 'appium:app': 'C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk'
[0-0] },
[0-0] firstMatch: [ {} ]
[0-0] },
[0-0] desiredCapabilities: {
[0-0] platformName: 'Android',
[0-0] 'appium:udid': 'emulator-5554',
[0-0] 'appium:automationName': 'UiAutomator2',
[0-0] 'appium:app': 'C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk'
[0-0] }
[0-0] }
[0-0] 2022-06-07T10:58:28.707Z ERROR webdriver: Request failed with status 404 due to unknown command: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
[0-0] 2022-06-07T10:58:28.707Z ERROR webdriver: unknown command: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
[0-0] at getErrorFromResponseBody (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\webdriver\build\utils.js:197:12)
[0-0] at NodeJSRequest._request (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\webdriver\build\request\index.js:166:60)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async startWebDriverSession (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\webdriver\build\utils.js:67:20)
[0-0] at async Function.newSession (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\webdriver\build\index.js:46:45)
[0-0] at async remote (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\webdriverio\build\index.js:77:22)
[0-0] at async Runner._startSession (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\#wdio\runner\build\index.js:223:56)
[0-0] at async Runner._initSession (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\#wdio\runner\build\index.js:176:25)
[0-0] at async Runner.run (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\#wdio\runner\build\index.js:88:19)
[0-0] 2022-06-07T10:58:28.708Z ERROR #wdio/runner: Error: Failed to create session.
[0-0] The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
[0-0] at startWebDriverSession (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\webdriver\build\utils.js:72:15)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Function.newSession (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\webdriver\build\index.js:46:45)
[0-0] at async remote (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\webdriverio\build\index.js:77:22)
[0-0] at async Runner._startSession (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\#wdio\runner\build\index.js:223:56)
[0-0] at async Runner._initSession (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\#wdio\runner\build\index.js:176:25)
[0-0] at async Runner.run (C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\node_modules\#wdio\runner\build\index.js:88:19)
[0-0] FAILED in Android - C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio\test\specs\example.e2e.js
2022-06-07T10:58:28.827Z INFO #wdio/cli:launcher: Run onWorkerEnd hook
2022-06-07T10:58:28.828Z INFO #wdio/cli:launcher: Run onComplete hook
Spec Files: 0 passed, 1 failed, 1 total (100% completed) in 00:00:10
2022-06-07T10:58:28.830Z INFO #wdio/local-runner: Shutting down spawned worker
2022-06-07T10:58:29.095Z INFO #wdio/local-runner: Waiting for 0 to shut down gracefully
2022-06-07T10:58:29.097Z INFO #wdio/local-runner: shutting down
PS C:\Users\Ramkumar\learnings\study\mock-appium-webdriverio>
I try to invoke the same with Appium tool, its invoking the application.
Appium opening the application for inspection.
Emulator opening the apps screen shot
Appium Server Screen shot
Let me know if any other setting is required.
Thanks,
Ramkumar

Some site video session mentioned about having "appium:platformVersion" as one more properties in capabilities and adding one more version of emulator will solve this problem.
Earlier I have having only one emulator [Android version 'R']. Now I added one more emulator with [Android version 'Q']. After adding the "appium:platformVersion" in capabilities, its working fine.
capabilities defined in wdio.conf.js [previous]
capabilities: [{
"platformName": "Android",
"appium:udid": "d278263c",
"appium:automationName": "UiAutomator2",
"appium:app": "C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk"
}],
capabilities defined in wdio.conf.js [New one]
capabilities: [{
"platformName": "Android",
"appium:udid": "d278263c",
"appium:automationName": "UiAutomator2",
"appium:app": "C:\\Users\\Ramkumar\\learnings\\study\\mock-appium-webdriverio\\app\\android\\ApiDemos-debug.apk",
"appium:platformVersion": "9"
}],
Kindly note this observations:
Every time executing the script with "appium:platformVersion": "9" always works and its starting the application.
After adding one more device [earlier I had only one device], if I execute the script without "appium:platformVersion": "9", some time it works and some time it throws me same error "ERROR #wdio/cli:utils: A service failed in the 'onPrepare' hook"
Even when I have only one emulator [deleted the new one created], executing with capabilities "appium:platformVersion": "9" always works and its starting the application.
This works on both emualator and android real device. Above mentioned capabilities is for my personal device Oneplus 5 [Android Version 9]
I'm not sure if this is change mentioned above works and it started working, but I have not changed anything else in the project or my laptop. If someone facing this issue can try this solution... If it resolve or still facing the issue, kindly leave a comment for others....

your config says that your path is /wd/hub , but your appium server is pointing to /. Appium server path is not configurable with GUI, so you can
set your path in your config to
{
port: 4723,
path: '/',
...
}
or manually launch appium server in a terminal and use these settings :
appium --base-path /wd/hub --port 4723
Also, set your capabilities following this link.

Related

Appium capability baseUrl is not working when trying to connect to remote server

I am trying to run my tests with a remote Appium server. Until now, I have always used the server in the same machine where the tests are being run, so I was using url + port (localhost:4723).
The problem I am facing now is that the "baseUrl" capability does not make any change, it seems that it is being ignored. I am using Appium 1.22.3
This is my code:
const url = '88.123.123.23'
const path = '/ws/hub';
const timeout = 20000;
export function createAndroidConfig(port: number, deviceName: string, id: string): RemoteOptions {
const config: RemoteOptions = {
path: path,
port: port,
logLevel: 'trace',
baseUrl: url,
waitforTimeout: timeout,
capabilities: {
udid: id,
automationName: 'UiAutomator2',
platformName: 'Android',
deviceName: deviceName,
autoGrantPermissions: true,
unicodeKeyboard: true,
resetKeyboard: true,
'appium:app': apkPath,
newCommandTimeout: 100000,
unlockType: "pin",
unlockKey: "0000"
}
}
return config;
}
The error I get:
Unable to connect to "http://localhost:4723/ws/hub", make sure browser driver is running on that address.
I have searched for it, thinking it could be an Appium bug, but I did not find information.
If I change the port or path, the changes do take effect, but url does not.
const path = '/ws/hub';
/wd/hub
replace this with

WebdriverIO not using config.path to access Appium Server

I'm trying to get started with appium and successfully connected myself with my device using Appium Server and Appium Inspector (I had to change remote path to /wd/hub). Now, I'm trying to do the same using WebdriverIO using https://github.com/webdriverio/appium-boilerplate
At first I start the appium server:
Now I cloned Appium Boilerplate from https://github.com/webdriverio/appium-boilerplate and ran npm install. Then I changed the path in config/wdio.android.app.conf.ts to '/wd/hub':
import { join } from 'path';
import config from './wdio.shared.local.appium.conf';
// ============
// Specs
// ============
config.specs = [
'./tests/specs/**/app*.spec.ts',
];
// ============
// Capabilities
// ============
// For all capabilities please check
// http://appium.io/docs/en/writing-running-appium/caps/#general-capabilities
config.capabilities = [
{
// The defaults you need to have in your config
platformName: 'Android',
maxInstances: 1,
// For W3C the appium capabilities need to have an extension prefix
// http://appium.io/docs/en/writing-running-appium/caps/
// This is `appium:` for all Appium Capabilities which can be found here
'appium:deviceName': 'Pixel_3_10.0',
'appium:platformVersion': '10.0',
'appium:orientation': 'PORTRAIT',
'appium:automationName': 'UiAutomator2',
// The path to the app
'appium:app': join(process.cwd(), './apps/Android-NativeDemoApp-0.4.0.apk'),
// #ts-ignore
'appium:appWaitActivity': 'com.wdiodemoapp.MainActivity',
// Read the reset strategies very well, they differ per platform, see
// http://appium.io/docs/en/writing-running-appium/other/reset-strategies/
'appium:noReset': true,
'appium:newCommandTimeout': 240,
},
];
config.path = '/wd/hub';
console.log(config);
exports.config = config;
Now I call npm run android.app, and the console.log command shows me:
{
runner: 'local',
specs: [ './tests/specs/**/app*.spec.ts' ],
capabilities: [
{
platformName: 'Android',
maxInstances: 1,
'appium:deviceName': 'Pixel_3_10.0',
'appium:platformVersion': '10.0',
'appium:orientation': 'PORTRAIT',
'appium:automationName': 'UiAutomator2',
'appium:app': '<<removed initially ;-)>>',
'appium:appWaitActivity': 'com.wdiodemoapp.MainActivity',
'appium:noReset': true,
'appium:newCommandTimeout': 240
}
],
logLevel: 'silent',
bail: 0,
baseUrl: 'http://the-internet.herokuapp.com',
waitforTimeout: 45000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services: [ [ 'appium', [Object] ] ],
framework: 'mocha',
reporters: [ 'spec' ],
mochaOpts: { ui: 'bdd', timeout: 180000 },
port: 4723,
path: '/wd/hub'
}
... which seems ok for me, but the Appium server shows:
[HTTP] Waiting until the server is closed
[HTTP] Received server close event
[Appium] Welcome to Appium v1.22.0
[Appium] Non-default server args:
[Appium] address: 127.0.0.1
[Appium] sessionOverride: true
[Appium] relaxedSecurityEnabled: true
[Appium] allowInsecure: {
[Appium] }
[Appium] denyInsecure: {
[Appium] }
[Appium] Appium REST http interface listener started on 127.0.0.1:4723
[HTTP] --> POST /session
[HTTP] {"capabilities":{"alwaysMatch":{"platformName":"Android","appium:deviceName":"Pixel_3_10.0","appium:platformVersion":"10.0","appium:orientation":"PORTRAIT","appium:automationName":"UiAutomator2","appium:app":"<<removed ;-)>>","appium:appWaitActivity":"com.wdiodemoapp.MainActivity","appium:noReset":true,"appium:newCommandTimeout":240},"firstMatch":[{}]},"desiredCapabilities":{"platformName":"Android","appium:deviceName":"Pixel_3_10.0","appium:platformVersion":"10.0","appium:orientation":"PORTRAIT","appium:automationName":"UiAutomator2","appium:app":"<<removed ;-)>>","appium:appWaitActivity":"com.wdiodemoapp.MainActivity","appium:noReset":true,"appium:newCommandTimeout":240}}
[HTTP] No route found for /session
[HTTP] <-- POST /session 404 8 ms - 211
[HTTP]
[HTTP] --> POST /session
[HTTP] {"capabilities":{"alwaysMatch":{"platformName":"Android","appium:deviceName":"Pixel_3_10.0","appium:platformVersion":"10.0","appium:orientation":"PORTRAIT","appium:automationName":"UiAutomator2","appium:app":"<<removed ;-)>>","appium:appWaitActivity":"com.wdiodemoapp.MainActivity","appium:noReset":true,"appium:newCommandTimeout":240},"firstMatch":[{}]},"desiredCapabilities":{"platformName":"Android","appium:deviceName":"Pixel_3_10.0","appium:platformVersion":"10.0","appium:orientation":"PORTRAIT","appium:automationName":"UiAutomator2","appium:app":"<<removed ;-)>>","appium:appWaitActivity":"com.wdiodemoapp.MainActivity","appium:noReset":true,"appium:newCommandTimeout":240}}
It looks like WebdriverIO doesn't recognize the config.path-setting. I was already checking out Testing Mobile App with Appium & WebdriverIO: "No route found for /session" but the solution was changing the config.path value (which I did) but I've no idea why it's no recognized... Is anyone having any idea?
i just stepped over the same issue and it looks like it works when you set it under the capabilites:
capabilities: [{
"path": "/wd/hub",
...

Ho to run multiple mobile tests on Sauce Labs via Jenkins?

I have a problem with run Jenkins job with additional parameters
In my package.json I named a script name with some browser configs like:
"mobile": "npx wdio run ./config/wdio.mobile.conf.js"
I have got a config file with my mobile devices:
exports.config = {
...config,
...{
user: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
testobject_api_key: process.env.SAUCE_RDC_ACCESS_KEY,
region: 'eu',
specs: [
'./features/*'
],
maxInstances: 1,
capabilities: [{
deviceName: 'Samsung Galaxy S',
automationName: 'UiAutomator2',
platformName: 'Android',
idleTimeout: 180,
cacheId: new Date().getTime(),
noReset: true,
autoGrantPermissions: true,
orientation: 'PORTRAIT',
newCommandTimeout: 180,
build: 'test',
name: 'test',
maxInstances: 1,
}],
services: ['sauce'],
}
}
But instead of hardcoded strings with deviceName etc I want to use some parameters to set any device while running Jenkins job something like:
Additional problem:
How to manage running multiple devices? For example an array of devices at once. (30 devices).
I would appreciate your help
One way to do that is to manipulate env file
On Jenkins side:
creation of Jenkins input with devices
with every run with chosen device add dynamically new node variable to env file with deviceName, automationName and platformName:
echo DEVICE_NAME=${DEVICE_NAME} >> .env
On config side parametrize device capabilities like that:
deviceName: `${process.env.DEVICE_NAME}`
automationName: `${process.env.AUTOMATION_NAME}`
platformName: `${process.env.PLATFORM_NAME}`

Jenkins Finished: FAILURE after Katalon test

I am trying using Jenkins to run Katalon test but I have failure when finish katalon test.
here detail what i have done:
Run Test on Katalon it's work fine no error,
jenkins Failed After runing Katalon test,
Change Jenkinsfile Script with chrome no-sanbox (error)
if you have idea what going on here or find what I miss please let me know, I have work on this few days but still no clue.
here details of my Jenkinsfile, I have declare all variable before.
stage ("Regression Test") {
echo 'regression test'
node ('kre-centos') {
cleanWs deleteDirs: true
checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[credentialsId: 'ci-cd', url: "${katalonRepoUrl}"]], branches: [[name: "${katalonBranch}"]]]
withCredentials([string(credentialsId: 'katalon-api-key', variable: 'secret')]) {
echo "workspace : ${workspace}"
sh """
pwd
ls
/katalon01/katalon-studio-engine/katalonc -noSplash -runMode=console \
-projectPath='${workspace}/${katalonProjectName}' -retry=0 \
-testSuiteCollectionPath="Test Suites/${katalonTestSuiteName}" \
-executionProfile="default" -browserType="Chrome (headless)" \
-apiKey=${secret}
"""
}
}
}
Here details of jenkins log
+ pwd
/katalon01/jenkins-agent/workspace/Framework/framework-katalon
+ ls
build.gradle
console.properties
debug.log
FRM-Katalon.prj
Include
Object Repository
Profiles
Scripts
settings
Test Cases
Test Suites
+ /katalon01/katalon-studio-engine/katalonc -noSplash -runMode=console -projectPath=/katalon01/jenkins-agent/workspace/Framework/framework-katalon/FRM-Katalon.prj -retry=0 '-testSuiteCollectionPath=Test Suites/FRM_Katalon' -executionProfile=default '-browserType=Chrome (headless)' -apiKey= 8490e2f6-9949-4610-b043-*******
Katalon workspace folder is set to default location: /tmp/session-f1cdbf48
Starting Groovy-Eclipse compiler resolver. Specified compiler level: unspecified
177 2.4.7.xx-2016111****-e46 = ACTIVE
INFO: Katalon Version: 7.5.2
INFO: Command-line arguments: -runMode=console -projectPath=/katalon01/jenkins-agent/workspace/Framework/framework-katalon/FRM-Katalon.prj -retry=0 -testSuiteCollectionPath=Test Suites/FRM_Katalon -executionProfile=default -browserType=Chrome (headless) -apiKey=******** 8490e2f6-9949-4610-b043-********
INFO: User working dir: /katalon01/jenkins-agent/workspace/Framework/framework-katalon
INFO: Error log: /tmp/session-f1cdbf48/.metadata/.log
INFO: Katalon TestOps server URL: https://analytics.katalon.com
INFO: Katalon Store server URL: https://store.katalon.com
INFO: User home: /katalon01/jenkins-agent
INFO: Java vendor: Oracle Corporation
INFO: Java version: 1.8.0_262
INFO: Local OS: Linux 64bit
INFO: CPU load: 0%
INFO: Total memory: 7316 MB
INFO: Free memory: 1013 MB
Start getting machine ID on Linux
End getting machine ID on Linux c05973d029ca9e78c8*******
Start appending additional signatures
hardwareSerialNumber
osDependentUsername jenkins
End appending additional signatures c05973d029ca9e78c8d1437*****__jenkins
INFO: Machine ID: 6546c254cb38a5280********
Activating...
Start activating offline...
Search for valid offline licenses in folder: /katalon01/jenkins-agent/.katalon/license
The number of valid offline licenses: 0
Offline activation failed.
Start activating online...
Cleaning up workspace
Opening project file: /katalon01/jenkins-agent/workspace/Framework/framework-katalon/FRM-Katalon.prj
Warning! Please run Katalon execution command outside of the project folder.
Generating global variables...
Parsing custom keywords...
Project 'FRM-Katalon' opened
Start reloading plugins...
Katalon version: 7.5.2
Plugin info URL: https://store.katalon.com/api/products/ks?appVersion=7.5.2&appType=ENGINE&licenseType=ENTERPRISE
Start check license task
chromedriver is located at default location: /katalon01/katalon-studio-engine/configuration/resources/drivers/chromedriver_linux64/chromedriver. In case your browser is updated to a newer version, please use this command to update chromdriver: --config -webui.autoUpdateDrivers=true
--------------------------------------------------------------------------------
Test Suites/FRM_Katalon - 20200814_092512................................0/7(0%)
--------------------------------------------------------------------------------
Test Suites/Test Suite_Application Controller - Chrome - 20200814_092512.0/7(0%)
--------------------------------------------------------------------------------
Launcher status after execution process completed: Running
Start writing execution.uuid file to folder: /katalon01/jenkins-agent/workspace/Framework/framework-katalon/Reports/20200814_092512/Test Suite_Application Controller/20200814_092512
Start generating JUnit report folder at: /katalon01/jenkins-agent/workspace/Framework/framework-katalon/Reports/20200814_092512/Test Suite_Application Controller/20200814_092512...
JUnit report were generated at folder: /katalon01/jenkins-agent/workspace/Framework/framework-katalon/Reports/20200814_092512/Test Suite_Application Controller/20200814_092512
--------------------------------------------------------------------------------
Test Suites/FRM_Katalon - 20200814_092512...............................4/7(57%)
--------------------------------------------------------------------------------
Test Suites/Test Suite_Application Controller - Chrome - 20200814_092512........
........................................................................4/7(57%)
--------------------------------------------------------------------------------
Uploading report to Katalon TestOps...
Start sending test result to Katalon TestOps
Uploading log files of test suite collection
Sending file: /katalon01/jenkins-agent/workspace/Framework/framework-katalon/Reports/20200814_092512/Test Suite_Application Controller/20200814_092512/execution.uuid
Sending file: /katalon01/jenkins-agent/workspace/Framework/framework-katalon/Reports/20200814_092512/Test Suite_Application Controller/20200814_092512/execution0.log
Sending file: /katalon01/jenkins-agent/workspace/Framework/framework-katalon/Reports/20200814_092512/Test Suite_Application Controller/20200814_092512/execution.properties
Sending file: /katalon01/jenkins-agent/workspace/Framework/framework-katalon/Reports/20200814_092512/Test Suite_Application Controller/20200814_092512/JUnit_Report.xml
Sending file: /katalon01/jenkins-agent/workspace/Framework/framework-katalon/Reports/20200814_092512/FRM_Katalon/20200814_092512/JUnit_Report.xml
Sending file: /katalon01/jenkins-agent/workspace/Framework/framework-katalon/Reports/20200814_092512/FRM_Katalon/20200814_092512/20200814_092512.rp
--------------------------------------------------------------------------------
Test Suites/FRM_Katalon - 20200814_092512..............................7/7(100%)
--------------------------------------------------------------------------------
Test Suites/Test Suite_Application Controller - Chrome - 20200814_092512........
.......................................................................7/7(100%)
--------------------------------------------------------------------------------
Katalon TestOps: Start uploading report to Katalon TestOps server: https://analytics.katalon.com
Katalon TestOps - Execution URL: https://analytics.katalon.com/from-ks/execution-result?teamId=50***&projectId=62***&id=6941***
End sending to Katalon TestOps
Report has been sent to Katalon TestOps
--------------------------------------------------------------------------------
Test Suites/FRM_Katalon - 20200814_092512..............................7/7(100%)
--------------------------------------------------------------------------------
Test Suites/Test Suite_Application Controller - Chrome - 20200814_092512........
.......................................................................7/7(100%)
--------------------------------------------------------------------------------
Execution completed. Exit code: 1.
Start clean up session
End check license task
End clean up session
Start release license task
License released
End release license task
All launchers terminated
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Posting build status of FAILED to bitbucketERROR: script returned exit code 1
Finished: FAILURE
Here details of Katalon error log
2020-08-14 08:40:21 - [TEST_CASE][FAILED] - Test Cases/Application Controller/TS-001_Login Logout Positive Case: Test Cases/Application Controller/TS-001_Login Logout Positive Case FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to open browser with url: 'http://10.172.**.***:3000/'
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword.openBrowser(OpenBrowserKeyword.groovy:81)
at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword.execute(OpenBrowserKeyword.groovy:67)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.openBrowser(WebUiBuiltInKeywords.groovy:60)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$openBrowser.call(Unknown Source)
at TS-001_Login Logout Positive Case.run(TS-001_Login Logout Positive Case:19)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:169)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:142)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:91)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1597394411452.run(TempTestSuite1597394411452.groovy:37)
Caused by: org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'devopstools-katalon', ip: '10.172.**.***', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1127.el7.x86_64', java.version: '1.8.0_262'
Driver info: driver.version: CChromeDriver
remote stacktrace: #0 0x55edd4eed*** <unknown>
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at com.kms.katalon.selenium.driver.CChromeDriver.execute(CChromeDriver.java:19))
at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword$_openBrowser_closure1.doCall(OpenBrowserKeyword.groovy:74)
at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword$_openBrowser_closure1.call(OpenBrowserKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
... 19 more
Try updating your Chrome options with
ChromeOptions options = new ChromeOptions();
...
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
as suggested here.
UPDATE:
To switch from Katalon keywords to Selenium commands use the DriverFactory library. Add this to the top of your script:
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
System.setProperty("webdriver.chrome.driver", "C:\\test\\chromedriver.exe")
ChromeOptions options = new ChromeOptions()
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
WebDriver driver = new ChromeDriver(options)
DriverFactory.changeWebDriver(driver)
For more information see here.

Rails - Setting up karma with hamlc - getting parse error on hamlcoffee.js.coffee.erb

I'm trying to set up an angular testing environment using Karma, Jasmine, and Phantomjs. It's a rails app using hamlcoffee as template language.
My problem is that when i try to run the tests i get the following error:
PhantomJS 1.9.7 (Linux) ERROR
SyntaxError: Parse error at /home/me/.rvm/gems/ruby-2.1.2/bundler/gems/haml_coffee_assets-a3c2951eca00/vendor/assets/javascripts/hamlcoffee.js.coffee.erb:1
It looks like the file hamlcoffee.js.coffee.erb is the problem here, so i tried adding everything ending with .erb to the exclude list in the karma config file, but unfortunately with no luck.
This is my Karma config file:
// Karma configuration
module.exports = function(config) {
config.set({
// base path, based on tmp/ folder
basePath: '..',
// frameworks to use
frameworks: ['jasmine', 'ng-scenario'],
// list of files / patterns to load in the browser
files: [
APPLICATION_SPEC,
'app/assets/javascripts/*/*.{coffee,js}',
'spec/javascripts/**/*_spec.{coffee,js}',
'app/assets/*.haml'
],
// list of files to exclude
exclude: [
'**/*.erb'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
// 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: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
// Preprocessors
preprocessors: {
'**/*.coffee' : 'coffee',
'app/assets/javascripts/**/*.hamlc' : 'haml'
},
hamlPreprocessor: {
options: {
language: 'coffee'
}
}
});
};
I'm using the karma-haml-preprocessor for my .hamlc templates.

Resources