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

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

我正在尝试学习使用 wdio 和 appium 自动化端到端测试 React-native 移动应用程序。

我在这个问题中试图点击的目标组件是这样的: Component screen shot

我在当前的测试项目中遇到了 TypeError: $(...).waitForDisplayed is not a function 错误。当我执行异步模式时遇到“找不到元素”的错误。

我可以验证 ID 在 Appium Element Inspector 中是否可见 ScreenShot here

以下是我的代码(#1 和#2) 无论哪种方式,我都遇到了错误。我真的需要了解为什么会出现此错误。 #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

#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
},
}
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)
  })
})

也将 await 添加到 waitfordisplay