我刚刚用Webdriverio安装了Appium,我在等待元素时遇到了麻烦。会话一打开就结束了,我从Appium日志中可以看到它正在等待0ms的元素。
这是我的测试文件login.test.js
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文件:
class WelcomePage {
/**
* Define Elements
*/
get signInBtn() {
return $("~Sign in");
}
}
module.exports = new WelcomePage();
package.json文件:
{
"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文件:
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原木
[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
不知道为什么它不等待元素,因为我已经尝试了隐式和显式等待?也许它与驱动程序有关。
发布于 2022-01-15 18:30:42
您需要在驱动程序功能中定义waitforTimeout
,以隐式等待所有全局驱动程序执行。关于这方面的进一步参考,请参阅本文件,
https://webdriver.io/docs/timeouts/#waitfor-timeout
https://building.niche.com/appium-automated-app-testing-f8f6f9682061
https://stackoverflow.com/questions/70702353
复制相似问题