Skip to content

Commit 08d91d4

Browse files
author
Krzysztof Borowy
committed
wdio runner
1 parent 9ee7ae7 commit 08d91d4

File tree

15 files changed

+1243
-1238
lines changed

15 files changed

+1243
-1238
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ jobs:
5151
uses: actions/upload-artifact@v3
5252
with:
5353
name: app-release.apk
54-
path: example/android/app/build/outputs/apk/release/
54+
path: example/android/app/build/outputs/apk/release/app-release.apk
5555
ios:
5656
name: iOS
57+
if: false # temp
5758
runs-on: macos-latest
5859
steps:
5960
- name: Checkout
@@ -78,7 +79,7 @@ jobs:
7879
yarn
7980
- name: Bundle JS
8081
run: |
81-
yarn bundle:ios --dev false
82+
yarn bundle:ios
8283
- name: Install Pods
8384
run: |
8485
pod install
@@ -156,11 +157,11 @@ jobs:
156157
157158
e2e-tests:
158159
name: Run e2e tests
159-
needs: [review, android, ios]
160+
needs: [review, android]
160161
if: github.event_name == 'pull_request'
161162
strategy:
162163
matrix:
163-
platform: [ android, ios ]
164+
platform: [ android ] # TEMP removed ios
164165
runs-on: macos-latest
165166
steps:
166167
- name: Checkout
@@ -175,12 +176,6 @@ jobs:
175176
yarn
176177
- name: Gradle cache
177178
uses: gradle/gradle-build-action@v2
178-
- name: Start Appium server
179-
run: |
180-
yarn appium --config example/appium.config.js &
181-
- name: Wait for appium boot
182-
run: |
183-
sleep 5
184179

185180
# ios part
186181
- name: Download iOS binary

example/__tests__/android.conf.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { config as commonConfig } from './common.conf';
2+
3+
export const config: WebdriverIO.Config = {
4+
...commonConfig,
5+
capabilities: [
6+
{
7+
platformName: 'Android',
8+
maxInstances: 1,
9+
'appium:deviceName': 'Android Emulator',
10+
'appium:app':
11+
'example/android/app/build/outputs/apk/release/app-release.apk',
12+
'appium:automationName': 'UiAutomator2',
13+
'appium:newCommandTimeout': 240,
14+
'appium:appWaitActivity':
15+
'com.microsoft.reacttestapp.component.ComponentActivity',
16+
},
17+
],
18+
};

example/__tests__/asyncstorage.spec.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import { commands as cmd } from './commands';
22
import testCases from '../examples/tests';
33

