Search code examples
appiumcodeceptjs

Using appium custom helper from docs, does not give access to appium functions, "is not a function" error occurs for most functions


What am I missing?

I'm trying to write a custom helper that checks for 4 elements, and then sends a different command based on which element is present.

In order to do this, we needed a custom helper per the codeceptjs documentation https://codecept.io/helpers/Appium.

So we call:

let browser = this.helpers['Appium'].browser

But that unfortunatly does not work as documented, it does not give access to almost any of the Appium functions documented on their website http://appium.io/docs/en/about-appium/api/

So when we try:

async checkElement(locator) {
let client = this.helpers['Appium'].browser;
        let elementResult = await client.$$(locator).isEnabled();
}

All of these commands throw an error that says something like this:

browser.$(...).isEnabled is not a function

Per the codeceptjs docs... that should be an appium client with all of those functions included...


Solution

    1. client.$$(locator) returns an array of elements found. Array in javascript does not have isEnabled() function. You can use $(locator) to find first element or $$(locator)[0]. $ throws exception if element not found, $$(...)[0] throws index of bound exception, if elements was not found (array with length of 0). Use first, if element should be single on page.

    2. Appium helper is wrapper for webdriverio Appium wrapper. It can differ from original Appium. See it's API here.