Browse Source

chore(adb): make driver smaller (#4713)

pull/4724/head
Pavel Feldman 4 months ago
committed by GitHub
parent
commit
e02c54485c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 28 additions and 71 deletions
  1. +1
    -1
      .github/workflows/tests.yml
  2. +2
    -1
      .gitignore
  3. BIN
      bin/android-driver-target.apk
  4. BIN
      bin/android-driver.apk
  5. +2
    -4
      src/dispatchers/androidDispatcher.ts
  6. +9
    -8
      src/server/android/android.ts
  7. +0
    -4
      src/server/android/driver/app/build.gradle
  8. +0
    -2
      src/server/android/driver/app/src/androidTest/java/com/microsoft/playwright/androiddriver/InstrumentedTest.java
  9. +2
    -3
      src/server/android/driver/app/src/main/AndroidManifest.xml
  10. +0
    -16
      src/server/android/driver/app/src/main/res/values-night/themes.xml
  11. +0
    -10
      src/server/android/driver/app/src/main/res/values/colors.xml
  12. +0
    -3
      src/server/android/driver/app/src/main/res/values/strings.xml
  13. +0
    -16
      src/server/android/driver/app/src/main/res/values/themes.xml
  14. +1
    -0
      test/android/android.fixtures.ts
  15. +8
    -0
      test/android/device.spec.ts
  16. +1
    -1
      test/android/webview.spec.ts
  17. +2
    -2
      utils/avd_start.sh

+ 1
- 1
.github/workflows/tests.yml View File

@ -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


+ 2
- 1
.gitignore View File

@ -17,4 +17,5 @@ jest-report.json
drivers/
/docs/api.json
.android-sdk/
.gradle/
.gradle/
nohup.out

BIN
bin/android-driver-target.apk View File


BIN
bin/android-driver.apk View File


+ 2
- 4
src/dispatchers/androidDispatcher.ts View File

@ -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) {


+ 9
- 8
src/server/android/android.ts View File

@ -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`);
@ -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> {
@ -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 }));


+ 0
- 4
src/server/android/driver/app/build.gradle View File

@ -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'


+ 0
- 2
src/server/android/driver/app/src/androidTest/java/com/microsoft/playwright/androiddriver/InstrumentedTest.java View File

@ -23,7 +23,6 @@ import android.net.LocalSocket;
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;
@ -53,7 +52,6 @@ import java.util.regex.Pattern;
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
@SdkSuppress(minSdkVersion = 21)
public class InstrumentedTest {
@SuppressWarnings("ConstantConditions")


+ 2
- 3
src/server/android/driver/app/src/main/AndroidManifest.xml View File

@ -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>

+ 0
- 16
src/server/android/driver/app/src/main/res/values-night/themes.xml View File

@ -1,16 +0,0 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.PlaywrightAndroidDriver" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

+ 0
- 10
src/server/android/driver/app/src/main/res/values/colors.xml View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>

+ 0
- 3
src/server/android/driver/app/src/main/res/values/strings.xml View File

@ -1,3 +0,0 @@
<resources>
<string name="app_name">Playwright Android Driver</string>
</resources>

+ 0
- 16
src/server/android/driver/app/src/main/res/values/themes.xml View File

@ -1,16 +0,0 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.PlaywrightAndroidDriver" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

+ 1
- 0
test/android/android.fixtures.ts View File

@ -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();
});


+ 8
- 0
test/android/device.spec.ts View File

@ -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');
});
}

+ 1
- 1
test/android/webview.spec.ts View File

@ -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' });


+ 2
- 2
utils/avd_start.sh View File

@ -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"

Loading…
Cancel
Save