Cannot run tests against android native using appium
What are you trying to achieve?
I have created a codeceptJS project by following the mobile testing setup steps located here: https://codecept.io/mobile/#setting-up
So far, I'm unable to test android apps via simulator; I instead get the following error:
The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
What do you get instead?
Tests won't run, and as stated I get the error above. Here's a more complete log:
-- FAILURES:
1) login
I should be able to login with the correct username and password:
The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
at Object.getErrorFromResponseBody (node_modules/webdriver/build/utils.js:189:12)
at NodeJSRequest._request (node_modules/webdriver/build/request/index.js:157:31)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Scenario Steps:
- I.see("Username") at Timeout._onTimeout (./login_test.js:5:7)
- I.click("//android.widget.EditText[@content-desc="test-Username"]") at Test.<anonymous> (./login_test.js:7:5)
Artifacts:
- screenshot: /Users/thomastupper/appium-codecept-android-POC/output/I_should_be_able_to_login_with_the_correct_username_and_password.failed.png
2) login
I should not be able to login with an incorrect username or password:
The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
at Object.getErrorFromResponseBody (node_modules/webdriver/build/utils.js:189:12)
at NodeJSRequest._request (node_modules/webdriver/build/request/index.js:157:31)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Scenario Steps:
- I.see("Username") at Timeout._onTimeout (./login_test.js:18:7)
- I.click("//android.widget.EditText[@content-desc="test-Username"]") at Test.<anonymous> (./login_test.js:20:5)
Artifacts:
- screenshot: /Users/thomastupper/appium-codecept-android-POC/output/I_should_not_be_able_to_login_with_an_incorrect_username_or_password.failed.png
3) login
I should be able to see details:
The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
at Object.getErrorFromResponseBody (node_modules/webdriver/build/utils.js:189:12)
at NodeJSRequest._request (node_modules/webdriver/build/request/index.js:157:31)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Scenario Steps:
- I.see("Username") at Timeout._onTimeout (./login_test.js:32:7)
- I.click("//android.widget.EditText[@content-desc="test-Username"]") at Test.<anonymous> (./login_test.js:34:5)
Artifacts:
- screenshot: /Users/thomastupper/appium-codecept-android-POC/output/I_should_be_able_to_see_details.failed.png
FAIL | 0 passed, 3 failed // 42s
Run with --verbose flag to see complete NodeJS stacktrace
2021-08-04T17:08:11.135Z ERROR webdriver: Request failed with status 404 due to invalid session id: A session is either terminated or not started
2021-08-04T17:08:11.754Z ERROR webdriver: Request failed with status 404 due to invalid session id: A session is either terminated or not started
2021-08-04T17:08:12.974Z ERROR webdriver: Request failed with status 404 due to invalid session id: A session is either terminated or not started
2021-08-04T17:08:15.391Z ERROR webdriver: Request failed with status 404 due to invalid session id: A session is either terminated or not started
(node:11232) UnhandledPromiseRejectionWarning: invalid session id: A session is either terminated or not started
at Object.getErrorFromResponseBody (/Users/thomastupper/appium-codecept-android-POC/node_modules/webdriver/build/utils.js:189:12)
at NodeJSRequest._request (/Users/thomastupper/appium-codecept-android-POC/node_modules/webdriver/build/request/index.js:157:31)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Browser.wrapCommandFn (/Users/thomastupper/appium-codecept-android-POC/node_modules/@wdio/utils/build/shim.js:103:29)
at async Browser.$$ (/Users/thomastupper/appium-codecept-android-POC/node_modules/webdriverio/build/commands/browser/$$.js:53:17)
at async Browser.wrapCommandFn (/Users/thomastupper/appium-codecept-android-POC/node_modules/@wdio/utils/build/shim.js:103:29)
at async Appium._locate (/Users/thomastupper/appium-codecept-android-POC/node_modules/codeceptjs/lib/helper/WebDriver.js:804:19)
at async Appium.proceedSee (/Users/thomastupper/appium-codecept-android-POC/node_modules/codeceptjs/lib/helper/WebDriver.js:2603:15)
(node:11232) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
Provide test source code if related
Here's my test file:
Feature('login');
Scenario('I should be able to login with the correct username and password', ({ I }) => {
setTimeout(() => {
I.see('Username');
}, 3000);
I.click('//android.widget.EditText[@content-desc="test-Username"]');
I.fillField('//android.widget.EditText[@content-desc="test-Username"]', 'standard_user');
I.click('//android.widget.EditText[@content-desc="test-Password"]');
I.fillField('//android.widget.EditText[@content-desc="test-Password"]', 'secret_sauce');
I.click('//android.view.ViewGroup[@content-desc="test-LOGIN"]');
I.waitForElement('//android.view.ViewGroup[@content-desc="test-Cart drop zone"]/android.view.ViewGroup/android.widget.TextView', 3)
I.dontSeeElement('//android.view.ViewGroup[@content-desc="test-Error message"]/android.widget.TextView');
});
Scenario('I should not be able to login with an incorrect username or password', ({ I }) => {
setTimeout(() => {
I.see('Username');
}, 3000);
I.click('//android.widget.EditText[@content-desc="test-Username"]');
I.fillField('//android.widget.EditText[@content-desc="test-Username"]', 'bob');
I.click('//android.widget.EditText[@content-desc="test-Password"]');
I.fillField('//android.widget.EditText[@content-desc="test-Password"]', 'secret_sauce');
I.click('//android.view.ViewGroup[@content-desc="test-LOGIN"]');
I.waitForElement('//android.view.ViewGroup[@content-desc="test-Cart drop zone"]/android.view.ViewGroup/android.widget.TextView', 3)
I.dontSeeElement('//android.view.ViewGroup[@content-desc="test-Error message"]/android.widget.TextView');
});
Scenario('I should be able to see details', ({ I }) => {
// login
setTimeout(() => {
I.see('Username');
}, 3000);
I.click('//android.widget.EditText[@content-desc="test-Username"]');
I.fillField('//android.widget.EditText[@content-desc="test-Username"]', 'standard_user');
I.click('//android.widget.EditText[@content-desc="test-Password"]');
I.fillField('//android.widget.EditText[@content-desc="test-Password"]', 'secret_sauce');
I.click('//android.view.ViewGroup[@content-desc="test-LOGIN"]');
I.waitForElement('//android.view.ViewGroup[@content-desc="test-Cart drop zone"]/android.view.ViewGroup/android.widget.TextView', 3)
// should be able to click a label to see details
I.click('(//android.widget.TextView[@content-desc="test-Item title"])[2]');
I.seeElement('//android.view.ViewGroup[@content-desc="test-Description"]/android.widget.TextView[2]');
I.click('//android.view.ViewGroup[@content-desc="test-BACK TO PRODUCTS"]');
});
And here is my codecept.conf.js:
const path = require('path');
const { setHeadlessWhen } = require('@codeceptjs/configure');
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);
exports.config = {
tests: './*_test.js',
output: './output',
helpers: {
Appium: {
platform: 'Android',
device: 'emulator',
desiredCapabilities: {
avd: 'Pixel_5_API_28',
app: path.resolve('./sample_apps/Android.apk'),
appActivity: 'com.swaglabsmobileapp.MainActivity'
}
},
},
include: {
I: './steps_file.js'
},
bootstrap: null,
mocha: {},
name: 'appium-codecept-android-POC',
plugins: {
pauseOnFail: {},
retryFailedStep: {
enabled: true
},
tryTo: {
enabled: true
},
screenshotOnFail: {
enabled: true
}
}
}
Lastly, here is my package.json:
{
"name": "appium-codecept-android-POC",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"codeceptjs": "^3.0.7",
"webdriverio": "^7.9.0"
}
}
Details
- CodeceptJS version: 3.0.7
- NodeJS Version: 14.11.0
- Operating System: MacOS Big Sur
- Webdriver IO version: 7.9.0
- Configuration file (same as stated above):
const path = require('path');
const { setHeadlessWhen } = require('@codeceptjs/configure');
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);
exports.config = {
tests: './*_test.js',
output: './output',
helpers: {
Appium: {
platform: 'Android',
device: 'emulator',
desiredCapabilities: {
avd: 'Pixel_5_API_28',
app: path.resolve('./sample_apps/Android.apk'),
appActivity: 'com.swaglabsmobileapp.MainActivity'
}
},
},
include: {
I: './steps_file.js'
},
bootstrap: null,
mocha: {},
name: 'appium-codecept-android-POC',
plugins: {
pauseOnFail: {},
retryFailedStep: {
enabled: true
},
tryTo: {
enabled: true
},
screenshotOnFail: {
enabled: true
}
}
}
After playing with this, I have narrowed the issue down to the use of XPath. Any time an xpath selector is used with a react-native Android app, it fails as described above. I've tried using espresso, but the espresso server exits for each case with a failure.
A full project can be obtained by cloning the following repo:
git clone https://github.com/ttupper92618/codeceptjs-native-POC.git
This is a nice demo project (if I can get android to work)!
Ok - after exhaustively evaluating, this seems related to using uiautomator2. If one sets the capabilities for android to use uiautomator1, tests run as expected. Switching to uiautomator2 immediately causes failures.
Thanks for investigation. I hope this also may help others