mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-03 17:09:01 +03:00
chore(adb): make driver smaller (#4713)
This commit is contained in:
parent
b09e0d01bd
commit
e02c54485c
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -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
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -17,4 +17,5 @@ jest-report.json
|
||||
drivers/
|
||||
/docs/api.json
|
||||
.android-sdk/
|
||||
.gradle/
|
||||
.gradle/
|
||||
nohup.out
|
Binary file not shown.
Binary file not shown.
@ -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) {
|
||||
|
@ -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 }));
|
||||
|
@ -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'
|
||||
|
@ -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")
|
||||
|
@ -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>
|
@ -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>
|
@ -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>
|
@ -1,3 +0,0 @@
|
||||
<resources>
|
||||
<string name="app_name">Playwright Android Driver</string>
|
||||
</resources>
|
@ -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>
|
@ -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();
|
||||
});
|
||||
|
@ -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');
|
||||
});
|
||||
}
|
||||
|
@ -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' });
|
||||
|
@ -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…
Reference in New Issue
Block a user