Skip to content

Commit

Permalink
chore(adb): make driver smaller (#4713)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Dec 15, 2020
1 parent b09e0d0 commit e02c544
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ jobs:
run: utils/avd_recreate.sh
- name: Start Android Emulator
run: utils/avd_start.sh
- run: npx folio test/android -p browserName=chromium --workers=1 --forbid-only --timeout=60000 --global-timeout=5400000 --retries=3 --reporter=dot,json
- run: npx folio test/android -p browserName=chromium --workers=1 --forbid-only --timeout=120000 --global-timeout=5400000 --retries=3 --reporter=dot,json
env:
FOLIO_JSON_OUTPUT_NAME: "test-results/report.json"
PW_ANDROID_TESTS: 1
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ jest-report.json
drivers/
/docs/api.json
.android-sdk/
.gradle/
.gradle/
nohup.out
Binary file modified bin/android-driver-target.apk
Binary file not shown.
Binary file modified bin/android-driver.apk
Binary file not shown.
6 changes: 2 additions & 4 deletions src/dispatchers/androidDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ export class AndroidDeviceDispatcher extends Dispatcher<AndroidDevice, channels.
}

async fill(params: channels.AndroidDeviceFillParams) {
await Promise.all([
this._object.send('click', { selector: params.selector }),
this._object.send('fill', params)
]);
await this._object.send('click', { selector: params.selector });
await this._object.send('fill', params);
}

async tap(params: channels.AndroidDeviceTapParams) {
Expand Down
17 changes: 9 additions & 8 deletions src/server/android/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ export class AndroidDevice extends EventEmitter {
}

private async _driver(): Promise<Transport> {
if (this._driverPromise)
return this._driverPromise;
let callback: any;
this._driverPromise = new Promise(f => callback = f);
if (!this._driverPromise)
this._driverPromise = this._installDriver();
return this._driverPromise;
}

private async _installDriver(): Promise<Transport> {
debug('pw:android')('Stopping the old driver');
await this.shell(`am force-stop com.microsoft.playwright.androiddriver`);

Expand Down Expand Up @@ -185,9 +186,7 @@ export class AndroidDevice extends EventEmitter {
callback.fulfill(result);
this._callbacks.delete(id);
};

callback(transport);
return this._driverPromise;
return transport;
}

private async _waitForLocalAbstract(socketName: string): Promise<SocketBackend> {
Expand All @@ -204,7 +203,9 @@ export class AndroidDevice extends EventEmitter {
return socket;
}

async send(method: string, params: any): Promise<any> {
async send(method: string, params: any = {}): Promise<any> {
// Patch the timeout in!
params.timeout = this._timeoutSettings.timeout(params);
const driver = await this._driver();
const id = ++this._lastId;
const result = new Promise((fulfill, reject) => this._callbacks.set(id, { fulfill, reject }));
Expand Down
4 changes: 0 additions & 4 deletions src/server/android/driver/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ android {
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.view.accessibility.AccessibilityNodeInfo;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SdkSuppress;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.BySelector;
Expand Down Expand Up @@ -53,7 +52,6 @@
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
@SdkSuppress(minSdkVersion = 21)
public class InstrumentedTest {

@SuppressWarnings("ConstantConditions")
Expand Down
5 changes: 2 additions & 3 deletions src/server/android/driver/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:label="Playwright Android Driver"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PlaywrightAndroidDriver" />
android:supportsRtl="true" />

</manifest>
16 changes: 0 additions & 16 deletions src/server/android/driver/app/src/main/res/values-night/themes.xml

This file was deleted.

10 changes: 0 additions & 10 deletions src/server/android/driver/app/src/main/res/values/colors.xml

This file was deleted.

3 changes: 0 additions & 3 deletions src/server/android/driver/app/src/main/res/values/strings.xml

This file was deleted.

16 changes: 0 additions & 16 deletions src/server/android/driver/app/src/main/res/values/themes.xml

This file was deleted.

1 change: 1 addition & 0 deletions test/android/android.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fixtures.device.init(async ({ playwright }, runTest) => {
const [device] = await playwright._android.devices();
await device.shell('am force-stop org.chromium.webview_shell');
await device.shell('am force-stop com.android.chrome');
device.setDefaultTimeout(120000);
await runTest(device);
device.close();
});
Expand Down
8 changes: 8 additions & 0 deletions test/android/device.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ if (process.env.PW_ANDROID_TESTS) {
const data = await device.shell('cat /data/local/tmp/hello-world');
expect(data).toEqual(Buffer.from('hello world'));
});

it('androidDevice.fill', test => {
test.fixme(!!process.env.CI, 'Hangs on the bots');
}, async function({ device }) {
await device.shell('am start org.chromium.webview_shell/.WebViewBrowserActivity');
await device.fill({ res: 'org.chromium.webview_shell:id/url_field' }, 'Hello');
expect((await device.info({ res: 'org.chromium.webview_shell:id/url_field' })).text).toBe('Hello');
});
}
2 changes: 1 addition & 1 deletion test/android/webview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if (process.env.PW_ANDROID_TESTS) {

it('should navigate page externally', test => {
test.fixme(!!process.env.CI, 'Hangs on the bots');
}, async function({ device, server }) {
}, async function({ device }) {
expect(device.webViews().length).toBe(0);
await device.shell('am start org.chromium.webview_shell/.WebViewBrowserActivity');
const webview = await device.webView({ pkg: 'org.chromium.webview_shell' });
Expand Down
4 changes: 2 additions & 2 deletions utils/avd_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ if [[ -z "${ANDROID_HOME}" ]]; then
fi

echo "Killing previous emulators"
${ANDROID_HOME}/platform-tools/adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
${ANDROID_HOME}/platform-tools/adb devices | grep emulator | cut -f1 | while read line; do ${ANDROID_HOME}/platform-tools/adb -s $line emu kill; done

echo "Starting emulator"
nohup ${ANDROID_HOME}/emulator/emulator -avd android30 -no-audio -no-snapshot -no-window -gpu swiftshader_indirect &
nohup ${ANDROID_HOME}/emulator/emulator -avd android30 -no-audio -no-snapshot &
${ANDROID_HOME}/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
${ANDROID_HOME}/platform-tools/adb devices
echo "Emulator started"

0 comments on commit e02c544

Please sign in to comment.