2021-04-01 16:35:26 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import type { AndroidDevice } from '../../index';
|
2021-05-08 17:45:04 -07:00
|
|
|
import { CommonArgs, baseTest } from '../config/baseTest';
|
2021-04-29 11:11:32 -07:00
|
|
|
import * as folio from 'folio';
|
2021-04-05 13:23:49 -07:00
|
|
|
export { expect } from 'folio';
|
2021-04-01 16:35:26 -07:00
|
|
|
|
2021-04-29 11:11:32 -07:00
|
|
|
type AndroidTestArgs = {
|
2021-04-01 16:35:26 -07:00
|
|
|
androidDevice: AndroidDevice;
|
|
|
|
};
|
|
|
|
|
2021-04-29 11:11:32 -07:00
|
|
|
export class AndroidEnv {
|
|
|
|
protected _device?: AndroidDevice;
|
|
|
|
protected _browserVersion: string;
|
2021-04-30 10:19:37 -07:00
|
|
|
protected _browserMajorVersion: number;
|
2021-04-29 11:11:32 -07:00
|
|
|
|
2021-04-30 13:26:13 -07:00
|
|
|
async beforeAll(args: CommonArgs, workerInfo: folio.WorkerInfo) {
|
2021-04-29 11:11:32 -07:00
|
|
|
this._device = (await args.playwright._android.devices())[0];
|
|
|
|
await this._device.shell('am force-stop org.chromium.webview_shell');
|
|
|
|
await this._device.shell('am force-stop com.android.chrome');
|
|
|
|
this._browserVersion = (await this._device.shell('dumpsys package com.android.chrome'))
|
|
|
|
.toString('utf8')
|
|
|
|
.split('\n')
|
|
|
|
.find(line => line.includes('versionName='))
|
|
|
|
.trim()
|
|
|
|
.split('=')[1];
|
2021-04-30 10:19:37 -07:00
|
|
|
this._browserMajorVersion = Number(this._browserVersion.split('.')[0]);
|
2021-04-29 11:11:32 -07:00
|
|
|
this._device.setDefaultTimeout(90000);
|
|
|
|
}
|
|
|
|
|
|
|
|
async beforeEach({}, testInfo: folio.TestInfo): Promise<AndroidTestArgs> {
|
|
|
|
testInfo.data.platform = 'Android';
|
|
|
|
testInfo.data.headful = true;
|
|
|
|
testInfo.data.browserVersion = this._browserVersion;
|
|
|
|
return {
|
|
|
|
androidDevice: this._device!,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async afterAll({}, workerInfo: folio.WorkerInfo) {
|
|
|
|
if (this._device)
|
|
|
|
await this._device.close();
|
|
|
|
this._device = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const androidTest = baseTest.extend(new AndroidEnv());
|