Skip to content

Commit 87c7d71

Browse files
committed
expose method map to override timeout at test level
1 parent 89503f8 commit 87c7d71

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

__tests__/e2e.spec.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { remote } from 'webdriverio';
1+
import { remote, command } from 'webdriverio';
22

33
const APPIUM_HOST = '127.0.0.1';
44
const APPIUM_PORT = 31337;
@@ -22,6 +22,7 @@ describe('Plugin Test', () => {
2222
});
2323

2424
it('Vertical swipe test', async () => {
25+
await driver.setWaitPluginTimeout('data', { timeout: 1111, intervalBetweenAttempts: 11 });
2526
await driver.$('~username').click();
2627
await driver.$('~username').clearValue();
2728
await driver.$('~username').setValue('admin');
@@ -30,6 +31,21 @@ describe('Plugin Test', () => {
3031
});
3132

3233
afterEach(async () => {
33-
// await driver.deleteSession();
34+
await driver.deleteSession();
3435
});
3536
});
37+
38+
driver.addCommand(
39+
'setWaitPluginTimeout',
40+
command('POST', '/session/:sessionId/waitplugin/timeout', {
41+
command: 'setWaitPluginTimeout',
42+
parameters: [
43+
{
44+
name: 'data',
45+
type: 'object',
46+
description: 'a valid parameter',
47+
required: true,
48+
},
49+
],
50+
})
51+
);

src/element.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export async function find(driver, args) {
4343
}
4444
}
4545

46+
export async function setWait(driver, args) {
47+
_setTimeout(args[0], driver.sessionId, true);
48+
}
49+
4650
export async function elementEnabled(driver, el) {
4751
let timeoutProp = _getTimeout(driver.sessionId);
4852
const predicate = async () => {
@@ -114,12 +118,16 @@ function sessionInfo(driver, strategy, selector) {
114118
}
115119
}
116120

117-
function _setTimeout(elementWaitProps, session) {
121+
function _setTimeout(elementWaitProps, session, overrideTimeout = false) {
122+
if (overrideTimeout && map.has(session)) {
123+
map.delete(session);
124+
}
118125
if (!map.has(session)) {
119126
log.info(`Timeout properties not set for session ${session}, trying to set one`);
120127
let defaultTimeoutProp = {
121128
timeout: 10000,
122129
intervalBetweenAttempts: 500,
130+
overrideTimeout,
123131
};
124132
if (
125133
elementWaitProps.timeout != undefined &&

src/plugin.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
import BasePlugin from '@appium/base-plugin';
2-
import { find, elementEnabled } from './element';
2+
import { find, elementEnabled, setWait } from './element';
33
import log from './logger';
44
export default class WaitCommandPlugin extends BasePlugin {
5+
// this plugin supports a non-standard 'compare images' command
6+
static newMethodMap = {
7+
'/session/:sessionId/waitplugin/timeout': {
8+
POST: {
9+
command: 'setWait',
10+
payloadParams: { required: ['data'] },
11+
neverProxy: true,
12+
},
13+
},
14+
};
15+
16+
async setWait(next, driver, ...args) {
17+
await setWait(driver, args);
18+
}
19+
520
async findElement(next, driver, ...args) {
621
let commandLineArgs = this.cliArgs;
722
await find(driver, args, commandLineArgs);

0 commit comments

Comments
 (0)