我正在尝试在位于 \node_modules\selenium-webdriver\example
的文件 google_search_test.js
中运行示例测试。我正在使用 WebdriverJS,并且只在我的系统中安装了 selenium-webdriver
NPM 包。
我已移动到命令提示符中的该路径位置并运行以下命令:node google_search_test.js
我收到以下错误:
错误描述:
Path\node_modules\selenium-webdriver\example>node google_search_test.js
Path\node_modules\selenium-webdriver\testing\index.js:184
exports.describe.skip = global.describe.skip;
^
TypeError: Cannot read property 'skip' of undefined
at Object.<anonymous> (C:\Users\kanasra\Desktop\Jaguars\Automation Testing\N
odeJs\node_modules\selenium-webdriver\testing\index.js:184:40)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\kanasra\Desktop\Jaguars\Automation Testing\N
odeJs\node_modules\selenium-webdriver\example\google_search_test.js:24:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
最佳答案
WebDriverJS (作为 npm 包 selenium-webdriver
分发)使用 Mocha 作为其测试驱动程序。假设你在node_modules
所在的目录下,你必须在Mocha中运行测试:
mocha -t 5000 node_modules/selenium-webdriver/example/google_search_test.js
如果您全局安装了 Mocha(使用 npm -g install mocha
),以上内容将有效。如果您在本地安装它(使用 npm install mocha
),您必须提供本地二进制文件的路径。在 Unix 系统上你会这样做:
node_modules/.bin/mocha -t 5000 node_modules/selenium-webdriver/example/google_search_test.js
我不知道 npm 将本地二进制文件放在 Windows 系统上的什么地方。
我建议使用 -t 5000
将超时从默认的 2 秒增加到 5 秒。在我的系统上,默认超时时间太短,并且在等待 Firefox 启动时 before
Hook 中的测试失败。
如果您想知道为什么 selenium-webdriver
不只是将 Mocha 列为依赖项,这是因为很可能在不使用 Mocha 的情况下使用此包。因此,如果想要使用 Mocha,则由包的用户自行安装。
关于javascript - 尝试运行 Selenium Webdriver (WebdriverJS) 的示例测试时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27224959/