Skip to content

Commit 1d9da9b

Browse files
authoredSep 27, 2024··
Add example for Emulators & Simulators (#763)
1 parent 1ef790f commit 1d9da9b

16 files changed

+276
-51
lines changed
 

‎.github/workflows/wdio-android.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: WDIO Android Tests
5+
6+
on:
7+
push:
8+
paths:
9+
- 'wdio-android-app/**'
10+
- '.github/workflows/wdio-android.yml'
11+
branches:
12+
- main
13+
pull_request:
14+
paths:
15+
- 'wdio-android-app/**'
16+
- '.github/workflows/wdio-android.yml'
17+
branches:
18+
- main
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
wdio-native-app:
26+
runs-on: ubuntu-latest
27+
strategy:
28+
matrix:
29+
runtype: [realdevice, emulator]
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Install saucectl
35+
uses: saucelabs/saucectl-run-action@v4
36+
env:
37+
GITHUB_TOKEN: ${{ github.token }}
38+
with:
39+
skip-run: true
40+
41+
- name: Pre-Upload App
42+
id: upload
43+
working-directory: ./wdio-android-app/
44+
env:
45+
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
46+
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
47+
run: |
48+
APP_FILEID=$(saucectl storage upload ./app/SauceLabs-Demo-App.apk -o json | jq -r '.id')
49+
echo "APP_FILEID=${APP_FILEID}" >> $GITHUB_OUTPUT
50+
51+
- name: Build wdio example
52+
uses: docker/build-push-action@v4
53+
with:
54+
context: ./wdio-android-app
55+
file: ./wdio-ios-app/Dockerfile
56+
build-args: |
57+
APP_FILEID=${{ steps.upload.outputs.APP_FILEID }}
58+
SIMULATOR_APP_FILEID=""
59+
RUN_TYPE=${{ matrix.runtype }}
60+
push: false
61+
secrets: |
62+
"dotenv=${{ secrets.DOTENV }}"

‎.github/workflows/wdio-ios.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: WDIO iOS Tests
5+
6+
on:
7+
push:
8+
paths:
9+
- 'wdio-ios-app/**'
10+
- '.github/workflows/wdio-ios.yml'
11+
branches:
12+
- main
13+
pull_request:
14+
paths:
15+
- 'wdio-ios-app/**'
16+
- '.github/workflows/wdio-ios.yml'
17+
branches:
18+
- main
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
wdio-native-app:
26+
runs-on: ubuntu-latest
27+
strategy:
28+
matrix:
29+
runtype: [realdevice, simulator]
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Install saucectl
35+
uses: saucelabs/saucectl-run-action@v4
36+
env:
37+
GITHUB_TOKEN: ${{ github.token }}
38+
with:
39+
skip-run: true
40+
41+
- name: Pre-Upload App
42+
id: upload
43+
working-directory: ./wdio-ios-app/
44+
env:
45+
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
46+
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
47+
run: |
48+
APP_FILEID=$(saucectl storage upload ./app/SauceLabs-Demo-App.ipa -o json | jq -r '.id')
49+
SIMULATOR_APP_FILEID=$(saucectl storage upload ./app/SauceLabs-Demo-App.Simulator.ipa -o json | jq -r '.id')
50+
echo "APP_FILEID=${APP_FILEID}" >> $GITHUB_OUTPUT
51+
echo "SIMULATOR_APP_FILEID=${SIMULATOR_APP_FILEID}" >> $GITHUB_OUTPUT
52+
53+
- name: Build wdio example
54+
uses: docker/build-push-action@v4
55+
with:
56+
context: ./wdio-ios-app
57+
file: ./wdio-ios-app/Dockerfile
58+
build-args: |
59+
APP_FILEID=${{ steps.upload.outputs.APP_FILEID }}
60+
SIMULATOR_APP_FILEID=${{ steps.upload.outputs.SIMULATOR_APP_FILEID }}
61+
RUN_TYPE=${{ matrix.runtype }}
62+
push: false
63+
secrets: |
64+
"dotenv=${{ secrets.DOTENV }}"

‎.github/workflows/wdio.yml

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,3 @@ jobs:
6666
push: false
6767
secrets: |
6868
"dotenv=${{ secrets.DOTENV }}"
69-
70-
wdio-native-app:
71-
runs-on: ubuntu-latest
72-
strategy:
73-
matrix:
74-
platform: [ios, android]
75-
steps:
76-
- name: Checkout code
77-
uses: actions/checkout@v4
78-
79-
- name: Install saucectl
80-
uses: saucelabs/saucectl-run-action@v4
81-
env:
82-
GITHUB_TOKEN: ${{ github.token }}
83-
with:
84-
skip-run: true
85-
86-
- name: Pre-Upload App
87-
id: upload
88-
working-directory: ./wdio-${{ matrix.platform }}-app/
89-
env:
90-
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
91-
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
92-
run: |
93-
EXT=apk
94-
if [ "${{ matrix.platform }}" = "ios" ];then
95-
EXT=ipa
96-
fi
97-
APP_FILEID=$(saucectl storage upload ./app/SauceLabs-Demo-App.${EXT} -o json | jq -r '.id')
98-
echo "APP_FILEID=${APP_FILEID}" >> $GITHUB_OUTPUT
99-
100-
- name: Build wdio example
101-
uses: docker/build-push-action@v4
102-
with:
103-
context: ./wdio-${{ matrix.platform }}-app
104-
file: ././wdio/Dockerfile
105-
build-args:
106-
APP_FILEID=${{ steps.upload.outputs.APP_FILEID }}
107-
push: false
108-
secrets: |
109-
"dotenv=${{ secrets.DOTENV }}"

‎wdio-android-app/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
app/

‎wdio-android-app/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,30 @@ export APP_FILEID=<file-ID-returned-by-saucectl>
6161

6262
- Run the test
6363

64-
65-
```sh { name=npm-run }
64+
On a real device:
65+
```sh { name=npm-run-realdevice }
6666
npm run sauce-visual
6767
```
6868

69+
On an emulator:
70+
```sh { name=npm-run-emulator }
71+
npm run sauce-visual-emulator
72+
```
73+
6974
- Review your screenshots by clicking on the url printed in the test or go to https://app.saucelabs.com/visual/builds.
7075
- Accept all diffs, so they become new baselines.
7176
- Re-run the tests
7277

73-
```sh { name=npm-run-modified }
78+
On a real device:
79+
```sh { name=npm-run-realdevice-modified }
7480
npm run sauce-visual-check
7581
```
7682

83+
On an emulator:
84+
```sh { name=npm-run-emulator-modified }
85+
npm run sauce-visual-emulator-check
86+
```
87+
7788
- Open the test or go to https://app.saucelabs.com/visual/builds to review changes.
7889

7990
## Installation & Usage
-158 KB
Binary file not shown.

‎wdio-android-app/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
},
1717
"scripts": {
1818
"sauce-visual": "wdio run ./tests/configs/wdio.saucelabs.mobile.conf.ts --spec tests/specs/visual.spec.ts",
19-
"sauce-visual-check": "VISUAL_CHECK=true wdio run ./tests/configs/wdio.saucelabs.mobile.conf.ts --spec tests/specs/visual.spec.ts"
19+
"sauce-visual-check": "VISUAL_CHECK=true wdio run ./tests/configs/wdio.saucelabs.mobile.conf.ts --spec tests/specs/visual.spec.ts",
20+
"sauce-visual-emulator": "wdio run ./tests/configs/wdio.saucelabs.emulator.conf.ts --spec tests/specs/visual.spec.ts",
21+
"sauce-visual-emulator-check": "VISUAL_CHECK=true wdio run ./tests/configs/wdio.saucelabs.emulator.conf.ts --spec tests/specs/visual.spec.ts"
2022
},
2123
"dependencies": {
2224
"@saucelabs/wdio-sauce-visual-service": "^0.6.0",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { Options } from '@wdio/types';
2+
import { config as sauceSharedConfig } from './wdio.saucelabs.shared.conf.ts';
3+
4+
const build = `Sauce Demo Test - ${new Date().getTime()}`;
5+
6+
export const config: Options.Testrunner = {
7+
...sauceSharedConfig,
8+
// ============
9+
// Capabilities
10+
// ============
11+
// For all capabilities please check
12+
// https://saucelabs.com/products/platform-configurator
13+
// and http://appium.io/docs/en/2.0/guides/caps/
14+
// For available devices please check
15+
// https://app.saucelabs.com/live/app-testing
16+
capabilities: [
17+
{
18+
'platformName': 'Android',
19+
'appium:deviceName': 'Google Pixel 3 XL GoogleAPI Emulator',
20+
'appium:platformVersion': 'current_major',
21+
'appium:app': `storage:${process.env.APP_FILEID}`,
22+
'appium:automationName': 'UIAutomator2',
23+
// https://kobiton.com/blog/understanding-appium-desired-capabilities/
24+
// Appium checks periodically that the main activity is (in our demo app, the SplashActivity).
25+
// SplashActivity may transition to MainActivity before Appium has check that it was displayed.
26+
// Waiting for MainActivity permits Appium to notice that the app is fully started, and allow tests to continue.
27+
'appium:appWaitActivity': 'com.saucelabs.mydemoapp.android.view.activities.MainActivity',
28+
'sauce:options': {
29+
build,
30+
name: `wdio-android-app - Emulator`,
31+
}
32+
}
33+
],
34+
};

‎wdio-android-app/tests/configs/wdio.saucelabs.mobile.conf.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ export const config: Options.Testrunner = {
2525
'appium:app': `storage:${process.env.APP_FILEID}`,
2626
'sauce:options': {
2727
appiumVersion: 'latest',
28-
build
28+
build,
29+
name: `wdio-android-app - Real Device`,
2930
},
30-
}
31+
},
3132
],
3233
};

