Skip to content

Commit eb3efef

Browse files
Execute map (#73)
* move to executeMethodMap * bump version
1 parent 33e1900 commit eb3efef

File tree

10 files changed

+33438
-22595
lines changed

10 files changed

+33438
-22595
lines changed

.github/workflows/node.js.yml

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ yarn-debug.log*
77
yarn-error.log*
88
lerna-debug.log*
99
lib/
10+
local_appium_home/
1011

1112
# Diagnostic reports (https://nodejs.org/api/report.html)
1213
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

README.md

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,42 +69,23 @@ driver.findElementByAccessibilityId("login").sendKeys('Hello');
6969
```
7070
## Configure Wait timeout in test
7171

72-
WDIO Example
72+
WDIO Example
7373

7474
```
75-
driver.addCommand(
76-
'setWaitPluginTimeout',
77-
command('POST', '/session/:sessionId/waitplugin/timeout', {
78-
command: 'setWaitPluginTimeout',
79-
parameters: [
80-
{
81-
name: 'data',
82-
type: 'object',
83-
description: 'a valid parameter',
84-
required: true,
85-
},
86-
],
87-
})
88-
);
89-
90-
driver.addCommand(
91-
'getWaitTimeout',
92-
command('GET', '/session/:sessionId/waitplugin/getTimeout', {
93-
command: 'getWaitTimeout',
94-
parameters: [],
95-
returns: {
96-
type: 'object',
97-
name: 'timeout',
98-
description: 'Get timeout set',
99-
},
100-
})
101-
);
75+
await driver.executeScript('plugin: setWaitTimeout', [
76+
{
77+
timeout: 1111,
78+
intervalBetweenAttempts: 11,
79+
},
80+
]);
81+
82+
await driver.executeScript('plugin: getWaitTimeout', [])
10283
```
10384

104-
Usage
85+
Java Example
10586

10687
```
107-
await driver.setWaitPluginTimeout({ timeout: 1111, intervalBetweenAttempts: 11 });
88+
driver.executeScript("plugin: setWaitTimeout", ImmutableMap.of("timeout", 1111 , "intervalBetweenAttempts", 11 ));
10889
```
10990

11091
Server logs will be as below:

__tests__/e2e/plugin.spec.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { remote } from 'webdriverio';
2+
import { pluginE2EHarness } from '@appium/plugin-test-support';
3+
import path from 'path';
4+
var chai = require('chai'),
5+
chaiAsPromised = require('chai-as-promised');
6+
7+
chai.use(chaiAsPromised);
8+
// eslint-disable-next-line no-undef
9+
should = chai.should();
10+
let expect = chai.expect;
11+
12+
const APPIUM_HOST = 'localhost';
13+
const FAKE_ARGS = { timeout: 10000, intervalBetweenAttempts: 1000 };
14+
const FAKE_PLUGIN_ARGS = { 'element-wait': FAKE_ARGS };
15+
16+
const THIS_PLUGIN_DIR = path.join(__dirname, '..', '..');
17+
const APPIUM_HOME = path.join(THIS_PLUGIN_DIR, 'local_appium_home');
18+
const FAKE_DRIVER_DIR =
19+
process.env.PLATFORM === 'android' ? 'appium-uiautomator2-driver' : 'appium-xcuitest-driver';
20+
const TEST_HOST = 'localhost';
21+
const TEST_PORT = 4723;
22+
23+
let server;
24+
const WDIO_PARAMS = {
25+
connectionRetryCount: 220000,
26+
hostname: APPIUM_HOST,
27+
port: 4723,
28+
path: '/wd/hub',
29+
};
30+
const androidCaps = {
31+
platformName: 'Android',
32+
'appium:uiautomator2ServerInstallTimeout': '120000',
33+
'appium:automationName': 'UIAutomator2',
34+
'appium:app':
35+
'https://github.com/AppiumTestDistribution/appium-demo/blob/main/VodQA.apk?raw=true',
36+
};
37+
38+
const iOSCaps = {
39+
platformName: 'iOS',
40+
'appium:automationName': 'XCUITest',
41+
'appium:deviceName': 'iPhone 14 Pro',
42+
'appium:platformVersion': '16.2',
43+
'appium:app':
44+
'https://github.com/AppiumTestDistribution/appium-demo/blob/main/vodqa.zip?raw=true',
45+
};
46+
47+
describe('Set Timeout', () => {
48+
describe('with CLI args', () => {
49+
let driver;
50+
pluginE2EHarness({
51+
before,
52+
after,
53+
server,
54+
serverArgs: { basePath: '/wd/hub', plugin: FAKE_PLUGIN_ARGS },
55+
port: TEST_PORT,
56+
host: TEST_HOST,
57+
appiumHome: APPIUM_HOME,
58+
driverName: process.env.PLATFORM === 'android' ? 'uiautomator2' : 'xcuitest',
59+
driverSource: 'npm',
60+
driverSpec: FAKE_DRIVER_DIR,
61+
pluginName: 'element-wait',
62+
pluginSource: 'local',
63+
pluginSpec: '.',
64+
});
65+
beforeEach(async () => {
66+
driver = await remote({
67+
...WDIO_PARAMS,
68+
capabilities: process.env.PLATFORM === 'android' ? androidCaps : iOSCaps,
69+
});
70+
});
71+
it('Should be able to set and get waitPlugin timeout', async () => {
72+
await driver.$('~login').click();
73+
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include(FAKE_ARGS);
74+
await driver.executeScript('plugin: setWaitTimeout', [
75+
{
76+
timeout: 1111,
77+
intervalBetweenAttempts: 11,
78+
},
79+
]);
80+
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include({
81+
timeout: 1111,
82+
intervalBetweenAttempts: 11,
83+
});
84+
});
85+
86+
afterEach(async () => {
87+
await driver.deleteSession();
88+
if (server) await server.close();
89+
});
90+
});
91+
});

__tests__/plugin.spec.js

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { remote } from 'webdriverio';
2-
import { command } from 'webdriver';
32
import { pluginE2EHarness } from '@appium/plugin-test-support';
43
import path from 'path';
54
var chai = require('chai'),
@@ -61,39 +60,17 @@ describe('Set Timeout', () => {
6160
});
6261
beforeEach(async () => {
6362
driver = await remote({ ...WDIO_PARAMS, capabilities });
64-
65-
driver.addCommand(
66-
'setWaitPluginTimeout',
67-
command('POST', '/session/:sessionId/waitplugin/timeout', {
68-
command: 'setWaitPluginTimeout',
69-
parameters: [
70-
{
71-
name: 'data',
72-
type: 'object',
73-
description: 'a valid parameter',
74-
required: true,
75-
},
76-
],
77-
})
78-
);
79-
driver.addCommand(
80-
'getWaitTimeout',
81-
command('GET', '/session/:sessionId/waitplugin/getTimeout', {
82-
command: 'getWaitTimeout',
83-
parameters: [],
84-
returns: {
85-
type: 'object',
86-
name: 'activity',
87-
description: 'Name of the current activity',
88-
},
89-
})
90-
);
9163
});
9264
it('Should be able to set and get waitPlugin timeout', async () => {
9365
await driver.$('id=AlertButton');
94-
expect(await driver.getWaitTimeout()).to.deep.include(FAKE_ARGS);
95-
await driver.setWaitPluginTimeout({ timeout: 1111, intervalBetweenAttempts: 11 });
96-
expect(await driver.getWaitTimeout()).to.deep.include({
66+
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include(FAKE_ARGS);
67+
await driver.executeScript('plugin: setWaitTimeout', [
68+
{
69+
timeout: 1111,
70+
intervalBetweenAttempts: 11,
71+
},
72+
]);
73+
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include({
9774
timeout: 1111,
9875
intervalBetweenAttempts: 11,
9976
});
@@ -129,42 +106,21 @@ describe('Set Timeout', () => {
129106
});
130107
beforeEach(async () => {
131108
driver = await remote({ ...WDIO_PARAMS, capabilities });
132-
133-
driver.addCommand(
134-
'setWaitPluginTimeout',
135-
command('POST', '/session/:sessionId/waitplugin/timeout', {
136-
command: 'setWaitPluginTimeout',
137-
parameters: [
138-
{
139-
name: 'data',
140-
type: 'object',
141-
description: 'a valid parameter',
142-
required: true,
143-
},
144-
],
145-
})
146-
);
147-
driver.addCommand(
148-
'getWaitTimeout',
149-
command('GET', '/session/:sessionId/waitplugin/getTimeout', {
150-
command: 'getWaitTimeout',
151-
parameters: [],
152-
returns: {
153-
type: 'object',
154-
name: 'activity',
155-
description: 'Name of the current activity',
156-
},
157-
})
158-
);
159109
});
110+
160111
it('Should be able to set and get waitPlugin timeout', async () => {
161112
await driver.$('#AlertButton');
162-
expect(await driver.getWaitTimeout()).to.deep.include({
113+
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include({
163114
timeout: 10000,
164115
intervalBetweenAttempts: 500,
165116
});
166-
await driver.setWaitPluginTimeout({ timeout: 1111, intervalBetweenAttempts: 11 });
167-
expect(await driver.getWaitTimeout()).to.deep.include({
117+
await driver.executeScript('plugin: setWaitTimeout', [
118+
{
119+
timeout: 1111,
120+
intervalBetweenAttempts: 11,
121+
},
122+
]);
123+
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include({
168124
timeout: 1111,
169125
intervalBetweenAttempts: 11,
170126
});

azure-pipelines.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
trigger:
2+
- main
3+
4+
jobs:
5+
- job: UnitTest
6+
pool:
7+
vmImage: 'macOS-latest'
8+
9+
steps:
10+
11+
inputs:
12+
versionSpec: '16.x'
13+
14+
- script: |
15+
npm ci
16+
npm test
17+
displayName: 'npm test'
18+
19+
- job: ANDROID
20+
pool:
21+
vmImage: 'macOS-latest'
22+
23+
steps:
24+
25+
inputs:
26+
versionSpec: '16.x'
27+
28+
- script: |
29+
npm ci
30+
displayName: 'npm install'
31+
32+
- bash: |
33+
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-27;google_apis;x86'
34+
displayName: "install Android image"
35+
- script: |
36+
$ANDROID_HOME/emulator/emulator -list-avds
37+
echo '---'
38+
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n test_android_emulator -k 'system-images;android-27;google_apis;x86' --force
39+
echo '---'
40+
$ANDROID_HOME/emulator/emulator -list-avds
41+
displayName: "create AVD"
42+
- script: |
43+
$ANDROID_HOME/platform-tools/adb devices
44+
echo '---'
45+
nohup $ANDROID_HOME/emulator/emulator -avd test_android_emulator -no-snapshot > /dev/null 2>&1 & $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
46+
echo '---'
47+
$ANDROID_HOME/platform-tools/adb devices
48+
displayName: "start Android emulator"
49+
- script: |
50+
PLATFORM='android' npm run test-e2e
51+
displayName: "Android Integration Test"
52+
- job: iOS
53+
pool:
54+
vmImage: 'macOS-latest'
55+
56+
steps:
57+
58+
inputs:
59+
versionSpec: '16.x'
60+
61+
- script: |
62+
npm ci
63+
displayName: 'npm install'
64+
65+
- script: |
66+
xcrun simctl list
67+
PLATFORM='ios' npm run test-e2e
68+
displayName: "iOS Integration Test"

0 commit comments

Comments
 (0)