通过WebStorm中的Mocha运行WebdriverIO测试

时间:2019-02-09 21:28:40

标签: mocha webstorm webdriver-io

我想从WebStorm装订线(左侧的绿色三角形图标,按行号)运行WebdriverIO + Mocha测试。

enter image description here

但是当我按下运行三角形时-发生错误:

pci_resources/libpci_resources.a(PciResources.cpp.obj): In function `PciResources::getPciConfigurationSpaceAgent()':
Z:/pci_resources/src/PciResources.cpp:15: multiple definition of `PciResources::getPciConfigurationSpaceAgent()'
pci_test/libpci_test.dll.a(d001513.o):(.text+0x0): first defined here
pci_resources/libpci_resources.a(PciResources.cpp.obj): In function `PciResources::getHostCliAgent()':
Z:/pci_resources/src/PciResources.cpp:23: multiple definition of `PciResources::getHostCliAgent()'
pci_test/libpci_test.dll.a(d001508.o):(.text+0x0): first defined here
pci_resources/libpci_resources.a(PciResources.cpp.obj): In function `PciResources::getPciCrspace()':
Z:/pci_resources/src/PciResources.cpp:37: multiple definition of `PciResources::getPciCrspace()'
pci_test/libpci_test.dll.a(d001506.o):(.text+0x0): first defined here
pci_resources/libpci_resources.a(PciResources.cpp.obj): In function `PciResources::hasCrspace()':
Z:/pci_resources/src/PciResources.cpp:44: multiple definition of `PciResources::hasCrspace()'
pci_test/libpci_test.dll.a(d001505.o):(.text+0x0): first defined here
pci_resources/libpci_resources.a(PciResources.cpp.obj): In function `PciResources::hasConfigurationSpaceAgent()':
Z:/pci_resources/src/PciResources.cpp:48: multiple definition of `PciResources::hasConfigurationSpaceAgent()'
pci_test/libpci_test.dll.a(d001511.o):(.text+0x0): first defined here
pci_resources/libpci_resources.a(PciResources.cpp.obj): In function `PciResources::hasHostCliAgent()':
Z:/pci_resources/src/PciResources.cpp:52: multiple definition of `PciResources::hasHostCliAgent()'

如何从WebStorm运行WebdriverIO测试?

我的版本:

/Users/ilyubin/.nvm/versions/node/v10.15.0/bin/node /Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/bin/_mocha --ui bdd --reporter /Applications/WebStorm.app/Contents/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js /Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/test/specs/catalog/not.found.page.spec.js --grep "^Тесты страницы ошибок Поиск несуществующего запроса$"
/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/test/specs/catalog/not.found.page.spec.js:1
(function (exports, require, module, __filename, __dirname) { import {expect} from 'chai';
                                                                     ^

SyntaxError: Unexpected token {
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at /Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/mocha.js:324:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/mocha.js:321:14)
    at Mocha.run (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/mocha.js:763:10)
    at Object.exports.singleRun (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/cli/run-helpers.js:196:16)
    at exports.runMocha (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/cli/run-helpers.js:291:13)
    at Object.exports.handler.argv [as handler] (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/cli/run.js:292:3)
    at Object.runCommand (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/node_modules/yargs/lib/command.js:238:44)
    at Object.parseArgs [as _parseArgs] (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/node_modules/yargs/yargs.js:1072:28)
    at Object.parse (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/node_modules/yargs/yargs.js:566:25)
    at Object.exports.main (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/cli/cli.js:62:6)
    at Object.<anonymous> (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/bin/_mocha:10:23)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

我的依赖项:

WebStorm 2018.3.3
Build #WS-183.5153.33, built on January 9, 2019
JRE: 1.8.0_152-release-1343-b26 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.2

➜ ~ node -v
v10.15.0

➜ ~ mocha --version
5.2.0

1 个答案:

答案 0 :(得分:3)

您无法使用mocha测试运行程序运行wdio规格,因此 Mocha 运行配置不能在此处使用。您需要改为使用 Node.js 运行配置:

enter image description here

此外,由于您在测试中使用ES6语法,因此必须将wdio配置为使用babel。有关说明,请参见https://webdriver.io/docs/babel.html

  • npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/register
  • 在项目根文件夹中,创建文件babel.config.js
module.exports = {
  presets: [
    ['@babel/preset-env', {
      targets: {
        node: 8
      }
    }]
  ]
}
  • 在您的wdio.conf.js中,按照以下步骤设置摩卡;
mochaOpts: {
        ui: 'bdd',
        timeout: 60000,
        compilers: ['js:@babel/register']
    },