From 9044ddd2a5709aa501b7e4358fd00ebcbb29a3c6 Mon Sep 17 00:00:00 2001 From: Davert Date: Thu, 10 Jan 2019 23:29:43 +0200 Subject: [PATCH] fixed appium wait* methods to use appium locators --- docs/helpers/Appium.md | 59 +++++++++++++++++++++++++++++++++++++-- docs/helpers/WebDriver.md | 4 +-- lib/helper/Appium.js | 41 +++++++++++++++++++++++++-- lib/helper/WebDriver.js | 5 ---- 4 files changed, 98 insertions(+), 11 deletions(-) diff --git a/docs/helpers/Appium.md b/docs/helpers/Appium.md index 0ce6ae5fe..8a98eb5b5 100644 --- a/docs/helpers/Appium.md +++ b/docs/helpers/Appium.md @@ -653,8 +653,7 @@ I.selectOption('Which OS do you use?', ['Android', 'iOS']); #### Parameters - `select` field located by label|name|CSS|XPath|strict locator. -- `option` visible text or value of option. - Support only web testing! +- `option` visible text or value of option.- Supported on only for web testing! ### sendDeviceKeyEvent @@ -960,6 +959,62 @@ Appium: support Android and iOS - `actions` +### waitForElement + +Waits for element to be present on page (by default waits for 1sec). +Element can be located by CSS or XPath. + +```js +I.waitForElement('.btn.continue'); +I.waitForElement('.btn.continue', 5); // wait for 5 secs +``` + +#### Parameters + +- `locator` element located by CSS|XPath|strict locator. +- `sec` (optional) time in seconds to wait, 1 by default. + +### waitForInvisible + +Waits for an element to be removed or become invisible on a page (by default waits for 1sec). +Element can be located by CSS or XPath. + + I.waitForInvisible('#popup'); + +#### Parameters + +- `locator` element located by CSS|XPath|strict locator. +- `sec` (optional) time in seconds to wait, 1 by default. + +### waitForText + +Waits for a text to appear (by default waits for 1sec). +Element can be located by CSS or XPath. +Narrow down search results by providing context. + +```js +I.waitForText('Thank you, form has been submitted'); +I.waitForText('Thank you, form has been submitted', 5, '#modal'); +``` + +#### Parameters + +- `text` to wait for. +- `sec` (optional) time in seconds to wait. +- `context` (optional) element located by CSS|XPath|strict locator. + +### waitForVisible + +Waits for an element to become visible on a page (by default waits for 1sec). +Element can be located by CSS or XPath. + + I.waitForVisible('#popup'); + +#### Parameters + +- `locator` element located by CSS|XPath|strict locator. +- `sec` (optional) time in seconds to wait, 1 by default. + [1]: http://codecept.io/helpers/WebDriver/ [2]: http://appium.io/ diff --git a/docs/helpers/WebDriver.md b/docs/helpers/WebDriver.md index 8d14fa92d..02a84ccd5 100644 --- a/docs/helpers/WebDriver.md +++ b/docs/helpers/WebDriver.md @@ -1325,7 +1325,7 @@ I.waitForElement('.btn.continue', 5); // wait for 5 secs #### Parameters - `locator` element located by CSS|XPath|strict locator. -- `sec` (optional) time in seconds to wait, 1 by default.- _Appium_: supported +- `sec` (optional) time in seconds to wait, 1 by default. ### waitForEnabled @@ -1385,7 +1385,7 @@ I.waitForText('Thank you, form has been submitted', 5, '#modal'); - `text` to wait for. - `sec` (optional) time in seconds to wait. -- `context` (optional) element located by CSS|XPath|strict locator.- _Appium_: supported +- `context` (optional) element located by CSS|XPath|strict locator. ### waitForValue diff --git a/lib/helper/Appium.js b/lib/helper/Appium.js index 9856e8c24..e8726d6f7 100644 --- a/lib/helper/Appium.js +++ b/lib/helper/Appium.js @@ -1275,12 +1275,49 @@ class Appium extends Webdriver { /** * {{> ../webapi/selectOption }} - * Support only web testing! + * + * * Supported on only for web testing! */ async selectOption(select, option) { if (this.isWeb) return super.selectOption(select, option); throw new Error('Should be used only in Web context. In native context use \'click\' method instead'); } + + /** + * {{> ../webapi/waitForElement }} + * + */ + async waitForElement(locator, sec = null) { + if (this.isWeb) return super.waitForElement(locator, sec); + return super.waitForElement(parseLocator.call(locator)); + } + + /** + * {{> ../webapi/waitForVisible }} + * + */ + async waitForVisible(locator, sec = null) { + if (this.isWeb) return super.waitForVisible(locator, sec); + return super.waitForVisible(parseLocator.call(locator)); + } + + /** + * {{> ../webapi/waitForInvisible }} + * + */ + async waitForInvisible(locator, sec = null) { + if (this.isWeb) return super.waitForInvisible(locator, sec); + return super.waitForInvisible(parseLocator.call(locator)); + } + + /** + * {{> ../webapi/waitForText }} + * + */ + async waitForText(text, sec = null, context = null) { + if (this.isWeb) return super.waitForText(text, sec, context); + return super.waitForText(text, sec, parseLocator.call(context)); + } } function parseLocator(locator) { @@ -1312,7 +1349,7 @@ function parseLocator(locator) { } } - locator = new Locator(locator); + locator = new Locator(locator, 'xpath'); if (locator.type === 'css' && !this.isWeb) throw new Error('Unable to use css locators in apps. Locator strategies for this request: xpath, id, class name or accessibility id'); if (locator.type === 'name' && !this.isWeb) throw new Error("Can't locate element by name in Native context. Use either ID, class name or accessibility id"); if (locator.type === 'id' && !this.isWeb && this.platform === 'android') return `//*[@resource-id='${locator.value}']`; diff --git a/lib/helper/WebDriver.js b/lib/helper/WebDriver.js index 3b3a551ca..6c8fa2e17 100644 --- a/lib/helper/WebDriver.js +++ b/lib/helper/WebDriver.js @@ -1536,9 +1536,6 @@ class WebDriver extends Helper { /** * {{> ../webapi/waitForElement }} - * - * - * * *Appium*: supported */ async waitForElement(locator, sec = null) { const aSec = sec || this.options.waitForTimeout; @@ -1603,8 +1600,6 @@ class WebDriver extends Helper { /** * {{> ../webapi/waitForText }} * - * - * * *Appium*: supported */ async waitForText(text, sec = null, context = null) { const aSec = sec || this.options.waitForTimeout;