Search code examples
javascriptappiumwebdriver-io

WDIO / Appium - " TypeError: $(...).waitForDisplayed is not a function" in my test


I am trying to learn to automate End2end testing a React-native mobile App using WDIO and Appium.

The target component I am trying to click in this problem is this:

Component screen shot

I got an error of TypeError: $(...).waitForDisplayed is not a function" in my current test project. While I got "elements not found" when I'll do assync mode.

I can verify that the IDs are visible in Appium Element Inspector

ScreenShot here

Below are my codes (#1 & #2) Either way, I got an error. I really need to understand why I got this errors.
#1

    describe('Test Unit - Assync Mode', () => {
      it('Client must be able to login in the app. ', async () => { 
        // pay attention to `async` keyword
        const el = await $('~pressSkip') // note `await` keyword
        await el.click()
        await browser.pause(500)
      })
    })

Error Message:

Error Message

#2

    beforeEach(() => {
       $('~pressSkip').waitForDisplayed({ timeout: 20000 })
    })
    
    describe('My Simple test', () => {
      it('Client must be able to login the app', () => {
        // Click Skip button id: "pressSkip"
        $('~pressSkip').click();
        // Enter Login
          // Email id: "loginEmail"
          // Password id: "loginPwd"
        // Click Login Button id:
      });
    });

Wdio.conf.js

    const { join } = require('path');
    
    exports.config = {
    //
    // ====================
    // Runner Configuration
    // ====================
    //
    // WebdriverIO allows it to run your tests in arbitrary locations (e.g. locally or
    // on a remote machine).
    runner: 'local',
    //
    // ==================
    // Specify Test Files
    // ==================
       
    specs: [
        './test/specs/**/*.js'],
    // ============
    // Capabilities
    // ============
    //
    capabilities: [{
    // http://appium.io/docs/en/writing-running-appium/caps/
    // This is `appium:` for all Appium Capabilities which can be found here
    'appium:platformName': 'Android',
    'appium:deviceName': 'emulator-5554',
    'appium:platformVersion': '8.1.0',
    'appium:newCommandTimeout': '60',         
    'appium:app': join(process.cwd(), '/android/app/build/outputs/apk/debug/app-debug.apk'),
    }],
    //
    // If you only want to run your tests until a specific amount of tests have failed use
    // bail (default is 0 - don't bail, run all tests).
        bail: 0,
    //
    // Set a base URL in order to shorten url command calls. If your `url` parameter starts
    // with `/`, the base url gets prepended, not including the path portion of your baseUrl.
    // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
    // gets prepended directly.
        baseUrl: 'http://localhost:/wd/hub',
    //
    // Default timeout for all waitFor* commands.
        waitforTimeout: 10000,
    //
    // Default timeout in milliseconds for request
    // if browser driver or grid doesn't send response
        connectionRetryTimeout: 120000,
    //
    // Default request retries count
        connectionRetryCount: 3,
    //
    // Test runner services
    // Services take over a specific job you don't want to take care of. They enhance
    // your test setup with almost no effort. Unlike plugins, they don't add new
    // commands. Instead, they hook themselves up into the test process.
        services: [['appium',{
        // This will use the globally installed version of Appium
        command: 'appium',
        args: {
        basePath: "/wd/hub",
    // This is needed to tell Appium that we can execute local ADB commands
    // and to automatically download the latest version of ChromeDriver
        relaxedSecurity: true,}
    }]],
    port: 4723,
    hostname: "localhost",
    // Make sure you have the wdio adapter package for the specific framework installed
    // before running any tests.
    framework: 'jasmine',
    //
    // Test reporter for stdout.
    // The only one supported by default is 'dot'
    // see also: https://webdriver.io/docs/dot-reporter
        reporters: ['spec'],
    //
    // Options to be passed to Jasmine.
        jasmineOpts: {
    // Jasmine default timeout
       defaultTimeoutInterval: 60000,
    //
    // The Jasmine framework allows interception of each assertion in order to log the state of the application
    // or website depending on the result. For example, it is pretty handy to take a screenshot every time
        },
    }

Solution

  • describe('Test Unit - Assync Mode', () => {
      it('Client must be able to login in the app. ', async () => { 
        // pay attention to `async` keyword
        await (await $('~pressSkip')).waitForDisplayed({ timeout: 20000 })
        const el = await $('~pressSkip') // note `await` keyword
        await el.click()
        await browser.pause(500)
      })
    })
    

    add await to the waitfordisplay also