【发布时间】:2017-11-13 08:21:52
【问题描述】:
我已将 cucumber 与 nightwatch.js 集成。
我的 package.json 看起来像:-
{
"name": "learning-nightwatch",
"version": "1.0.0",
"description": "learning nightwatch",
"license": "UNLICENSED",
"scripts": {
"nightwatch": "nightwatch",
"start": "bin/start",
"stop": "bin/stop",
"test": "bin/test"
},
"dependencies": {
"lodash": "^4.17.4",
"minimist": "^1.2.0",
"nightwatch": "^0.9.16",
"cucumber": "^3.1.0",
"nightwatch-cucumber": "^8.2.9"
}
}
nigtwatch 配置:-
{
"src_folders": [null],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "./pageObjects",
"globals_path": "",
"test_settings": {
"default": {
"launch_url": "http://localhost:8083",
"selenium_port": 4444,
"selenium_host": "localhost",
"screenshots": {
"enabled": true,
"on_failure": true,
"on_error": true,
"path": "./screenshots"
},
"desiredCapabilities": {
"marionette": true,
"javascriptEnabled": true,
"acceptSslCerts": true,
"browserName": "chrome",
"chromeOptions": {
"args": ["start-fullscreen"]
}
},
"silent": true
},
"firefox": {
"desiredCapabilities": {
"browserName": "firefox",
"args": ["-headless"]
}
}
},
"selenium": {
"start_process": true,
"server_path": "./bin/lib/selenium-server-standalone-3.7.1.jar",
"log_path": "",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "./bin/lib/chromedriver",
"webdriver.gecko.driver": "./bin/lib/geckodriver"
}
}
}
当我使用 yarn nightwatch 运行测试用例时。它成功运行了测试用例,但应用程序永远不会以退出代码 0 终止并显示以下消息:
4 scenarios (4 passed)
8 steps (8 passed)
0m05.510s
(node:19502) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'indexOf' of undefined
(node:19502) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
有人知道我为什么会收到这个错误吗?
【问题讨论】:
-
很明显,当
xyz是undefined时,您正在尝试做xyz.indexOf。这会导致一个错误,最终导致一个 Promise 被拒绝,并且代码没有处理该拒绝。您需要找到包含xyz.indexOf的语句并修复它。 -
@T.J.Crowder 我在代码中的任何地方都没有做过类似的事情。为了澄清,我只添加了一个不包含 indexof 的谷歌搜索测试用例
-
可爱...祝你好运!
-
这没有意义:
"src_folders": [null],,为什么你的数组里面有一个空值? -
这不是我检查的问题
标签: javascript selenium selenium-webdriver cucumber nightwatch.js