mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 19:04:43 +03:00
chore: fix Android tests (#12325)
This commit is contained in:
parent
71edad327b
commit
0b55950d6a
1
.github/workflows/tests_fyi.yml
vendored
1
.github/workflows/tests_fyi.yml
vendored
@ -48,6 +48,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
shard: [1, 2]
|
||||
# use mac build for emulator hardware accelerator
|
||||
runs-on: macos-11
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
@ -18,9 +18,11 @@ import debug from 'debug';
|
||||
import * as types from '../types';
|
||||
import { EventEmitter } from 'events';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import * as stream from 'stream';
|
||||
import * as ws from 'ws';
|
||||
import { createGuid, makeWaitForNextTask } from '../../utils/utils';
|
||||
import { createGuid, makeWaitForNextTask, removeFolders } from '../../utils/utils';
|
||||
import { BrowserOptions, BrowserProcess, PlaywrightOptions } from '../browser';
|
||||
import { BrowserContext, validateBrowserContextOptions } from '../browserContext';
|
||||
import { ProgressController } from '../progress';
|
||||
@ -28,11 +30,13 @@ import { CRBrowser } from '../chromium/crBrowser';
|
||||
import { helper } from '../helper';
|
||||
import { PipeTransport } from '../../protocol/transport';
|
||||
import { RecentLogsCollector } from '../../utils/debugLogger';
|
||||
import { gracefullyCloseSet } from '../../utils/processLauncher';
|
||||
import { TimeoutSettings } from '../../utils/timeoutSettings';
|
||||
import { AndroidWebView } from '../../protocol/channels';
|
||||
import { CRPage } from '../chromium/crPage';
|
||||
import { SdkObject, internalCallMetadata } from '../instrumentation';
|
||||
|
||||
const ARTIFACTS_FOLDER = path.join(os.tmpdir(), 'playwright-artifacts-');
|
||||
|
||||
export interface Backend {
|
||||
devices(): Promise<DeviceBackend[]>;
|
||||
}
|
||||
@ -256,15 +260,26 @@ export class AndroidDevice extends SdkObject {
|
||||
await androidBrowser._init();
|
||||
this._browserConnections.add(androidBrowser);
|
||||
|
||||
const artifactsDir = await fs.promises.mkdtemp(ARTIFACTS_FOLDER);
|
||||
const cleanupArtifactsDir = async () => {
|
||||
const errors = await removeFolders([artifactsDir]);
|
||||
for (let i = 0; i < (errors || []).length; ++i)
|
||||
debug('pw:android')(`exception while removing ${artifactsDir}: ${errors[i]}`);
|
||||
};
|
||||
gracefullyCloseSet.add(cleanupArtifactsDir);
|
||||
socket.on('close', async () => {
|
||||
gracefullyCloseSet.delete(cleanupArtifactsDir);
|
||||
cleanupArtifactsDir().catch(e => debug('pw:android')(`could not cleanup artifacts dir: ${e}`));
|
||||
});
|
||||
const browserOptions: BrowserOptions = {
|
||||
...this._android._playwrightOptions,
|
||||
name: 'clank',
|
||||
isChromium: true,
|
||||
slowMo: 0,
|
||||
persistent: { ...options, noDefaultViewport: true },
|
||||
artifactsDir: '',
|
||||
downloadsPath: '',
|
||||
tracesDir: '',
|
||||
artifactsDir,
|
||||
downloadsPath: artifactsDir,
|
||||
tracesDir: artifactsDir,
|
||||
browserProcess: new ClankBrowserProcess(androidBrowser),
|
||||
proxy: options.proxy,
|
||||
protocolLogger: helper.debugProtocolLogger(),
|
||||
@ -278,14 +293,6 @@ export class AndroidDevice extends SdkObject {
|
||||
await controller.run(async progress => {
|
||||
await defaultContext._loadDefaultContextAsIs(progress);
|
||||
});
|
||||
{
|
||||
// TODO: remove after rolling to r838157
|
||||
// Force page scale factor update.
|
||||
const page = defaultContext.pages()[0];
|
||||
const crPage = page._delegate as CRPage;
|
||||
await crPage._mainFrameSession._client.send('Emulation.setDeviceMetricsOverride', { mobile: false, width: 0, height: 0, deviceScaleFactor: 0 });
|
||||
await crPage._mainFrameSession._client.send('Emulation.clearDeviceMetricsOverride', {});
|
||||
}
|
||||
return defaultContext;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ echo Installing emulator...
|
||||
yes | ${ANDROID_HOME}/tools/bin/sdkmanager --install platform-tools emulator
|
||||
|
||||
echo Installing platform SDK...
|
||||
yes | ${ANDROID_HOME}/tools/bin/sdkmanager --install "platforms;android-31"
|
||||
yes | ${ANDROID_HOME}/tools/bin/sdkmanager --install "platforms;android-32"
|
||||
|
||||
echo Starting ADB...
|
||||
${ANDROID_HOME}/platform-tools/adb devices
|
||||
|
@ -8,7 +8,7 @@ if [[ -z "${ANDROID_HOME}" ]]; then
|
||||
export ANDROID_SDK_ROOT=${SDKDIR}
|
||||
fi
|
||||
|
||||
${ANDROID_HOME}/tools/bin/avdmanager delete avd --name android31 || true
|
||||
echo "y" | ${ANDROID_HOME}/tools/bin/sdkmanager --install "system-images;android-31;google_apis;x86_64"
|
||||
echo "no" | ${ANDROID_HOME}/tools/bin/avdmanager create avd --force --name android31 --device "Nexus 5X" --package "system-images;android-31;google_apis;x86_64"
|
||||
${ANDROID_HOME}/tools/bin/avdmanager delete avd --name android32 || true
|
||||
echo "y" | ${ANDROID_HOME}/tools/bin/sdkmanager --install "system-images;android-32;google_apis;x86_64"
|
||||
echo "no" | ${ANDROID_HOME}/tools/bin/avdmanager create avd --force --name android32 --device "Nexus 5X" --package "system-images;android-32;google_apis;x86_64"
|
||||
${ANDROID_HOME}/emulator/emulator -list-avds
|
||||
|
@ -11,8 +11,13 @@ fi
|
||||
echo "Killing previous emulators"
|
||||
${ANDROID_HOME}/platform-tools/adb devices | grep emulator | cut -f1 | while read line; do ${ANDROID_HOME}/platform-tools/adb -s $line emu kill; done
|
||||
|
||||
EMULATOR_GPU="host"
|
||||
if [[ -n "${GITHUB_ACTIONS}" ]]; then
|
||||
EMULATOR_GPU="swiftshader_indirect"
|
||||
fi
|
||||
|
||||
echo "Starting emulator"
|
||||
nohup ${ANDROID_HOME}/emulator/emulator -avd android31 -no-audio -no-window -gpu swiftshader &
|
||||
nohup ${ANDROID_HOME}/emulator/emulator -avd android32 -no-audio -no-window -gpu ${EMULATOR_GPU} -no-boot-anim &
|
||||
${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