Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .github/workflows/node.js.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*
lib/
local_appium_home/

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down
41 changes: 11 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,42 +69,23 @@ driver.findElementByAccessibilityId("login").sendKeys('Hello');
```
## Configure Wait timeout in test

WDIO Example
WDIO Example

```
driver.addCommand(
'setWaitPluginTimeout',
command('POST', '/session/:sessionId/waitplugin/timeout', {
command: 'setWaitPluginTimeout',
parameters: [
{
name: 'data',
type: 'object',
description: 'a valid parameter',
required: true,
},
],
})
);

driver.addCommand(
'getWaitTimeout',
command('GET', '/session/:sessionId/waitplugin/getTimeout', {
command: 'getWaitTimeout',
parameters: [],
returns: {
type: 'object',
name: 'timeout',
description: 'Get timeout set',
},
})
);
await driver.executeScript('plugin: setWaitTimeout', [
{
timeout: 1111,
intervalBetweenAttempts: 11,
},
]);

await driver.executeScript('plugin: getWaitTimeout', [])
```

Usage
Java Example

```
await driver.setWaitPluginTimeout({ timeout: 1111, intervalBetweenAttempts: 11 });
driver.executeScript("plugin: setWaitTimeout", ImmutableMap.of("timeout", 1111 , "intervalBetweenAttempts", 11 ));
```

Server logs will be as below:
Expand Down
91 changes: 91 additions & 0 deletions __tests__/e2e/plugin.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { remote } from 'webdriverio';
import { pluginE2EHarness } from '@appium/plugin-test-support';
import path from 'path';
var chai = require('chai'),
chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);
// eslint-disable-next-line no-undef
should = chai.should();
let expect = chai.expect;

const APPIUM_HOST = 'localhost';
const FAKE_ARGS = { timeout: 10000, intervalBetweenAttempts: 1000 };
const FAKE_PLUGIN_ARGS = { 'element-wait': FAKE_ARGS };

const THIS_PLUGIN_DIR = path.join(__dirname, '..', '..');
const APPIUM_HOME = path.join(THIS_PLUGIN_DIR, 'local_appium_home');
const FAKE_DRIVER_DIR =
process.env.PLATFORM === 'android' ? 'appium-uiautomator2-driver' : 'appium-xcuitest-driver';
const TEST_HOST = 'localhost';
const TEST_PORT = 4723;

let server;
const WDIO_PARAMS = {
connectionRetryCount: 220000,
hostname: APPIUM_HOST,
port: 4723,
path: '/wd/hub',
};
const androidCaps = {
platformName: 'Android',
'appium:uiautomator2ServerInstallTimeout': '120000',
'appium:automationName': 'UIAutomator2',
'appium:app':
'https://github.com/AppiumTestDistribution/appium-demo/blob/main/VodQA.apk?raw=true',
};

const iOSCaps = {
platformName: 'iOS',
'appium:automationName': 'XCUITest',
'appium:deviceName': 'iPhone 14 Pro',
'appium:platformVersion': '16.2',
'appium:app':
'https://github.com/AppiumTestDistribution/appium-demo/blob/main/vodqa.zip?raw=true',
};

describe('Set Timeout', () => {
describe('with CLI args', () => {
let driver;
pluginE2EHarness({
before,
after,
server,
serverArgs: { basePath: '/wd/hub', plugin: FAKE_PLUGIN_ARGS },
port: TEST_PORT,
host: TEST_HOST,
appiumHome: APPIUM_HOME,
driverName: process.env.PLATFORM === 'android' ? 'uiautomator2' : 'xcuitest',
driverSource: 'npm',
driverSpec: FAKE_DRIVER_DIR,
pluginName: 'element-wait',
pluginSource: 'local',
pluginSpec: '.',
});
beforeEach(async () => {
driver = await remote({
...WDIO_PARAMS,
capabilities: process.env.PLATFORM === 'android' ? androidCaps : iOSCaps,
});
});
it('Should be able to set and get waitPlugin timeout', async () => {
await driver.$('~login').click();
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include(FAKE_ARGS);
await driver.executeScript('plugin: setWaitTimeout', [
{
timeout: 1111,
intervalBetweenAttempts: 11,
},
]);
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include({
timeout: 1111,
intervalBetweenAttempts: 11,
});
});

afterEach(async () => {
await driver.deleteSession();
if (server) await server.close();
});
});
});
78 changes: 17 additions & 61 deletions __tests__/plugin.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { remote } from 'webdriverio';
import { command } from 'webdriver';
import { pluginE2EHarness } from '@appium/plugin-test-support';
import path from 'path';
var chai = require('chai'),
Expand Down Expand Up @@ -61,39 +60,17 @@ describe('Set Timeout', () => {
});
beforeEach(async () => {
driver = await remote({ ...WDIO_PARAMS, capabilities });

driver.addCommand(
'setWaitPluginTimeout',
command('POST', '/session/:sessionId/waitplugin/timeout', {
command: 'setWaitPluginTimeout',
parameters: [
{
name: 'data',
type: 'object',
description: 'a valid parameter',
required: true,
},
],
})
);
driver.addCommand(
'getWaitTimeout',
command('GET', '/session/:sessionId/waitplugin/getTimeout', {
command: 'getWaitTimeout',
parameters: [],
returns: {
type: 'object',
name: 'activity',
description: 'Name of the current activity',
},
})
);
});
it('Should be able to set and get waitPlugin timeout', async () => {
await driver.$('id=AlertButton');
expect(await driver.getWaitTimeout()).to.deep.include(FAKE_ARGS);
await driver.setWaitPluginTimeout({ timeout: 1111, intervalBetweenAttempts: 11 });
expect(await driver.getWaitTimeout()).to.deep.include({
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include(FAKE_ARGS);
await driver.executeScript('plugin: setWaitTimeout', [
{
timeout: 1111,
intervalBetweenAttempts: 11,
},
]);
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include({
timeout: 1111,
intervalBetweenAttempts: 11,
});
Expand Down Expand Up @@ -129,42 +106,21 @@ describe('Set Timeout', () => {
});
beforeEach(async () => {
driver = await remote({ ...WDIO_PARAMS, capabilities });

driver.addCommand(
'setWaitPluginTimeout',
command('POST', '/session/:sessionId/waitplugin/timeout', {
command: 'setWaitPluginTimeout',
parameters: [
{
name: 'data',
type: 'object',
description: 'a valid parameter',
required: true,
},
],
})
);
driver.addCommand(
'getWaitTimeout',
command('GET', '/session/:sessionId/waitplugin/getTimeout', {
command: 'getWaitTimeout',
parameters: [],
returns: {
type: 'object',
name: 'activity',
description: 'Name of the current activity',
},
})
);
});

it('Should be able to set and get waitPlugin timeout', async () => {
await driver.$('#AlertButton');
expect(await driver.getWaitTimeout()).to.deep.include({
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include({
timeout: 10000,
intervalBetweenAttempts: 500,
});
await driver.setWaitPluginTimeout({ timeout: 1111, intervalBetweenAttempts: 11 });
expect(await driver.getWaitTimeout()).to.deep.include({
await driver.executeScript('plugin: setWaitTimeout', [
{
timeout: 1111,
intervalBetweenAttempts: 11,
},
]);
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include({
timeout: 1111,
intervalBetweenAttempts: 11,
});
Expand Down
68 changes: 68 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
trigger:
- main

jobs:
- job: UnitTest
pool:
vmImage: 'macOS-latest'

steps:
- task: NodeTool@0.200.0
inputs:
versionSpec: '16.x'

- script: |
npm ci
npm test
displayName: 'npm test'

- job: ANDROID
pool:
vmImage: 'macOS-latest'

steps:
- task: NodeTool@0.200.0
inputs:
versionSpec: '16.x'

- script: |
npm ci
displayName: 'npm install'

- bash: |
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-27;google_apis;x86'
displayName: "install Android image"
- script: |
$ANDROID_HOME/emulator/emulator -list-avds
echo '---'
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n test_android_emulator -k 'system-images;android-27;google_apis;x86' --force
echo '---'
$ANDROID_HOME/emulator/emulator -list-avds
displayName: "create AVD"
- script: |
$ANDROID_HOME/platform-tools/adb devices
echo '---'
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'
echo '---'
$ANDROID_HOME/platform-tools/adb devices
displayName: "start Android emulator"
- script: |
PLATFORM='android' npm run test-e2e
displayName: "Android Integration Test"
- job: iOS
pool:
vmImage: 'macOS-latest'

steps:
- task: NodeTool@0.200.0
inputs:
versionSpec: '16.x'

- script: |
npm ci
displayName: 'npm install'

- script: |
xcrun simctl list
PLATFORM='ios' npm run test-e2e
displayName: "iOS Integration Test"
Loading