首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Appium与Webdriverio没有等待元素

Appium与Webdriverio没有等待元素
EN

Stack Overflow用户
提问于 2022-01-13 19:53:44
回答 1查看 819关注 0票数 0

我刚刚用Webdriverio安装了Appium,我在等待元素时遇到了麻烦。会话一打开就结束了,我从Appium日志中可以看到它正在等待0ms的元素。

这是我的测试文件login.test.js

代码语言:javascript
运行
复制
const welcome = require("../../pageObjects/welcome.page");

describe("Login", () => {
  it("Verify user can login", () => {
    driver.setImplicitTimeout(10000); // tried with implicit wait
    driver.pause(3000); // and with explicit wait
    welcome.signInBtn.click();
  });
});

welcome.page.js文件:

代码语言:javascript
运行
复制
class WelcomePage {
  /**
   * Define Elements
   */

  get signInBtn() {
    return $("~Sign in");
    
  }
}

module.exports = new WelcomePage();

package.json文件:

代码语言:javascript
运行
复制
{
  "name": "appium_js",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "./node_modules/.bin/wdio wdio.conf.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@wdio/cli": "^7.16.13"
  },
  "devDependencies": {
    "@wdio/local-runner": "^7.16.13",
    "@wdio/mocha-framework": "^7.16.13",
    "@wdio/selenium-standalone-service": "^7.16.13",
    "@wdio/spec-reporter": "^7.16.13",
    "@wdio/sync": "^7.16.13"
  }
}

wdio.conf.js文件:

代码语言:javascript
运行
复制
let { join } = require("path");

exports.config = {
  
  runner: "local",
  port: 4723,
  path: "/wd/hub",
  
  specs: ["./test/specs/**/*.js"],
 
  maxInstances: 1,
  
  capabilities: [
    {
      platformName: "Android",
      "appium:deviceName": "Pixel XL API 31",
      "appium:app": join(process.cwd(), "./app-dev-debug.apk"),
    },
  ],
  
  logLevel: "info",
  
  
  bail: 0,
  
  
  baseUrl: "http://localhost",
  
  waitforTimeout: 0,
  
  connectionRetryTimeout: 120000,
  
  connectionRetryCount: 3,
  
  services: ["selenium-standalone"],

  
  framework: "mocha",
  
  
  reporters: ["spec"],

  
  mochaOpts: {
    ui: "bdd",
    timeout: 60000,
  }
};

Appium原木

代码语言:javascript
运行
复制
[W3C (10484f32)] Calling AppiumDriver.findElement() with args: ["accessibility id","Sign in","10484f32-220b-4a22-ae39-9b7c6ff9adfb"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[WD Proxy] Matched '/element' to command name 'findElement'
[WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8201/wd/hub/session/0b87b7c0-9b19-48ce-9e6e-02c6d5cc8d08/element] with body: {"strategy":"accessibility id","selector":"Sign in","context":"","multiple":false}
[HTTP] --> DELETE /wd/hub/session/10484f32-220b-4a22-ae39-9b7c6ff9adfb
[HTTP] {}
[W3C (10484f32)] Calling AppiumDriver.deleteSession() with args: ["10484f32-220b-4a22-ae39-9b7c6ff9adfb"]
[BaseDriver] Event 'quitSessionRequested' logged at 1642100255280 (19:57:35 GMT+0100 (Central European Standard Time))
[Appium] Removing session 10484f32-220b-4a22-ae39-9b7c6ff9adfb from our master session list
[UiAutomator2] Deleting UiAutomator2 session
[UiAutomator2] Deleting UiAutomator2 server session
[WD Proxy] Matched '/' to command name 'deleteSession'
[WD Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:8201/wd/hub/session/0b87b7c0-9b19-48ce-9e6e-02c6d5cc8d08] with no body

不知道为什么它不等待元素,因为我已经尝试了隐式和显式等待?也许它与驱动程序有关。

EN

回答 1

Stack Overflow用户

发布于 2022-01-15 18:30:42

您需要在驱动程序功能中定义waitforTimeout,以隐式等待所有全局驱动程序执行。关于这方面的进一步参考,请参阅本文件,

https://webdriver.io/docs/timeouts/#waitfor-timeout

https://building.niche.com/appium-automated-app-testing-f8f6f9682061

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70702353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档