关于javascript:尝试运行Selenium Webdriver(WebdriverJS)的示例测试时出错

Getting Error while trying to run example test of Selenium Webdriver (WebdriverJS)

我试图在位于\
ode_modules\\selenium-webdriver\\example
的文件google_search_test.js中运行示例测试。我正在使用WebdriverJS,并且仅在系统中安装了selenium-webdriver NPM软件包。

我已移至命令提示符下的路径位置,并运行以下命令:node google_search_test.js

我收到以下错误:

enter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Path\
ode_modules\\selenium-webdriver\\example>node google_search_test.js

Path\
ode_modules\\selenium-webdriver\\testing\\index.js:184
exports.describe.skip = global.describe.skip;
                                       ^
TypeError: Cannot read property 'skip' of undefined
    at Object. (C:\\Users\\kanasra\\Desktop\\Jaguars\\Automation Testing\

odeJs\
ode_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. (C:\\Users\\kanasra\\Desktop\\Jaguars\\Automation Testing\

odeJs\
ode_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中运行测试:

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

如果您全局安装了Mocha(使用npm -g install mocha),则上述内容将起作用。如果在本地安装(使用npm install mocha),则必须提供本地二进制文件的路径。在Unix系统上,您可以执行以下操作:

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

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

我建议使用-t 5000将超时从默认的2秒增加到5秒。在我的系统上,默认超时时间太短,并且在等待Firefox启动时,before挂钩中的测试失败。

如果您想知道为什么selenium-webdriver不仅将Mocha列为依赖项,那是因为很可能无需使用Mocha就可以使用此软件包。因此,要由软件包的用户自行安装Mocha(如果要使用它)。