Skip to content

Commit

Permalink
Merge branch 'master' into tvos-ios17-workaround2
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa authored Oct 23, 2024
2 parents c765bdc + c5c9aef commit aba9e03
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 23 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ jobs:
name: Docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Use Node.js LTS
uses: actions/setup-node@v3
with:
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
## [7.28.1](https://github.com/appium/appium-xcuitest-driver/compare/v7.28.0...v7.28.1) (2024-10-18)

### Bug Fixes

* bump WDA to fix transient overlay windows handling when respectSystemAlerts is enabled ([#2482](https://github.com/appium/appium-xcuitest-driver/issues/2482)) ([e504a6d](https://github.com/appium/appium-xcuitest-driver/commit/e504a6dc6fca4a4d5480a4a37d47b2f26cdee243))

## [7.28.0](https://github.com/appium/appium-xcuitest-driver/compare/v7.27.1...v7.28.0) (2024-10-17)

### Features

* Add 'simulatorLogLevel' capability ([#2479](https://github.com/appium/appium-xcuitest-driver/issues/2479)) ([b75f5ec](https://github.com/appium/appium-xcuitest-driver/commit/b75f5ecbc87d2245a330e043b8ca5aac96f8cac1))

## [7.27.1](https://github.com/appium/appium-xcuitest-driver/compare/v7.27.0...v7.27.1) (2024-10-09)

### Bug Fixes

* use lipo -info instead of file for architecture detection ([#2478](https://github.com/appium/appium-xcuitest-driver/issues/2478)) ([993aa3a](https://github.com/appium/appium-xcuitest-driver/commit/993aa3a13fe257a636293b78aa5fa757601dcc09))

## [7.27.0](https://github.com/appium/appium-xcuitest-driver/compare/v7.26.4...v7.27.0) (2024-09-25)

### Features

* build-wda script parameters ([#2475](https://github.com/appium/appium-xcuitest-driver/issues/2475)) ([b8bdfad](https://github.com/appium/appium-xcuitest-driver/commit/b8bdfad3c86efd2d351e99fd53c879d7e6e4b082))

## [7.26.4](https://github.com/appium/appium-xcuitest-driver/compare/v7.26.3...v7.26.4) (2024-09-17)

### Miscellaneous Chores
Expand Down
8 changes: 8 additions & 0 deletions docs/guides/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,11 @@ usually found in the following locations, should they need to be deleted:
$HOME/Library/Logs/CoreSimulator/*
$HOME/Library/Developer/Xcode/DerivedData/*
```

## Frequent `Disconnecting from remote debugger` error in iOS 17

Please try out iOS 17.6 or a newer version which includes [a possible fix by Apple](https://developer.apple.com/documentation/safari-release-notes/safari-17_6-release-notes#Web-Inspector).

Frequent Web Inspector debugger disconnection started since iOS 17.2 (or iOS 17.0), that eventually caused `Disconnecting from remote debugger` error.
It could be improved since iOS 17.6.
Please check [the corresponding pull request](https://github.com/appium/appium-xcuitest-driver/pull/2334) for more details.
1 change: 1 addition & 0 deletions docs/reference/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ about capabilities, refer to the [Appium documentation](https://appium.io/docs/e
|`appium:autoFillPasswords`| It allows you to turn on/off autofill passwords function when text field is foccused. Works only with iOS16.4+ simulators | `true` |
|`appium:permissions`| Allows to set permissions for the specified application bundle on Simulator only. The capability value is expected to be a valid JSON string with `{"<bundleId1>": {"<serviceName1>": "<serviceStatus1>", ...}, ...}` format. Since Xcode SDK 11.4 Apple provides native APIs to interact with application settings. Check the output of `xcrun simctl privacy booted` command to get the list of available permission names. Use `yes`, `no` and `unset` as values in order to `grant`, `revoke` or `reset` the corresponding permission. Below Xcode SDK 11.4 it is required that `applesimutils` package is installed and available in PATH. The list of available service names and statuses can be found at https://github.com/wix/AppleSimulatorUtils. | `{"com.apple.mobilecal": {"calendar": "YES"}}` |
|`appium:iosSimulatorLogsPredicate`|Set the `--predicate` flag in the ios simulator logs|`'process != "locationd" AND process != "DTServiceHub"' AND process != "mobileassetd"`|
|`appium:simulatorLogLevel`|Allows to customize the minimum log level for logs collected from simulators. Possible values are `default` (the default value), `info` and `debug`| `debug` |
|`appium:simulatorPasteboardAutomaticSync`| Handle the `-PasteboardAutomaticSync` flag when simulator process launches. It could improve launching simulator performance not to sync pasteboard with the system when this value is `off`. `on` forces the flag enabled. `system` does not provide the flag to the launching command. `on`, `off`, or `system` is available. They are case insensitive. Defaults to `off` | `system` |
|`appium:simulatorDevicesSetPath`| This capability allows to set an alternative path to the simulator devices set in case you have multiple sets deployed on your local system. Such feature could be useful if you, for example, would like to save disk space on the main system volume. | `/MyVolume/Devices` |
|`appium:safariGlobalPreferences`| Allows changing of Mobile Safari's preferences at the session startup. Check the documentation on arguments of [mobile: updateSafariPreferences](./execute-methods.md#mobile-updatesafaripreferences) extension to get more details on the value type requirements. Only available on real devices since driver version 7.9.0. A new Safari instance must be launched upon test startup for this capability to take effect on real devices. | `{ ShowTabBar: 0, WarnAboutFraudulentWebsites: 0 }` |
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ appium driver run xcuitest <script-name>
|Script Name|Description|
|------------|-----------|
|`open-wda`|Opens the WebDriverAgent project in Xcode|
|`build-wda`|Builds the WebDriverAgent project using the first available iPhone simulator and the latest iOS supported by the current Xcode version|
|`build-wda`|Builds the WebDriverAgent project using the first available iPhone simulator and the latest iOS supported by the current Xcode version by default|
|`build-wda --sdk=17.5 --name="iPhone 15"`|Builds the WebDriverAgent project using the iPhone 15 simulator with iOS 17.5. If `--sdk` and `--name` params are not specified - the latest iOS and the first available iPhone simulator will be used|
6 changes: 3 additions & 3 deletions lib/app-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function verifyApplicationPlatform() {

const executablePath = path.resolve(this.opts.app, await this.appInfosCache.extractExecutableName(this.opts.app));
const [resFile, resUname] = await B.all([
exec('file', [executablePath]),
exec('lipo', ['-info', executablePath]),
exec('uname', ['-m']),
]);
const bundleExecutableInfo = _.trim(resFile.stdout);
Expand All @@ -68,8 +68,8 @@ export async function verifyApplicationPlatform() {
// We cannot run Simulator builds compiled for arm64 on Intel machines
// Rosetta allows only to run Intel ones on arm64
if (
!_.includes(bundleExecutableInfo, `executable ${arch}`) &&
!(isAppleSilicon && _.includes(bundleExecutableInfo, 'executable x86_64'))
!_.includes(bundleExecutableInfo, arch) &&
!(isAppleSilicon && _.includes(bundleExecutableInfo, 'x86_64'))
) {
throw new Error(
`The ${this.opts.bundleId} application does not support the ${arch} Simulator ` +
Expand Down
1 change: 1 addition & 0 deletions lib/commands/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export default {
sim: /** @type {import('appium-ios-simulator').Simulator} */ (this.device),
showLogs: this.opts.showIOSLog,
iosSimulatorLogsPredicate: this.opts.iosSimulatorLogsPredicate,
simulatorLogLevel: this.opts.simulatorLogLevel,
log: this.log,
}),
{
Expand Down
3 changes: 3 additions & 0 deletions lib/desired-caps.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ const desiredCapConstraints = /** @type {const} */ ({
iosSimulatorLogsPredicate: {
isString: true,
},
simulatorLogLevel: {
isString: true,
},
appPushTimeout: {
isNumber: true,
},
Expand Down
33 changes: 28 additions & 5 deletions lib/device-log/ios-simulator-log.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import _ from 'lodash';
import {SubProcess, exec} from 'teen_process';
import {util} from 'appium/support';
import { LineConsumingLog } from './line-consuming-log';
import type { Simulator } from 'appium-ios-simulator';
import type { AppiumLogger } from '@appium/types';

const EXECVP_ERROR_PATTERN = /execvp\(\)/;
const LOG_STREAMING_PROCESS_NAME_PATTERN = /^com\.apple\.xpc\.launchd\.oneshot\.0x[0-f]+\.log$/;

const START_TIMEOUT = 10000;

export interface IOSSimulatorLogOptions {
sim: Simulator;
showLogs?: boolean;
iosSimulatorLogsPredicate?: string;
simulatorLogLevel?: string;
log: AppiumLogger;
}

export class IOSSimulatorLog extends LineConsumingLog {
private readonly sim: Simulator;
private readonly showLogs: boolean;
private readonly predicate?: string;
private readonly logLevel?: string;
private proc: SubProcess | null;

constructor(opts: IOSSimulatorLogOptions) {
super({log: opts.log});
this.sim = opts.sim;
this.showLogs = !!opts.showLogs;
this.predicate = opts.iosSimulatorLogsPredicate;
this.logLevel = opts.simulatorLogLevel;
this.proc = null;
}

Expand All @@ -41,13 +46,14 @@ export class IOSSimulatorLog extends LineConsumingLog {
if (this.predicate) {
spawnArgs.push('--predicate', this.predicate);
}
if (this.logLevel) {
spawnArgs.push('--level', this.logLevel);
}
this.log.debug(
`Starting log capture for iOS Simulator with udid '${this.sim.udid}' ` + `using simctl`,
`Starting log capture for iOS Simulator with udid '${this.sim.udid}' ` +
`via simctl using the following arguments '${util.quote(spawnArgs)}'`
);
try {
// cleanup existing listeners if the previous session has not been terminated properly
await exec('pkill', ['-f', [this.sim.udid, ...spawnArgs].join(' ')]);
} catch (ign) {}
await this.cleanupObsoleteLogStreams();
try {
this.proc = await this.sim.simctl.spawnSubProcess(spawnArgs);
await this.finishStartingLogCapture();
Expand Down Expand Up @@ -112,6 +118,23 @@ export class IOSSimulatorLog extends LineConsumingLog {
};
await this.proc.start(startDetector, START_TIMEOUT);
}

private async cleanupObsoleteLogStreams(): Promise<void> {
const processes = await this.sim.ps();
const pids = processes
.filter(({name}) => LOG_STREAMING_PROCESS_NAME_PATTERN.test(name))
.map(({pid}) => pid);
if (_.isEmpty(pids)) {
return;
}
try {
await exec('kill', pids.map(String));
} catch (e) {
this.log.warn(
`Cound not terminate one or more obsolete log streams: ${e.stderr || e.message}`
);
}
}
}

export default IOSSimulatorLog;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"xcuitest",
"xctest"
],
"version": "7.26.4",
"version": "7.28.1",
"author": "Appium Contributors",
"license": "Apache-2.0",
"repository": {
Expand Down Expand Up @@ -81,7 +81,7 @@
"appium-ios-device": "^2.7.23",
"appium-ios-simulator": "^6.1.7",
"appium-remote-debugger": "^12.1.1",
"appium-webdriveragent": "^8.9.1",
"appium-webdriveragent": "^8.9.4",
"appium-xcode": "^5.1.4",
"async-lock": "^1.4.0",
"asyncbox": "^3.0.0",
Expand Down
33 changes: 22 additions & 11 deletions scripts/build-wda.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
const {WebDriverAgent} = require('appium-webdriveragent');
const xcode = require('appium-xcode');
const B = require('bluebird');
const {Simctl} = require('node-simctl');
const {getSimulator} = require('appium-ios-simulator');
const {logger} = require('appium/support');

const log = logger.getLogger('WDA');

// TODO: allow passing in all the various build params as CLI args
function parseArgValue(argName) {
const argNamePattern = new RegExp(`^--${argName}\\b`);
for (let i = 1; i < process.argv.length; ++i) {
const arg = process.argv[i];
if (argNamePattern.test(arg)) {
return arg.includes('=') ? arg.split('=')[1] : process.argv[i + 1];
}
}
return null;
}

async function build() {
const [xcodeVersion, platformVersion] = await B.all([
xcode.getVersion(true),
xcode.getMaxIOSSDK(),
]);
const customDevice = parseArgValue('name');
const xcodeVersion = await xcode.getVersion(true);
const platformVersion = parseArgValue('sdk') || (await xcode.getMaxIOSSDK());
const iosDevices = await new Simctl().getDevices(platformVersion, 'iOS');
const verifyDevicePresence = (info) => {
if (!info) {
throw new Error(`Cannot find any available iOS ${platformVersion} Simulator on your system`);
throw new Error(
`Cannot find any available iOS ${platformVersion} ${customDevice ? `${customDevice} ` : ''}simulator on your system. Only the following simulators are available:\n${iosDevices.map((e) => e.name).join('\n')}`,
);
}
return info;
};
const deviceInfo = verifyDevicePresence(
(await new Simctl().getDevices(platformVersion, 'iOS')).find(({name}) =>
name.includes('iPhone'),
),
iosDevices.find(({name}) => name.includes(customDevice || 'iPhone')),
);
const device = await getSimulator(deviceInfo.udid, {
platform: deviceInfo.platform,
Expand All @@ -34,7 +43,9 @@ async function build() {
showXcodeLog: true,
device,
});
log.info(`Building WDA for ${deviceInfo.name} ${platformVersion} Simulator...`);
log.info(
`Building WDA for ${deviceInfo.name} ${platformVersion} with udid '${deviceInfo.udid}' Simulator...`,
);
await wda.xcodebuild.start(true);
}

Expand Down

0 comments on commit aba9e03

Please sign in to comment.