I have some troubles with setting up Appium tests with Expo Typescript app. This is also my first attempt with e2e mobile app testing, especially made with react-native, so please be understanding.
I mixed some tutorials (for example this). I tried to use Expo, Appium, WebdriverIO, Mocha and Chai. I managed to run Expo app programmatically, but further I got some errors.
Folder structure:
- tests
|wdio.conf.ts
|AppiumSetup.ts
|- specs
|example.test.ts
wdio.conf.ts file:
export const androidCapability: WebDriver.DesiredCapabilities = {
browserName: "",
platformName: "Android",
deviceName: "emulator-5564", // Change to the name of the AVD you're using
automationName: "UiAutomator2",
platformVersion: "10",
appPackage: "host.exp.exponent",
intentAction: "android.intent.action.VIEW",
appActivity: "host.exp.exponent.experience.HomeActivity",
appWaitActivity: "host.exp.exponent.experience.HomeActivity",
};
export const config: WebdriverIO.Config = {
path: "/wd/hub",
port: 4723,
hostname: "localhost",
protocol: "http",
specs: ["./test/specs/**/*.ts"],
maxInstances: 1,
capabilities: [androidCapability],
logLevel: "info",
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services: ["appium"],
framework: "mocha",
reporters: [["allure", { outputDir: "allure-results" }]],
mochaOpts: {
ui: "bdd",
timeout: 60000,
},
baseUrl: "localhost",
};
AppiumSetup.ts file:
import { remote } from "webdriverio";
import { androidCapability, config } from "./wdio.conf";
const options = {
path: config.path,
port: config.port,
};
export async function launchExpoAndroid() {
const client = await remote({
...options,
capabilities: androidCapability,
});
client.closeApp();
client.startActivity(
androidCapability.appPackage!,
androidCapability.appActivity!
); //Reload to force update
await client.execute("mobile:deepLink", {
url: "exp://127.0.0.1:19000",
package: androidCapability.appPackage,
});
return client;
}
And example.test.ts file is below. As you can see, there is a simple test with just adding two numbers, but in before function I launch expo app. example.test.ts file:
import { expect } from "chai";
import { launchExpoAndroid } from "../AppiumSetup";
let driver: WebdriverIO.Browser;
describe("First tests", () => {
before(async () => {
driver = await launchExpoAndroid();
});
after(() => {
driver.deleteSession();
});
it("adding", () => {
expect(2 + 2).to.eq(4);
});
});
Also, dev dependencies (not everything connected to testing of course):
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/register": "^7.16.7",
"@openapitools/openapi-generator-cli": "^2.4.13",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"@types/react": "~17.0.21",
"@types/react-native": "~0.64.12",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"@wdio/allure-reporter": "^7.16.11",
"@wdio/appium-service": "^7.16.11",
"@wdio/cli": "^7.16.12",
"@wdio/devtools-service": "^7.16.12",
"@wdio/local-runner": "^7.16.12",
"@wdio/mocha-framework": "^7.16.11",
"appium": "^1.22.2",
"chai": "^4.3.4",
"eslint": "^8.0.1",
"eslint-config-universe": "^7.0.1",
"jest-expo": "^43.0.0",
"mocha": "^9.1.3",
"prettier": "2.4.1",
"ts-node": "^10.4.0",
"tsconfig-paths": "^3.12.0",
"typescript": "^4.5.4",
"webdriverio": "^7.16.12"
},
I run tests with command: npx wdio ./test/wdio.conf.ts.
Then, after Expo app launch (not my app, but Expo app), when the splashscreen is displayed, the following errors appear and after that Expo app is closed (this is not the full terminal output, but from the point when errors occur, also I changed the paths to be relative):
[0-0] 2022-01-08T18:09:44.811Z 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-01-08T18:09:44.811Z 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 (.\node_modules\webdriver\build\utils.js:197:12)
[0-0] at NodeJSRequest._request (.\node_modules\webdriver\build\request\index.js:158:60)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async startWebDriverSession (.\node_modules\webdriver\build\utils.js:67:20)
[0-0] at async Function.newSession (.\node_modules\webdriver\build\index.js:58:45)
[0-0] at async remote (.\node_modules\webdriverio\build\index.js:73:22)
[0-0] at async launchExpoAndroid (.\test\AppiumSetup.ts:11:17)
[0-0] at async Context.<anonymous> (.\test\specs\example.test.ts:11:12)
[0-0] Error in "First tests."before all" hook for "adding""
Error: Failed to create session.
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 startWebDriverSession (.\node_modules\webdriver\build\utils.js:72:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Function.newSession (.\node_modules\webdriver\build\index.js:58:45)
at async remote (.\node_modules\webdriverio\build\index.js:73:22)
at async launchExpoAndroid (.\test\AppiumSetup.ts:11:17)
at async Context.<anonymous> (.\test\specs\example.test.ts:11:12)
[0-0] TypeError in "First tests."after all" hook for "adding""
TypeError: Cannot read properties of undefined (reading 'deleteSession')
at Context.<anonymous> (.\test\specs\example.test.ts:15:10)
at Context.executeAsync (.\node_modules\@wdio\utils\build\shim.js:325:27)
at Context.testFrameworkFnWrapper (.\node_modules\@wdio\utils\build\test-framework\testFnWrapper.js:45:32)
[0-0] 2022-01-08T18:09:44.868Z INFO webdriver: COMMAND deleteSession()
[0-0] 2022-01-08T18:09:44.869Z INFO webdriver: [DELETE] http://localhost:4723/session/bdc2d781-8aab-4a9c-ae96-3379e3d12623
[0-0] FAILED in host.exp.exponent - .\test\specs\example.test.ts
2022-01-08T18:09:45.286Z INFO @wdio/cli:launcher: Run onComplete hook
Spec Files: 0 passed, 1 failed, 1 total (100% completed) in 00:00:10
Please help