‎wdio-ios-app/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
app/

‎wdio-ios-app/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM ubuntu:22.04 as amd64
2+
3+
RUN apt-get update && apt-get install -y curl
4+
5+
# Install runme
6+
RUN curl -sSL https://download.stateful.com/runme/1.2.6/runme_linux_x86_64.tar.gz | tar -xz -C /usr/local/bin runme
7+
RUN runme --version
8+
9+
FROM ubuntu:22.04 as arm64
10+
11+
RUN apt-get update && apt-get install -y curl
12+
13+
# Install runme
14+
RUN curl -sSL https://download.stateful.com/runme/1.2.6/runme_linux_arm64.tar.gz | tar -xz -C /usr/local/bin runme
15+
RUN runme --version
16+
17+
FROM ${TARGETARCH}
18+
19+
RUN mkdir -p /workspace
20+
WORKDIR /workspace
21+
22+
COPY . .
23+
24+
RUN runme run nodejs-linux
25+
RUN runme run npm-install
26+
27+
ARG APP_FILEID
28+
ARG SIMULATOR_APP_FILEID
29+
ARG RUN_TYPE
30+
31+
RUN --mount=type=secret,id=dotenv,target=/workspace/.env runme run npm-run-${RUN_TYPE}
32+
RUN --mount=type=secret,id=dotenv,target=/workspace/.env runme run npm-run-${RUN_TYPE}-modified

