尝试运行 Selenium Webdriver (WebdriverJS) 的示例测试时出现错误

2024-03-09

我正在尝试在文件中运行示例测试google_search_test.js位于\node_modules\selenium-webdriver\example。我正在使用 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 https://code.google.com/p/selenium/wiki/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 秒。在我的系统上,默认超时时间太短,测试失败before等待 Firefox 启动时挂接。

如果你想知道为什么selenium-webdriver不仅仅将 Mocha 列为依赖项,这是因为很可能在不使用 Mocha 的情况下使用此包。因此,如果软件包的用户想要使用 Mocha,则需要自行安装 Mocha。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试运行 Selenium Webdriver (WebdriverJS) 的示例测试时出现错误 的相关文章

随机推荐