尝试运行Selenium Webdriver(WebdriverJS)的示例测试时出错 [英] Getting Error while trying to run example test of Selenium Webdriver (WebdriverJS)
问题描述
我正在尝试在位于 \\\
ode_modules\selenium-webdriver \ example $的文件 google_search_test.js
中运行示例测试C $ C>。我正在使用WebdriverJS并且只在我的系统中安装了 selenium-webdriver
NPM包。
I am trying to run example test in file google_search_test.js
located at \node_modules\selenium-webdriver\example
. I am using WebdriverJS and only installed the selenium-webdriver
NPM package in my system.
我已经转移到了命令提示符中的路径位置并运行以下命令:节点google_search_test.js
I have moved to that path location in command prompt and ran the following command: 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中运行测试:
WebDriverJS (distributed as the npm package selenium-webdriver
) uses Mocha as its test driver. Assuming you are in the directory where node_modules
is located, you must run the test in Mocha:
mocha -t 5000 node_modules/selenium-webdriver/example/google_search_test.js
如果您在全球安装了Mocha( npm -g install mocha
),则上述操作将起作用。如果您在本地安装它(使用 npm install mocha
),则必须提供本地二进制文件的路径。在Unix系统上你可以这样做:
The above will work if you have Mocha installed globally (with npm -g install mocha
). If you install it locally (with npm install mocha
), you have to give the path to the local binary. On Unix systems you'd do:
node_modules/.bin/mocha -t 5000 node_modules/selenium-webdriver/example/google_search_test.js
我不知道npm在Windows系统上放置本地二进制文件的位置。
I don't know where npm puts local binaries on Windows systems.
我建议使用 -t 5000
将超时从默认的2秒增加到5秒。在我的系统上,默认超时太短,并且等待Firefox启动时,挂钩前的测试失败。
I suggest using -t 5000
to increase the timeout from the default 2 seconds to 5 seconds. On my system, the default timeout is too short and the test fails in the before
hook while waiting for Firefox to start.
如果您想知道为什么 selenium-webdriver
不仅仅将Mocha列为依赖项,这是因为很有可能在不使用Mocha的情况下使用此包。因此,如果他们想要使用它,则由软件包的用户自行安装。
If you wonder why selenium-webdriver
does not just list Mocha as a dependency this is because it is quite possible to use this package without using Mocha. So it is up to users of the package to install Mocha themselves, if they want to use it.
这篇关于尝试运行Selenium Webdriver(WebdriverJS)的示例测试时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!