Skip to content

Commit

Permalink
Implements uncheckOption in WebDriverIO (#856)
Browse files Browse the repository at this point in the history
* uncheckOption in WebdriverIO

Adds uncheckOption.

* Added uncheckOption docs

* pt-BR for uncheckOption

* Fixed doc
  • Loading branch information
brunobg authored and DavertMik committed Jan 12, 2018
1 parent 50e50ed commit 61a2461
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/webapi/uncheckOption.mustache
@@ -0,0 +1,12 @@
Unselects a checkbox or radio button.
Element is located by label or name or CSS or XPath.

The second parameter is a context (CSS or XPath locator) to narrow the search.

```js
I.uncheckOption('#agree');
I.uncheckOption('I Agree to Terms and Conditions');
I.uncheckOption('agree', '//form');
```
@param field checkbox located by label | name | CSS | XPath | strict locator
@param context (optional) element located by CSS | XPath | strict locator
18 changes: 18 additions & 0 deletions lib/helper/WebDriverIO.js
Expand Up @@ -649,6 +649,24 @@ class WebDriverIO extends Helper {
return this.browser[clickMethod](elem.ELEMENT);
}

/**
* {{> ../webapi/uncheckOption }}
* Appium: not tested
*/
async uncheckOption(field, context = null) {
const clickMethod = this.browser.isMobile ? 'touchClick' : 'elementIdClick';
const locateFn = prepareLocateFn.call(this, context);

const res = await findCheckable.call(this, field, locateFn);

assertElementExists(res, field, 'Checkable');
const elem = res.value[0];

const isSelected = await this.browser.elementIdSelected(elem.ELEMENT);
if (!isSelected.value) return Promise.resolve(true);
return this.browser[clickMethod](elem.ELEMENT);
}

/**
* {{> ../webapi/grabTextFrom }}
* Appium: support
Expand Down
1 change: 1 addition & 0 deletions translations/pt-BR.js
Expand Up @@ -25,6 +25,7 @@ module.exports = {
dontSeeInField: 'naoVejoNoCampo',
appendField: 'adicionaCampo',
checkOption: 'marcoOpcao',
uncheckOption: 'desmarcoOpcao',
seeCheckboxIsChecked: 'vejoCheckboxMarcado',
dontSeeCheckboxIsChecked: 'naoVejoCheckboxMarcado',
grabTextFrom: 'pegoTextoDe',
Expand Down

0 comments on commit 61a2461

Please sign in to comment.