|
1 |
| -import { main as startAppium } from 'appium'; |
| 1 | +import { remote } from 'webdriverio'; |
| 2 | +import { command } from 'webdriver'; |
| 3 | +import { pluginE2EHarness } from 'appium/test'; |
| 4 | +import path from 'path'; |
2 | 5 | var chai = require('chai'),
|
3 | 6 | // eslint-disable-next-line no-unused-vars
|
4 | 7 | should = chai.should();
|
| 8 | +let expect = chai.expect; |
5 | 9 | import axios from 'axios';
|
6 | 10 |
|
7 | 11 | const APPIUM_HOST = 'localhost';
|
8 |
| -const FAKE_ARGS = { sillyWebServerPort: 1234, host: 'hey' }; |
9 |
| -const FAKE_PLUGIN_ARGS = { fake: FAKE_ARGS }; |
| 12 | +const FAKE_ARGS = { timeout: 10000, intervalBetweenAttempts: 1000 }; |
| 13 | +const FAKE_PLUGIN_ARGS = { 'element-wait': FAKE_ARGS }; |
| 14 | + |
| 15 | +const THIS_PLUGIN_DIR = path.join(__dirname, '..', '..'); |
| 16 | +const APPIUM_HOME = path.join(THIS_PLUGIN_DIR, 'local_appium_home'); |
| 17 | +const FAKE_DRIVER_DIR = '@appium/fake-driver'; |
| 18 | +const TEST_HOST = 'localhost'; |
| 19 | +const TEST_PORT = 4723; |
| 20 | +const TEST_FAKE_APP = path.join( |
| 21 | + APPIUM_HOME, |
| 22 | + 'node_modules', |
| 23 | + '@appium', |
| 24 | + 'fake-driver', |
| 25 | + 'test', |
| 26 | + 'fixtures', |
| 27 | + 'app.xml' |
| 28 | +); |
10 | 29 | let server;
|
11 |
| -describe('Plugin Test', () => { |
12 |
| - beforeEach('Start Server', async () => { |
13 |
| - const port = '4723'; |
14 |
| - const baseArgs = { |
15 |
| - port, |
16 |
| - address: APPIUM_HOST, |
17 |
| - usePlugins: ['element-wait'], |
18 |
| - }; |
19 |
| - const args = { ...baseArgs, plugin: FAKE_PLUGIN_ARGS }; |
20 |
| - server = await startAppium(args); |
21 |
| - }); |
22 |
| - it('Basic Plugin test', async () => { |
23 |
| - const res = { fake: 'fakeResponse' }; |
24 |
| - (await axios.post('http://localhost:4723/fake')).data.should.eql(res); |
| 30 | +const WDIO_PARAMS = { |
| 31 | + connectionRetryCount: 0, |
| 32 | + hostname: APPIUM_HOST, |
| 33 | + port: 4723, |
| 34 | + path: '/wd/hub', |
| 35 | +}; |
| 36 | +const capabilities = { |
| 37 | + platformName: 'Fake', |
| 38 | + 'appium:automationName': 'Fake', |
| 39 | + 'appium:app': TEST_FAKE_APP, |
| 40 | +}; |
| 41 | +describe('Set Timeout', () => { |
| 42 | + describe('with CLI args', () => { |
| 43 | + let driver; |
| 44 | + pluginE2EHarness({ |
| 45 | + before, |
| 46 | + after, |
| 47 | + server, |
| 48 | + serverArgs: { basePath: '/wd/hub', plugin: FAKE_PLUGIN_ARGS }, |
| 49 | + port: TEST_PORT, |
| 50 | + host: TEST_HOST, |
| 51 | + appiumHome: APPIUM_HOME, |
| 52 | + driverName: 'fake', |
| 53 | + driverSource: 'npm', |
| 54 | + driverSpec: FAKE_DRIVER_DIR, |
| 55 | + pluginName: 'element-wait', |
| 56 | + pluginSource: 'local', |
| 57 | + pluginSpec: '.', |
| 58 | + }); |
| 59 | + beforeEach(async () => { |
| 60 | + driver = await remote({ ...WDIO_PARAMS, capabilities }); |
| 61 | + |
| 62 | + driver.addCommand( |
| 63 | + 'setWaitPluginTimeout', |
| 64 | + command('POST', '/session/:sessionId/waitplugin/timeout', { |
| 65 | + command: 'setWaitPluginTimeout', |
| 66 | + parameters: [ |
| 67 | + { |
| 68 | + name: 'data', |
| 69 | + type: 'object', |
| 70 | + description: 'a valid parameter', |
| 71 | + required: true, |
| 72 | + }, |
| 73 | + ], |
| 74 | + }) |
| 75 | + ); |
| 76 | + driver.addCommand( |
| 77 | + 'getWaitTimeout', |
| 78 | + command('GET', '/session/:sessionId/waitplugin/getTimeout', { |
| 79 | + command: 'getWaitTimeout', |
| 80 | + parameters: [], |
| 81 | + returns: { |
| 82 | + type: 'object', |
| 83 | + name: 'activity', |
| 84 | + description: 'Name of the current activity', |
| 85 | + }, |
| 86 | + }) |
| 87 | + ); |
| 88 | + }); |
| 89 | + it('Should be able to set and get waitPlugin timeout', async () => { |
| 90 | + await driver.$('#AlertButton'); |
| 91 | + expect(await driver.getWaitTimeout()).to.deep.include(FAKE_ARGS); |
| 92 | + await driver.setWaitPluginTimeout({ timeout: 1111, intervalBetweenAttempts: 11 }); |
| 93 | + expect(await driver.getWaitTimeout()).to.deep.include({ |
| 94 | + timeout: 1111, |
| 95 | + intervalBetweenAttempts: 11, |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + it('Basic Plugin test', async () => { |
| 100 | + const res = { fake: 'fakeResponse' }; |
| 101 | + (await axios.post('http://localhost:4723/fake')).data.should.eql(res); |
| 102 | + }); |
| 103 | + |
| 104 | + afterEach(async () => { |
| 105 | + await driver.deleteSession(); |
| 106 | + if (server) await server.close(); |
| 107 | + }); |
25 | 108 | });
|
26 | 109 |
|
27 |
| - afterEach('Stop server', async () => { |
28 |
| - if (server) await server.close(); |
| 110 | + describe('without CLI args', () => { |
| 111 | + let driver; |
| 112 | + pluginE2EHarness({ |
| 113 | + before, |
| 114 | + after, |
| 115 | + server, |
| 116 | + serverArgs: { basePath: '/wd/hub' }, |
| 117 | + port: TEST_PORT, |
| 118 | + host: TEST_HOST, |
| 119 | + appiumHome: APPIUM_HOME, |
| 120 | + driverName: 'fake', |
| 121 | + driverSource: 'npm', |
| 122 | + driverSpec: FAKE_DRIVER_DIR, |
| 123 | + pluginName: 'element-wait', |
| 124 | + pluginSource: 'local', |
| 125 | + pluginSpec: '.', |
| 126 | + }); |
| 127 | + beforeEach(async () => { |
| 128 | + driver = await remote({ ...WDIO_PARAMS, capabilities }); |
| 129 | + |
| 130 | + driver.addCommand( |
| 131 | + 'setWaitPluginTimeout', |
| 132 | + command('POST', '/session/:sessionId/waitplugin/timeout', { |
| 133 | + command: 'setWaitPluginTimeout', |
| 134 | + parameters: [ |
| 135 | + { |
| 136 | + name: 'data', |
| 137 | + type: 'object', |
| 138 | + description: 'a valid parameter', |
| 139 | + required: true, |
| 140 | + }, |
| 141 | + ], |
| 142 | + }) |
| 143 | + ); |
| 144 | + driver.addCommand( |
| 145 | + 'getWaitTimeout', |
| 146 | + command('GET', '/session/:sessionId/waitplugin/getTimeout', { |
| 147 | + command: 'getWaitTimeout', |
| 148 | + parameters: [], |
| 149 | + returns: { |
| 150 | + type: 'object', |
| 151 | + name: 'activity', |
| 152 | + description: 'Name of the current activity', |
| 153 | + }, |
| 154 | + }) |
| 155 | + ); |
| 156 | + }); |
| 157 | + it('Should be able to set and get waitPlugin timeout', async () => { |
| 158 | + await driver.$('#AlertButton'); |
| 159 | + expect(await driver.getWaitTimeout()).to.deep.include({ |
| 160 | + timeout: 10000, |
| 161 | + intervalBetweenAttempts: 500, |
| 162 | + }); |
| 163 | + await driver.setWaitPluginTimeout({ timeout: 1111, intervalBetweenAttempts: 11 }); |
| 164 | + expect(await driver.getWaitTimeout()).to.deep.include({ |
| 165 | + timeout: 1111, |
| 166 | + intervalBetweenAttempts: 11, |
| 167 | + }); |
| 168 | + }); |
| 169 | + |
| 170 | + afterEach(async () => { |
| 171 | + await driver.deleteSession(); |
| 172 | + if (server) await server.close(); |
| 173 | + }); |
29 | 174 | });
|
30 | 175 | });
|
0 commit comments