初始化提交

This commit is contained in:
2026-02-03 16:52:44 +08:00
commit d2f9806384
512 changed files with 65167 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
import { util } from '@appium/support';
export const PLATFORM_VERSION = process.env.PLATFORM_VERSION ? process.env.PLATFORM_VERSION : '11.3';
export const DEVICE_NAME = process.env.DEVICE_NAME
|| (util.compareVersions(PLATFORM_VERSION, '>=', '13.0') ? 'iPhone X' : 'iPhone 6');

View File

@@ -0,0 +1,41 @@
import _ from 'lodash';
import { Simctl } from 'node-simctl';
import { retryInterval } from 'asyncbox';
import { killAllSimulators as simKill } from 'appium-ios-simulator';
import { resetTestProcesses } from '../../../lib/utils';
async function killAllSimulators () {
if (process.env.CLOUD) {
return;
}
const simctl = new Simctl();
const allDevices = _.flatMap(_.values(await simctl.getDevices()));
const bootedDevices = allDevices.filter((device) => device.state === 'Booted');
for (const {udid} of bootedDevices) {
// It is necessary to stop the corresponding xcodebuild process before killing
// the simulator, otherwise it will be automatically restarted
await resetTestProcesses(udid, true);
simctl.udid = udid;
await simctl.shutdownDevice();
}
await simKill();
}
async function shutdownSimulator (device) {
// stop XCTest processes if running to avoid unexpected side effects
await resetTestProcesses(device.udid, true);
await device.shutdown();
}
async function deleteDeviceWithRetry (udid) {
const simctl = new Simctl({udid});
try {
await retryInterval(10, 1000, simctl.deleteDevice.bind(simctl));
} catch {}
}
export { killAllSimulators, shutdownSimulator, deleteDeviceWithRetry };

View File

@@ -0,0 +1,129 @@
import { Simctl } from 'node-simctl';
import { getVersion } from 'appium-xcode';
import { getSimulator } from 'appium-ios-simulator';
import { killAllSimulators, shutdownSimulator } from './helpers/simulator';
import { SubProcess } from 'teen_process';
import { PLATFORM_VERSION, DEVICE_NAME } from './desired';
import { retryInterval } from 'asyncbox';
import { WebDriverAgent } from '../../lib/webdriveragent';
import axios from 'axios';
const MOCHA_TIMEOUT_MS = 60 * 1000 * 5;
const SIM_DEVICE_NAME = 'webDriverAgentTest';
const SIM_STARTUP_TIMEOUT_MS = MOCHA_TIMEOUT_MS;
let testUrl = 'http://localhost:8100/tree';
function getStartOpts (device) {
return {
device,
platformVersion: PLATFORM_VERSION,
host: 'localhost',
port: 8100,
realDevice: false,
showXcodeLog: true,
wdaLaunchTimeout: 60 * 3 * 1000,
};
}
describe('WebDriverAgent', function () {
this.timeout(MOCHA_TIMEOUT_MS);
let chai;
let xcodeVersion;
before(async function () {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.should();
chai.use(chaiAsPromised.default);
// Don't do these tests on Sauce Labs
if (process.env.CLOUD) {
this.skip();
}
xcodeVersion = await getVersion(true);
});
describe('with fresh sim', function () {
let device;
let simctl;
before(async function () {
simctl = new Simctl();
simctl.udid = await simctl.createDevice(
SIM_DEVICE_NAME,
DEVICE_NAME,
PLATFORM_VERSION
);
device = await getSimulator(simctl.udid);
// Prebuild WDA
const wda = new WebDriverAgent(xcodeVersion, {
iosSdkVersion: PLATFORM_VERSION,
platformVersion: PLATFORM_VERSION,
showXcodeLog: true,
device,
});
await wda.xcodebuild.start(true);
});
after(async function () {
this.timeout(MOCHA_TIMEOUT_MS);
await shutdownSimulator(device);
await simctl.deleteDevice();
});
describe('with running sim', function () {
this.timeout(6 * 60 * 1000);
beforeEach(async function () {
await killAllSimulators();
await device.run({startupTimeout: SIM_STARTUP_TIMEOUT_MS});
});
afterEach(async function () {
try {
await retryInterval(5, 1000, async function () {
await shutdownSimulator(device);
});
} catch {}
});
it('should launch agent on a sim', async function () {
const agent = new WebDriverAgent(xcodeVersion, getStartOpts(device));
await agent.launch('sessionId');
await axios({url: testUrl}).should.be.eventually.rejected;
await agent.quit();
});
it('should fail if xcodebuild fails', async function () {
// short timeout
this.timeout(35 * 1000);
const agent = new WebDriverAgent(xcodeVersion, getStartOpts(device));
agent.xcodebuild.createSubProcess = async function () {
let args = [
'-workspace',
`${this.agentPath}dfgs`,
// '-scheme',
// 'XCTUITestRunner',
// '-destination',
// `id=${this.device.udid}`,
// 'test'
];
return new SubProcess('xcodebuild', args, {detached: true});
};
await agent.launch('sessionId')
.should.eventually.be.rejectedWith('xcodebuild failed');
await agent.quit();
});
});
});
});