获取错误,而尝试运行seleniumwebdriver的示例testing

我试图在位于“\ node_modules \ selenium-webdriver \ example”的文件“google_search_test.js”中运行示例testing。 我正在使用webdriverjs,并且只在我的系统中安装了npm包“selenium-webdriver”。

我已经移动到命令提示符下的path位置并运行命令

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作为其testing驱动程序。 假设您位于node_modules所在的目录中,则必须在Mocha中运行testing:

 mocha -t 5000 node_modules/selenium-webdriver/example/google_search_test.js 

如果您在全球npm -g install mocha (以npm -g install mocha ),以上方法将可行。 如果您在本地安装(使用npm install mocha ),则必须提供本地二进制文件的path。 在Unix系统上,你会这样做:

 node_modules/.bin/mocha -t 5000 node_modules/selenium-webdriver/example/google_search_test.js 

我不知道npm在Windows系统上放置本地二进制文件。

我build议使用-t 5000将默认的2秒增加到5秒。 在我的系统上,默认的超时时间太短,而在等待Firefox启动的时候, before挂钩beforetesting失败。

如果您想知道为什么selenium-webdriver不仅仅将Mocha列为依赖项,这是因为在不使用Mocha的情况下很有可能使用这个包。 所以如果他们想要使用它,那么这个包的使用者自己安装Mocha。