Skip to content

Commit

Permalink
chore(android): respect timeout, add build script (microsoft#4690)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Dec 12, 2020
1 parent f20518f commit aa1b546
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ jest-report.json
drivers/
/docs/api.json
.android-sdk/
.gradle/
Binary file modified bin/android-driver-target.apk
Binary file not shown.
Binary file modified bin/android-driver.apk
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 14 additions & 1 deletion src/server/android/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,14 @@ private static Direction parseDirection(JSONObject params) throws JSONException
}

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 {
Expand Down
4 changes: 2 additions & 2 deletions utils/avd_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ mkdir ${SDKDIR}/cmdline-tools

echo 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.zip
mv cmdline-tools latest

echo Installing emulator...
Expand Down
14 changes: 14 additions & 0 deletions utils/build_android_driver.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit aa1b546

Please sign in to comment.