Skip to content

Commit

Permalink
chore: Set the default webview connect timeout (#2438)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jul 31, 2024
1 parent 7eb7e7d commit a63856d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 28 deletions.
6 changes: 2 additions & 4 deletions docs/reference/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ about capabilities, refer to the [Appium documentation](https://appium.io/docs/e
|`appium:iosSimulatorLogsPredicate`|Set the `--predicate` flag in the ios simulator logs|`'process != "locationd" AND process != "DTServiceHub"' AND process != "mobileassetd"`|
|`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:webkitResponseTimeout`| (Real device only) Set the time, in ms, to wait for a response from WebKit in a Safari session. Defaults to `5000` | `10000`|
|`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 }` |

### Web Context
Expand All @@ -138,9 +137,8 @@ about capabilities, refer to the [Appium documentation](https://appium.io/docs/e
|`appium:safariAllowPopups`| Allow javascript to open new windows in Safari. Default keeps the current setting. Only available on real devices since driver version 7.9.0. A new Safari instance must be launched upon test startup on real devices for this capability to take effect. |`true` or `false`|
|`appium:safariIgnoreFraudWarning`| Prevent Safari from showing a fraudulent website warning. Default keeps the current setting. Only available on real devices since driver version 7.9.0. A new Safari instance must be launched upon test startup on real devices for this capability to take effect. |`true` or `false`|
|`appium:safariOpenLinksInBackground`| Whether Safari should allow links to open in new windows. Default keeps the current sim setting. Only available on real devices since driver version 7.9.0. A new Safari instance must be launched upon test startup on real devices for this capability to take effect. |`true` or `false`|
|`appium:webviewConnectRetries`| The maximum number of retries before giving up on web view pages detection. The delay between each retry is 500ms, which creates a minimum 10s of wait with the default retries amount of `20`. This capability has a priority over `appium:webviewConnectTimeout` one. |`10`|
|`appium:webviewConnectTimeout`| The time to wait, in `ms`, for the presence of webviews in MobileSafari or hybrid apps. If this capability is set and `appium:webviewConnectRetries` is not provided explicitly then the amount of connection retries will be adjusted automatically in order to satisfy the given timeout. |`5000`|
|`appium:webkitResponseTimeout`| (Real device only) Set the time, in ms, to wait for a response from WebKit in a Safari session. Defaults to `5000`|`10000`|
|`appium:webviewConnectRetries`| The maximum number of retries before giving up on web view pages detection. Under the hood the remote debugger waits until webkit delivers the list of connected applications pages (`_rpc_applicationSentListing`). The delay between each retry is 500ms, which creates a minimum 10s of waiting time with the default retries amount of `20`. |`10`|
|`appium:webviewConnectTimeout`| The time to wait, in `ms`, for the presence of webviews in MobileSafari or hybrid apps. Under the hood the remote debugger waits until webkit delivers the list of connected applications (`_rpc_reportConnectedApplicationList`) after sending a request for setting the connection key (`_rpc_reportIdentifier`). For better stability it might be necessary to increase this value if you run tests on Simulator and the host does not perform fast enough, for example in the continuous integration environment. `5000` ms by default. |`10000`|
|`appium:enableAsyncExecuteFromHttps`| Capability to allow simulators to execute asynchronous JavaScript on pages using HTTPS. Defaults to `false` | `true` or `false` |
|`appium:fullContextList` | Returns the detailed information on contexts for the [Get Contexts](https://appium.io/docs/en/latest/guides/context/) command. If this capability is enabled, then each item in the returned contexts list would additionally include WebView title, full URL and the bundle identifier. Defaults to `false`. | `true` or `false` |
|`appium:enablePerformanceLogging`| Enable Safari's performance logging (default `false`)| `true`, `false`|
Expand Down
26 changes: 6 additions & 20 deletions lib/commands/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@ import _ from 'lodash';
const NATIVE_WIN = 'NATIVE_APP';
const WEBVIEW_WIN = 'WEBVIEW';
const WEBVIEW_BASE = `${WEBVIEW_WIN}_`;
const DEFAULT_REMOTE_DEBUGGER_CONNECT_TIMEOUT_MS = 5000;

/**
* Type guard for a non-empty array.
*
* @remarks Does not support subclasses of `Array` nor tuples.
* @template T
* @param {T[]} [value]
* @returns {value is [T, ...T[]]}
*/
function isNonEmptyArray(value) {
return Boolean(value?.length);
}

const extensions = {
/**
Expand Down Expand Up @@ -79,15 +69,9 @@ const extensions = {

if (!this.remote) {
await this.connectToRemoteDebugger();
// @ts-ignore TS does not understand property mutation
if (!this.remote.appIdKey) {
// @ts-ignore TS does not understand property mutation
await this.remote.setConnectionKey();
}
}
/** @type {number|undefined} */
const maxRetriesCount = this.opts.webviewConnectRetries
?? (this.opts.webviewConnectTimeout ? Math.ceil(this.opts.webviewConnectTimeout / 500.0) : undefined);
const maxRetriesCount = this.opts.webviewConnectRetries;
try {
const pageArray = await (/** @type {RemoteDebugger} */ (this.remote)).selectApp(
useUrl ? this.getCurrentUrl() : undefined,
Expand All @@ -114,7 +98,7 @@ const extensions = {
this.remote.on(RemoteDebugger.EVENT_PAGE_CHANGE, this.onPageChange.bind(this));
// @ts-ignore static is fine
this.remote.on(RemoteDebugger.EVENT_FRAMES_DETACHED, () => {
if (isNonEmptyArray(this.curWebFrames)) {
if (!_.isEmpty(this.curWebFrames)) {
const curWebFrames = this.curWebFrames;
this.log.debug(
`Clearing ${util.pluralize('frame', curWebFrames.length, true)}: ${curWebFrames.join(
Expand All @@ -125,7 +109,9 @@ const extensions = {
this.curWebFrames = [];
});

await this.remote.connect(this.opts.webviewConnectTimeout);
await this.remote.connect(
this.opts.webviewConnectTimeout ?? DEFAULT_REMOTE_DEBUGGER_CONNECT_TIMEOUT_MS
);
},

/**
Expand Down
3 changes: 0 additions & 3 deletions lib/desired-caps.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ const desiredCapConstraints = /** @type {const} */ ({
customSSLCert: {
isString: true,
},
webkitResponseTimeout: {
isNumber: true,
},
remoteDebugProxy: {
isString: true,
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"appium-idb": "^1.6.13",
"appium-ios-device": "^2.5.4",
"appium-ios-simulator": "^6.1.7",
"appium-remote-debugger": "^11.5.3",
"appium-remote-debugger": "^11.5.5",
"appium-webdriveragent": "^8.7.8",
"appium-xcode": "^5.1.4",
"async-lock": "^1.4.0",
Expand Down

0 comments on commit a63856d

Please sign in to comment.