Skip to content

Commit

Permalink
make timeout override to be partial and enable enable check exclusion. (
Browse files Browse the repository at this point in the history
#79)

* make timeout override to be partial and enable enable check exclusion.

* remove depricated bindings and update methods. add fix for #80

* move wait-on installation to last stage.

* instal wait-on in bootstrap and use absolute path to run wait-on

* add await for async function - getPluginProperties()
  • Loading branch information
Dileep17 authored Jun 22, 2023
1 parent 641472a commit 36ddcc9
Show file tree
Hide file tree
Showing 9 changed files with 1,018 additions and 1,637 deletions.
3 changes: 2 additions & 1 deletion .azure-template/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ steps:
npm config delete prefix
npm config set prefix $NVM_DIR/versions/node/`node --version`
node --version
npm install -g appium@next
npm install -g appium@next
npm install -g wait-on
52 changes: 47 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<br>
<br>
</h1>

This is an Appium plugin designed to wait for element to be present.

## Prerequisite
Expand All @@ -16,6 +15,15 @@ Appium version 2.0

Tested with appium v2.0.0-beta.42

### From Verion 2.0.0
* Following bindings are not supported
- `sessionId/waitplugin/timeout`
- `sessionId/waitplugin/getTimeout`
* Following command are renamed
- `plugin: getWaitTimeout` is renamed to `plugin: getWaitPluginProperties`
- `plugin: getWaitTimeout` is renamed to `plugin: setWaitPluginProperties`


## Installation - Server

Install the plugin using Appium's plugin CLI, either as a named plugin or via NPM:
Expand All @@ -41,7 +49,8 @@ appium --use-plugins=element-wait
To override the default element-wait retry
1. Use appium server CLI
--plugin-element-wait-timeout=30000
--plugin-element-wait-interval-between-attempts=200
--plugin-element-wait-interval-between-attempts=200
--plugin-element-wait-element-enabled-check-exclusion-cmds-list=['click']


2. Use appium server config file. [Refer](https://github.com/AppiumTestDistribution/appium-wait-plugin/blob/main/server-config.json).
Expand Down Expand Up @@ -69,23 +78,37 @@ driver.findElementByAccessibilityId("login").sendKeys('Hello');
```
## Configure Wait timeout in test

While overriding timeouts one can choose to override all or one of the below
* timeout
* intervalBetweenAttempts

WDIO Example

```
await driver.executeScript('plugin: setWaitTimeout', [
await driver.executeScript('plugin: setWaitPluginProperties', [
{
timeout: 1111,
intervalBetweenAttempts: 11,
},
]);
await driver.executeScript('plugin: getWaitTimeout', [])
await driver.executeScript('plugin: getWaitPluginProperties', [])
```
or
```
await driver.executeScript('plugin: setWaitPluginProperties', [
{
timeout: 1111,
},
]);
await driver.executeScript('plugin: getWaitPluginProperties', [])
```

Java Example

```
driver.executeScript("plugin: setWaitTimeout", ImmutableMap.of("timeout", 1111 , "intervalBetweenAttempts", 11 ));
driver.executeScript("plugin: setWaitPluginProperties", ImmutableMap.of("timeout", 1111 , "intervalBetweenAttempts", 11 ));
```

Server logs will be as below:
Expand All @@ -101,3 +124,22 @@ Server logs will be as below:
[Plugin [element-wait (sessionless)]] Checking if login element is displayed
[Plugin [element-wait (sessionless)]] login element is displayed.
```

## Skip element Enabled Check for commands
Before performing actions such as `click`, `setValue`, `clear` etc, plugin waits for element to be enabled.
As mentioned in [#78](https://github.com/AppiumTestDistribution/appium-wait-plugin/issues/78) if there is a need to skip the `elementEnabled` check for a set of commands, `excludeEnabledCheck` can be sent along with timeout values.
##### Usage
wdio
```
await driver.executeScript('plugin: setWaitPluginProperties', [
{
timeout: 1111,
intervalBetweenAttempts: 11,
excludeEnabledCheck: ['click','setValue']
},
]);
await driver.executeScript('plugin: getWaitPluginProperties', [])
```

By default `excludeEnabledCheck` is empty list.
18 changes: 11 additions & 7 deletions __tests__/e2e/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ should = chai.should();
let expect = chai.expect;

const APPIUM_HOST = '127.0.0.1';
const DEFAULT_TIMEOUT_VALUE = { timeout: 10000, intervalBetweenAttempts: 500 };
const DEFAULT_TIMEOUT_VALUE = {
timeout: 10000,
intervalBetweenAttempts: 500,
excludeEnabledCheck: [],
};

const androidApp = resolve('./build/VodQA.apk');
const iosApp = resolve('./build/vodqa.zip');
Expand All @@ -34,7 +38,7 @@ const iOSCaps = {
'appium:platformVersion': '16.2',
'appium:app': iosApp,
'appium:usePrebuiltWDA': true,
'appium:wdaLaunchTimeout': 120000
'appium:wdaLaunchTimeout': 120000,
};

describe('Set Timeout', () => {
Expand All @@ -46,18 +50,18 @@ describe('Set Timeout', () => {
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(
it('Should be able to get default properties and override/get properties', async () => {
expect(await driver.executeScript('plugin: getWaitPluginProperties', [])).to.deep.include(
DEFAULT_TIMEOUT_VALUE
);
await driver.executeScript('plugin: setWaitTimeout', [
await driver.$('~login').click();
await driver.executeScript('plugin: setWaitPluginProperties', [
{
timeout: 1111,
intervalBetweenAttempts: 11,
},
]);
expect(await driver.executeScript('plugin: getWaitTimeout', [])).to.deep.include({
expect(await driver.executeScript('plugin: getWaitPluginProperties', [])).to.deep.include({
timeout: 1111,
intervalBetweenAttempts: 11,
});
Expand Down
Loading

0 comments on commit 36ddcc9

Please sign in to comment.