WebdriverIO not using config.path to access Appium Server - appium

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",
...

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

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

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.

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}`

How to add conditional if in Jenkins file for output with many lines

How to add if condition, that if i get specific output do this else do this, knowing that im getting output like this
[Appium] Welcome to Appium v1.17.0
[Appium] Non-default server args:
[Appium] logFile: /var/log/appium.log
[Appium] allowInsecure: {
[Appium] 0: chromedriver_autodownload
[Appium] }
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
i have used this but achive nothing
script{
def appiumLog = sh label: 'Appium log', returnStdout: true, script: "docker logs ${containerName}"
if( appiumLog.substring(appiumLog.lastIndexOf("\n")) == '[Appium] Appium REST http interface listener started on 0.0.0.0:4723') {
sh label: 'APK Loading', script: "docker cp src/main/resources/test.apk ${containerName}:/opt"
echo "APK file has copied to: ${containerName}"
} else {
echo "This is the output: ${appiumLog}"
}
}
also used this but no use
if( appiumLog.indexOf('[Appium] Appium REST http interface listener started on 0.0.0.0:4723') >= 0) {
First, if you are using returnStdout: true, make sure to always trim() the returned string. Most likely there is a trailing \n which messes up your search.
def appiumLog = sh( label: 'Appium log', returnStdout: true, script: "docker logs ${containerName}").trim()
Your first substring() actually returns the \n as first character! So you should add +1 to the index to skip the \n:
if( appiumLog.substring(appiumLog.lastIndexOf("\n") + 1) ...

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