webstorm - WebdriverIO 5 - 'browser.$(...).click 不是函数' 错误
问题描述
我是 WebdriverIO 的新手。我试图执行我的第一个功能文件,但出现此错误:
[chrome windows #0-0] browser.$(...).click is not a function
[chrome windows #0-0] TypeError: browser.$(...).click is not a function
但是click()
当我在编辑器中输入代码时,我可以看到自动建议中列出的功能。有人可以指出我做错了什么吗?
这是我的步骤定义文件:
import {Given, Then} from "cucumber";
Given(/^I navigated to RPA Challenge website$/, function() {
browser.url("http://rpachallenge.com/");
});
Then(/^I see the submit button$/, function () {
browser.$("/html/body/app-root/div[2]/app-rpa1/div/div[2]/form/input").click();
console.log("URL is "+browser.getUrl());
});
这是我的 package.json 文件:
{
"name": "WebdriverIO_2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.6",
"@babel/preset-env": "^7.8.6",
"@babel/register": "^7.8.6",
"@wdio/cli": "^5.18.7",
"@wdio/cucumber-framework": "^5.18.6",
"@wdio/local-runner": "^5.18.7",
"@wdio/spec-reporter": "^5.18.7",
"@wdio/sync": "^5.18.7",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"chromedriver": "^80.0.1",
"cucumber": "^6.0.5",
"install": "^0.13.0",
"wdio-chromedriver-service": "^5.0.2",
"webdriverio": "^5.18.7"
},
"dependencies": {
"wdio-selenium-standalone-service": "0.0.12"
}
}
输出和错误消息:
C:\Users\myusername\Desktop\WebdriverIO3>node_modules\.bin\wdio wdio.conf.js
2020-03-04T07:18:16.130Z DEBUG @wdio/sync: Couldn't load fibers package for Node v10 and above
2020-03-04T07:18:16.130Z DEBUG @wdio/sync: Couldn't load fibers package for Node v8
Execution of 1 spec files started at 2020-03-04T07:18:18.858Z
2020-03-04T07:18:19.124Z INFO @wdio/cli:launcher: Run onPrepare hook
Starting ChromeDriver 80.0.3987.16 (320f6526c1632ad4f205ebce69b99a062ed78647-refs/branch-heads/3987@{#185}) on port 4444
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
2020-03-04T07:18:19.940Z INFO @wdio/local-runner: Start worker 0-0 with arg: wdio.conf.js
[0-0] 2020-03-04T07:18:22.709Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in chrome - C:\Users\myusername\Desktop\WebdriverIO3\features\login.feature
[0-0] 2020-03-04T07:18:24.759Z INFO webdriverio: Initiate new session using the webdriver protocol
[0-0] 2020-03-04T07:18:24.766Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session
[0-0] 2020-03-04T07:18:24.766Z INFO webdriver: DATA { capabilities: { alwaysMatch: { browserName: 'chrome' }, firstMatch: [ {} ] },
desiredCapabilities: { browserName: 'chrome' } }
[3132:23720:0304/124825.906:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: AlwaysAuthorizePlugins
[3132:23720:0304/124825.906:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: DisablePluginFinder
[3132:23720:0304/124825.906:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: PasswordManagerAllowShowPasswords
[3132:23720:0304/124826.015:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: AlwaysAuthorizePlugins
[3132:23720:0304/124826.015:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: DisablePluginFinder
[3132:23720:0304/124826.015:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: PasswordManagerAllowShowPasswords
DevTools listening on ws://127.0.0.1:53324/devtools/browser/9124ea53-8ac6-483b-8bba-3dcdf611bb28
[0-0] 2020-03-04T07:18:34.702Z INFO webdriver: COMMAND navigateTo("http://rpachallenge.com/")
[0-0] 2020-03-04T07:18:34.703Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session/0132136b9c7a963983c93889b31c16d5/url
2020-03-04T07:18:34.703Z INFO webdriver: DATA { url: 'http://rpachallenge.com/' }
[0-0] 2020-03-04T07:18:34.712Z INFO webdriver: COMMAND findElement("xpath", "/html/body/app-root/div[2]/app-rpa1/div/div[2]/form/input")
[0-0] 2020-03-04T07:18:34.713Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session/0132136b9c7a963983c93889b31c16d5/element
[0-0] 2020-03-04T07:18:34.714Z INFO webdriver: DATA { using: 'xpath',
value: '/html/body/app-root/div[2]/app-rpa1/div/div[2]/form/input' }
[0-0] Error in "RPA Challenge website launch: scenario 1: Then I see the submit button"
browser.$(...).click is not a function
[0-0] 2020-03-04T07:18:34.775Z INFO webdriver: COMMAND deleteSession()
[0-0] 2020-03-04T07:18:34.777Z INFO webdriver: [DELETE] http://127.0.0.1:4444/wd/hub/session/0132136b9c7a963983c93889b31c16d5
[1583306316.590][SEVERE]: Timed out receiving message from renderer: 0.100
[1583306316.692][SEVERE]: Timed out receiving message from renderer: 0.100
[1583306316.796][SEVERE]: Timed out receiving message from renderer: 0.100
[1583306316.898][SEVERE]: Timed out receiving message from renderer: 0.100
[0-0] 2020-03-04T07:19:14.197Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '54156a65-2e41-4f61-b9fe-7669cf591b1c' }
[0-0] FAILED in chrome - C:\Users\myusername\Desktop\WebdriverIO3\features\login.feature
2020-03-04T07:19:14.593Z INFO @wdio/cli:launcher: Run onComplete hook
"spec" Reporter:
------------------------------------------------------------------
[chrome windows #0-0] Spec: C:\Users\myusername\Desktop\WebdriverIO3\features\login.feature
[chrome windows #0-0] Running: chrome on windows
[chrome windows #0-0] Session ID: 0132136b9c7a963983c93889b31c16d5
[chrome windows #0-0]
[chrome windows #0-0] RPA Challenge website launch
[chrome windows #0-0] scenario 1
[chrome windows #0-0] ✓ Given I navigated to RPA Challenge website
[chrome windows #0-0] ✖ Then I see the submit button
[chrome windows #0-0]
[chrome windows #0-0] 1 passing (44.3s)
[chrome windows #0-0] 1 failing
[chrome windows #0-0]
[chrome windows #0-0] 1) scenario 1 Then I see the submit button
[chrome windows #0-0] browser.$(...).click is not a function
[chrome windows #0-0] TypeError: browser.$(...).click is not a function
[chrome windows #0-0] at World.<anonymous> (C:\Users\myusername\Desktop\WebdriverIO3\stepDefs/Login.stepdef.js:8:76)
[chrome windows #0-0] at World.executeAsync (C:\Users\myusername\Desktop\WebdriverIO3\node_modules\@wdio\utils\build\shim.js:123:21)
[chrome windows #0-0] at World.testFrameworkFnWrapper (C:\Users\myusername\Desktop\WebdriverIO3\node_modules\@wdio\utils\build\test-framework\testFnWrapper.js:55:28)
[chrome windows #0-0] at <anonymous>
Spec Files: 0 passed, 1 failed, 1 total (100% completed) in 00:00:55
2020-03-04T07:19:14.600Z INFO @wdio/local-runner: Shutting down spawned worker
2020-03-04T07:19:14.860Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2020-03-04T07:19:14.860Z INFO @wdio/local-runner: shutting down
解决方案
错误是由于纤维而发生的。
2020-03-04T07:18:16.130Z DEBUG @wdio/sync: Couldn't load fibers package for Node v10 and above
对我来说最简单的解决方法是将纤程添加到 devDependencies。
推荐阅读
- android - 如何通过单击我的 Android 应用程序中的按钮来创建 Google 电子表格?
- java - 服务器错误 500:不存在任何值。在 Pivotal Cloud Foundry 上部署 Spring Boot
- google-apps-script - 从 Apps 脚本中的 URL 调用图像
- python - 打印数据框中有异常值的列
- wordpress - 如何从 Joomla 外部生成 Joomla 登录令牌
- sql - Top、Limit、Offset...我无法在 SQL Server 中显示寄存器
- python - 将 CNN 用于未塑造 NxM 的数据
- solr - 未能创建集合“techproducts”,原因是:创建集合时基础核心创建失败:techproducts
- elisp - 如何在 Emacs Lisp 中将对象转换为字符串,引用符号以便可以读回?
- html - IE11 无法渲染 SVG 元素,我不知道为什么