Skip to content

Commit 254bc04

Browse files
feat: Make command exports more straightforward (#2646)
1 parent a66b362 commit 254bc04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+6082
-5986
lines changed

lib/commands/active-app-info.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Returns information about the active application.
3+
*
4+
* @returns {Promise<import('./types').ActiveAppInfo>} Active app information
5+
* @throws {Error} if an error raised by command
6+
* @this {import('../driver').XCUITestDriver}
7+
*/
8+
export async function mobileGetActiveAppInfo() {
9+
return /** @type {import('./types').ActiveAppInfo} */ (
10+
await this.proxyCommand('/wda/activeAppInfo', 'GET')
11+
);
12+
}

lib/commands/activeAppInfo.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

lib/commands/alert.js

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,71 @@
1+
/**
2+
* @this {XCUITestDriver}
3+
*/
4+
export async function getAlertText() {
5+
return /** @type {string|null} */ (await this.proxyCommand('/alert/text', 'GET'));
6+
}
7+
8+
/**
9+
* @param {string} value
10+
* @this {XCUITestDriver}
11+
* @returns {Promise<void>}
12+
*/
13+
export async function setAlertText(value) {
14+
await this.proxyCommand('/alert/text', 'POST', {value});
15+
}
16+
17+
/**
18+
* @param { {buttonLabel?: string} } opts
19+
* @returns {Promise<void>}
20+
* @this {XCUITestDriver}
21+
*/
22+
export async function postAcceptAlert(opts = {}) {
23+
await this.proxyCommand('/alert/accept', 'POST', toAlertParams(opts));
24+
}
25+
26+
/**
27+
* @param { {buttonLabel?: string} } opts
28+
* @returns {Promise<void>}
29+
* @this {XCUITestDriver}
30+
*/
31+
export async function postDismissAlert(opts = {}) {
32+
await this.proxyCommand('/alert/dismiss', 'POST', toAlertParams(opts));
33+
}
34+
35+
/**
36+
* @internal
37+
* @this {XCUITestDriver}
38+
* @returns {Promise<string[]>} The list of button labels
39+
*/
40+
export async function getAlertButtons() {
41+
return /** @type {string[]} */ (await this.proxyCommand('/wda/alert/buttons', 'GET'));
42+
}
43+
44+
/**
45+
* Tries to apply the given action to the currently visible alert.
46+
*
47+
* @param {AlertAction} action - The actual action to apply.
48+
* @param {string} [buttonLabel] - The name of the button used to perform the chosen alert action. Only makes sense if the action is `accept` or `dismiss`.
49+
* @returns {Promise<string[]|void>} If `action` is `getButtons`, a list of alert button labelsp; otherwise nothing.
50+
* @remarks This should really be separate commands.
51+
* @this {XCUITestDriver}
52+
*/
53+
export async function mobileHandleAlert(action, buttonLabel) {
54+
switch (action) {
55+
case 'accept':
56+
return await this.postAcceptAlert({buttonLabel});
57+
case 'dismiss':
58+
return await this.postDismissAlert({buttonLabel});
59+
case 'getButtons':
60+
return await this.getAlertButtons();
61+
default:
62+
throw new Error(
63+
`The 'action' value should be either 'accept', 'dismiss' or 'getButtons'. ` +
64+
`'${action}' is provided instead.`,
65+
);
66+
}
67+
}
68+
169
/**
270
*
371
* @param { {buttonLabel?: string} } opts
@@ -11,71 +79,6 @@ function toAlertParams(opts = {}) {
1179
return params;
1280
}
1381

14-
export default {
15-
/**
16-
* @this {XCUITestDriver}
17-
*/
18-
async getAlertText() {
19-
return /** @type {string|null} */ (await this.proxyCommand('/alert/text', 'GET'));
20-
},
21-
/**
22-
* @param {string} value
23-
* @this {XCUITestDriver}
24-
* @returns {Promise<void>}
25-
*/
26-
async setAlertText(value) {
27-
await this.proxyCommand('/alert/text', 'POST', {value});
28-
},
29-
/**
30-
* @param { {buttonLabel?: string} } opts
31-
* @returns {Promise<void>}
32-
* @this {XCUITestDriver}
33-
*/
34-
async postAcceptAlert(opts = {}) {
35-
await this.proxyCommand('/alert/accept', 'POST', toAlertParams(opts));
36-
},
37-
/**
38-
* @param { {buttonLabel?: string} } opts
39-
* @returns {Promise<void>}
40-
* @this {XCUITestDriver}
41-
*/
42-
async postDismissAlert(opts = {}) {
43-
await this.proxyCommand('/alert/dismiss', 'POST', toAlertParams(opts));
44-
},
45-
/**
46-
* @internal
47-
* @this {XCUITestDriver}
48-
* @returns {Promise<string[]>} The list of button labels
49-
*/
50-
async getAlertButtons() {
51-
return /** @type {string[]} */ (await this.proxyCommand('/wda/alert/buttons', 'GET'));
52-
},
53-
/**
54-
* Tries to apply the given action to the currently visible alert.
55-
*
56-
* @param {AlertAction} action - The actual action to apply.
57-
* @param {string} [buttonLabel] - The name of the button used to perform the chosen alert action. Only makes sense if the action is `accept` or `dismiss`.
58-
* @returns {Promise<string[]|void>} If `action` is `getButtons`, a list of alert button labelsp; otherwise nothing.
59-
* @remarks This should really be separate commands.
60-
* @this {XCUITestDriver}
61-
*/
62-
async mobileHandleAlert(action, buttonLabel) {
63-
switch (action) {
64-
case 'accept':
65-
return await this.postAcceptAlert({buttonLabel});
66-
case 'dismiss':
67-
return await this.postDismissAlert({buttonLabel});
68-
case 'getButtons':
69-
return await this.getAlertButtons();
70-
default:
71-
throw new Error(
72-
`The 'action' value should be either 'accept', 'dismiss' or 'getButtons'. ` +
73-
`'${action}' is provided instead.`,
74-
);
75-
}
76-
},
77-
};
78-
7982
/**
8083
* @typedef {'accept'|'dismiss'|'getButtons'} AlertAction
8184
*/

0 commit comments

Comments
 (0)