‎wdio-ios-app/README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export SAUCE_ACCESS_KEY=__YOUR_SAUCE_ACCESS_KEY__
5050
5151
- Upload application binary using `saucectl`
5252
53+
For Real Devices:
5354
```sh { name=upload-binary }
5455
npx saucectl storage upload ./app/SauceLabs-Demo-App.ipa
5556
```
@@ -59,21 +60,44 @@ npx saucectl storage upload ./app/SauceLabs-Demo-App.ipa
5960
export APP_FILEID=<file-ID-returned-by-saucectl>
6061
```
6162

62-
- Run the test
6363

64+
For Simulators:
65+
```sh { name=upload-binary-simulators }
66+
npx saucectl storage upload ./app/SauceLabs-Demo-App.Simulator.ipa
67+
```
68+
69+
- Get the file ID and export it to the env
70+
```sh { name=set-file-id-simulators }
71+
export SIMULATOR_APP_FILEID=<file-ID-returned-by-saucectl>
72+
```
73+
74+
- Run the test
6475

65-
```sh { name=npm-run }
76+
On a Real Device:
77+
```sh { name=npm-run-realdevice }
6678
npm run sauce-visual
6779
```
6880

81+
On a Simulator:
82+
83+
```sh { name=npm-run-simulator }
84+
npm run sauce-visual-simulator
85+
```
86+
6987
- Review your screenshots by clicking on the url printed in the test or go to https://app.saucelabs.com/visual/builds.
7088
- Accept all diffs, so they become new baselines.
7189
- Re-run the tests
7290

73-
```sh { name=npm-run-modified }
91+
On a Real Device:
92+
```sh { name=npm-run-realdevice-modified }
7493
npm run sauce-visual-check
7594
```
7695

96+
On a Simulator:
97+
```sh { name=npm-run-simulator-modified }
98+
npm run sauce-visual-simulator-check
99+
```
100+
77101
- Open the test or go to https://app.saucelabs.com/visual/builds to review changes.
78102

79103
## Installation & Usage
Binary file not shown.

‎wdio-ios-app/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
},
1717
"scripts": {
1818
"sauce-visual": "wdio run ./tests/configs/wdio.saucelabs.mobile.conf.ts --spec tests/specs/visual.spec.ts",
19-
"sauce-visual-check": "VISUAL_CHECK=true wdio run ./tests/configs/wdio.saucelabs.mobile.conf.ts --spec tests/specs/visual.spec.ts"
19+
"sauce-visual-check": "VISUAL_CHECK=true wdio run ./tests/configs/wdio.saucelabs.mobile.conf.ts --spec tests/specs/visual.spec.ts",
20+
"sauce-visual-simulator": "wdio run ./tests/configs/wdio.saucelabs.simulator.conf.ts --spec tests/specs/visual.spec.ts",
21+
"sauce-visual-simulator-check": "VISUAL_CHECK=true wdio run ./tests/configs/wdio.saucelabs.simulator.conf.ts --spec tests/specs/visual.spec.ts"
2022
},
2123
"dependencies": {
2224
"@saucelabs/wdio-sauce-visual-service": "^0.6.0",

‎wdio-ios-app/tests/configs/wdio.saucelabs.mobile.conf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const config: Options.Testrunner = {
2525
'appium:app': `storage:${process.env.APP_FILEID}`,
2626
'sauce:options': {
2727
appiumVersion: 'latest',
28+
name: `wdio-ios-app - Real Device`,
2829
build
2930
},
3031
}

0 commit comments

Comments
 (0)
Please sign in to comment.