4-
describe('Async Storage', () => {
5-
describe('functional tests', () => {
6-
it('should be visible', async () => {
7-
const el = await cmd.elementByLabel('functional-view');
8-
await expect(await el.isExisting()).toEqual(true);
9-
});
4+
describe('Async Storage functional tests', () => {
5+
it('should be visible', async () => {
6+
// wait until content loads, as android's waitForSelectorTimeout setting does not seem to work
7+
await new Promise((r) => setTimeout(r, 3000));
8+
const el = await cmd.elementByLabel('functional-view');
9+
await expect(await el.isExisting()).toEqual(true);
10+
});
1011

11-
const testNames = Object.keys(testCases);
12+
const testNames = Object.keys(testCases);
13+
describe('storing / reading values', () => {
1214
for (const name of testNames) {
1315
it(`${name}`, async () => {
1416
const el = await cmd.elementByLabel(`test:${name}`);
1517
await expect(await el.getText()).toEqual('Pass');
1618
});
1719
}
20+
});
1821

19-
// Re-run tests with native delegate set
22+
describe('storing / reading values with delegate', () => {
2023
for (const currentName of testNames) {
2124
const name = currentName + ' with delegate';
2225
it(`${name}`, async () => {

example/__tests__/commands.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { e2e } from '../jest.setup';
2-
31
const testAppId = 'com.microsoft.ReactTestApp';
2+
import { browser } from '@wdio/globals';
43

54
export const commands = {
65
restartApp: async () => {
7-
await e2e.terminateApp(testAppId);
8-
await e2e.activateApp(testAppId);
6+
await browser.terminateApp(testAppId);
7+
await browser.activateApp(testAppId);
98
},
10-
elementByLabel: async (id: string) => await e2e.$(`~${id}`),
9+
elementByLabel: async (id: string) => await $(`~${id}`),
1110
};

example/__tests__/common.conf.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
export const config: WebdriverIO.Config = {
2+
runner: 'local',
3+
autoCompileOpts: {
4+
autoCompile: true,
5+
tsNodeOpts: {
6+
transpileOnly: true,
7+
project: '../../tsconfig.all.json',
8+
},
9+
},
10+
capabilities: [],
11+
connectionRetryTimeout: 180000,
12+
waitforTimeout: 90000,
13+
framework: 'mocha',
14+
reporters: ['spec'],
15+
mochaOpts: {
16+
ui: 'bdd',
17+
/**
18+
* NOTE: This has been increased for more stable Appium Native app
19+
* tests because they can take a bit longer.
20+
*/
21+
timeout: 5 * 60 * 1000, // 5min
22+
},
23+
specs: ['./asyncstorage.spec.ts'],
24+
services: [
25+
[
26+
'appium',
27+
{
28+
command: 'appium',
29+
args: {
30+
// This is needed to tell Appium that we can execute local ADB commands
31+
// and to automatically download the latest version of ChromeDriver
32+
relaxedSecurity: true,
33+
address: '127.0.0.1',
34+
'callback-port': 4723,
35+
port: 4723,
36+
},
37+
},
38+
],
39+
],
40+
};

example/__tests__/ios.conf.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { config as commonConfig } from './common.conf';
2+
3+
export const config: WebdriverIO.Config = {
4+
...commonConfig,
5+
capabilities: [
6+
{
7+
platformName: 'iOS',
8+
'appium:platformVersion': '16.4',
9+
'appium:deviceName': 'iPhone 14',
10+
'appium:automationName': 'XCUITest',
11+
'appium:app':
12+
'example/ios/build/Build/Products/Release-iphonesimulator/ReactTestApp.app',
13+
},
14+
],
15+
};

example/appium.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/examples/Functional.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ async function execute(steps: TestStep[]): Promise<void> {
8181
const testProp = (id: string) =>
8282
Platform.select({
8383
android: {
84+
accessible: true,
8485
accessibilityLabel: id,
8586
},
8687
ios: {
88+
accessible: false,
8789
testID: id,
8890
},
8991
});

example/jest.config.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

example/jest.setup.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,20 @@
7474
"@semantic-release/git": "^10.0.0",
7575
"@types/jest": "^29.5.2",
7676
"@types/lodash": "^4.14.184",
77+
"@types/mocha": "^10.0.1",
7778
"@types/react": "^18.0.0",
79+
"@wdio/appium-service": "^8.11.2",
80+
"@wdio/cli": "^8.11.2",
81+
"@wdio/local-runner": "^8.11.2",
82+
"@wdio/mocha-framework": "^8.11.0",
83+
"@wdio/spec-reporter": "^8.11.2",
7884
"appium": "2.0.0-rc.3",
7985
"appium-uiautomator2-driver": "^2.26.2",
8086
"appium-xcuitest-driver": "^4.32.5",
8187
"concurrently": "^6.4.0",
8288
"eslint": "^8.0.0",
89+
"eslint-plugin-wdio": "^8.8.7",
8390
"expo": "^48.0.0",
84-
"jest": "^29.3.1",
8591
"lodash": "^4.17.21",
8692
"prettier": "^2.5.1",
8793
"react": "18.2.0",
@@ -108,18 +114,22 @@
108114
"metro-react-native-babel-transformer": "^0.73.10",
109115
"metro-runtime": "^0.73.10",
110116
"metro-source-map": "^0.73.10",
111-
"chalk": "4.1.2",
112117
"uuid": "^9.0.0",
113118
"ts-node": "^10.9.1"
114119
},
115120
"eslintConfig": {
116121
"root": true,
122+
"plugins": [
123+
"wdio"
124+
],
117125
"extends": [
118126
"@react-native-community",
127+
"plugin:wdio/recommended",
119128
"plugin:jest/recommended"
120129
],
121130
"rules": {
122-
"dot-notation": "off"
131+
"dot-notation": "off",
132+
"jest/no-deprecated-functions": "off"
123133
}
124134
},
125135
"prettier": {

scripts/android_e2e.sh

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/bin/bash
22

3-
INTERVAL=5 # 5 secs between each check
4-
MAX_RETRIES=60 # wait max 5 minutes for emu to boot
5-
63
build_apk() {
74
echo
85
echo "[Android E2E] Building APK"
@@ -13,58 +10,16 @@ bundle_js() {
1310
extraArgs="$@"
1411
echo
1512
echo "[Android E2E] Bundling JS"
16-
react-native bundle --entry-file index.ts --platform android --bundle-output example/index.android.jsbundle $extraArgs
17-
}
18-
19-
wait_for_emulator_to_boot() {
20-
isBooted=$(adb shell getprop sys.boot_completed 2>&1 | tr -d '\r')
21-
retriesLeft=${MAX_RETRIES}
22-
23-
echo
24-
echo "[Android E2E] Checking if emulator is booted up."
25-
26-
while [[ "$isBooted" != "1" ]]; do
27-
28-
if [[ ${retriesLeft} -eq 0 ]]; then
29-
echo "[Android E2E] Seems like emulator could not be booted." 1>&2
30-
exit 125
31-
fi
32-
33-
isBooted=$(adb shell getprop sys.boot_completed 2>&1 | tr -d '\r')
34-
35-
retriesLeft=$((retriesLeft - 1))
36-
echo "[Android E2E] $retriesLeft checks left."
37-
sleep ${INTERVAL}
38-
done
39-
40-
echo "[Android E2E] Emulator booted."
13+
react-native bundle --entry-file index.ts --platform android --bundle-output example/index.android.jsbundle --dev false $extraArgs
4114
}
4215

43-
assert_appium_server_running() {
44-
RES=$(curl -Is "http://0.0.0.0:4723/status" | grep HTTP | cut -d ' ' -f2)
45-
46-
if [ "$RES" != "200" ]; then
47-
echo "[Android E2E] Appium server not running! Try starting it:"
48-
echo
49-
echo "yarn appium --config example/appium.config.js"
50-
echo
51-
exit 2
52-
fi;
53-
}
5416

5517
run_e2e_test() {
56-
export NODE_OPTIONS=--experimental-vm-modules
57-
export E2E_PLATFORM=android
58-
assert_appium_server_running
59-
6018
echo "[Android E2E] Running tests"
61-
jest --config example/jest.config.ts --roots=$PWD
19+
wdio run example/__tests__/android.conf.ts
6220
}
6321

6422
case $1 in
65-
wait_for_emulator)
66-
wait_for_emulator_to_boot
67-
;;
6823
build)
6924
build_apk
7025
;;

0 commit comments

Comments
 (0)