Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore(android): respect timeout, add build script (#4690)
Pavel Feldmanaa1b546bd057
diff --git a/.gitignore b/.gitignoreindex 4506eee5d6..d67be88ba1 100644--- a/.gitignore+++ b/.gitignore@@ -17,3 +17,4 @@ jest-report.jsondrivers//docs/api.json.android-sdk/+.gradle/\ No newline at end of filediff --git a/bin/android-driver-target.apk b/bin/android-driver-target.apkindex 1e1e0d188f..a326d2549f 100644Binary files a/bin/android-driver-target.apk and b/bin/android-driver-target.apk differdiff --git a/bin/android-driver.apk b/bin/android-driver.apkindex 90c9184ea8..bb51655417 100644Binary files a/bin/android-driver.apk and b/bin/android-driver.apk differdiff --git a/package.json b/package.jsonindex e1d37955d5..0a19dadaae 100644--- a/package.json+++ b/package.json@@ -30,7 +30,8 @@"typecheck-tests": "tsc -p ./test/","roll-browser": "node utils/roll_browser.js","coverage": "node test/checkCoverage.js",- "check-deps": "node utils/check_deps.js"+ "check-deps": "node utils/check_deps.js",+ "build-android-driver": "./utils/build_android_driver.sh"},"author": {"name": "Microsoft Corporation"diff --git a/src/server/android/android.ts b/src/server/android/android.tsindex c08fadd1f8..257184f5f8 100644--- a/src/server/android/android.ts+++ b/src/server/android/android.ts@@ -54,6 +54,7 @@ export interface SocketBackend extends EventEmitter {export class Android {private _backend: Backend;+ private _devices = new Map<string, AndroidDevice>();readonly _timeoutSettings: TimeoutSettings;constructor(backend: Backend) {@@ -67,7 +68,19 @@ export class Android {async devices(): Promise<AndroidDevice[]> {const devices = (await this._backend.devices()).filter(d => d.status === 'device');- return await Promise.all(devices.map(d => AndroidDevice.create(this, d)));+ const newSerials = new Set<string>();+ for (const d of devices) {+ newSerials.add(d.serial);+ if (this._devices.has(d.serial))+ continue;+ const device = await AndroidDevice.create(this, d);+ this._devices.set(d.serial, device);+ }+ for (const d of this._devices.keys()) {+ if (!newSerials.has(d))+ this._devices.delete(d);+ }+ return [...this._devices.values()];}}diff --git a/src/server/android/driver/app/src/androidTest/java/com/microsoft/playwright/androiddriver/InstrumentedTest.java b/src/server/android/driver/app/src/androidTest/java/com/microsoft/playwright/androiddriver/InstrumentedTest.javaindex 9483a72610..4c9cb6d7af 100644--- a/src/server/android/driver/app/src/androidTest/java/com/microsoft/playwright/androiddriver/InstrumentedTest.java+++ b/src/server/android/driver/app/src/androidTest/java/com/microsoft/playwright/androiddriver/InstrumentedTest.java@@ -154,11 +154,14 @@ public class InstrumentedTest {}private static UiObject2 wait(UiDevice device, JSONObject params) throws JSONException {- return device.wait(Until.findObject(parseSelector(params)), parseTimeout(params));+ UiObject2 result = device.wait(Until.findObject(parseSelector(params)), parseTimeout(params));+ if (result == null)+ throw new RuntimeException("Timed out waiting for selector");+ return result;}private static void fill(UiDevice device, JSONObject params) throws JSONException {- device.wait(Until.findObject(parseSelector(params)), parseTimeout(params)).setText(params.getString("text"));+ wait(device, params).setText(params.getString("text"));}private static void click(UiDevice device, JSONObject params) throws JSONException {diff --git a/utils/avd_install.sh b/utils/avd_install.shindex e7b476146e..5f1310c0d6 100755--- a/utils/avd_install.sh+++ b/utils/avd_install.sh@@ -10,8 +10,8 @@ mkdir ${SDKDIR}/cmdline-toolsecho Downloading Android SDK...cd ${SDKDIR}/cmdline-tools-curl https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip -o commandlinetools-linux-6858069_latest.zip-unzip commandlinetools-linux-6858069_latest.zip+curl https://dl.google.com/android/repository/commandlinetools-mac-6858069_latest.zip -o commandlinetools-mac-6858069_latest.zip+unzip commandlinetools-mac-6858069_latest.zipmv cmdline-tools latestecho Installing emulator...diff --git a/utils/build_android_driver.sh b/utils/build_android_driver.shnew file mode 100755index 0000000000..92b8c66c8f--- /dev/null+++ b/utils/build_android_driver.sh@@ -0,0 +1,14 @@+#!/bin/bash++(cd src/server/android/driver ; ./gradlew assemble)+if [ "$?" -ne "0" ]; then+ exit 1+fi++(cd src/server/android/driver ; ./gradlew assembleAndroidTest)+if [ "$?" -ne "0" ]; then+ exit 1+fi++cp src/server/android/driver/app/build/outputs/apk/debug/app-debug.apk ./bin/android-driver-target.apk+cp src/server/android/driver/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk ./bin/android-driver.apk