如何运行selenium-side-runner以针对Firefox执行测试?

时间:2019-07-12 16:49:17

标签: selenium firefox selenium-webdriver command-line

我刚刚在Mac Mojave上安装了selenium-side-runner,并尝试使用在IDE中记录的测试从命令行运行测试。我的测试文件名为“ myTest.side”。我创建了一个“ myTest.side.yml”文件来告诉selenium-side-runner我的驱动程序在哪里...

capabilities:
  chromeOptions:
    binary: '/Users/davea/Documents/workspace/starter_project/selenium/chromedriver_mac'
  firefoxOptions:
    binary: '/Users/davea/Documents/workspace/starter_project/selenium/geckodriver_mac'

但是,当我尝试运行测试时,出现此错误...

localhost:selenium davea$ selenium-side-runner -c "browserName=firefox" myTest.side
info:    Running myTest.side
 FAIL  ./DefaultSuite.test.js
  ● Test suite failed to run

    The geckodriver executable could not be found on the current PATH. Please download the latest version from https://github.com/mozilla/geckodriver/releases/ and ensure it can be found on your PATH.

      at findGeckoDriver (../../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/firefox.js:444:11)
      at new ServiceBuilder (../../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/firefox.js:533:22)
      at Function.createSession (../../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/firefox.js:591:21)
      at createDriver (../../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/index.js:155:33)
      at Builder.build (../../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/index.js:670:16)
      at buildDriver (../../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/jest-environment-selenium/dist/index.js:66:17)
      at WebdriverEnvironment.setup (../../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/jest-environment-selenium/dist/index.js:37:32)

Test Suites: 1 failed, 1 total

如何使用Firefox从命令行运行测试?

2 个答案:

答案 0 :(得分:0)

在要运行测试的目录中创建一个 .side.yml 文件。跑步者将自动捡起它。这是文件内容的示例。和Selenium Command-Line Runner一样。

所以请确保更改文件名。

或者您可以使用-config-file 而不更改文件名。 --config-file将忽略.side.yml,并从指定路径中获取配置。

selenium-side-runner --config-file "/path/to/your/config.yaml"

Selenium IDE Documenation的信用额

答案 1 :(得分:0)

如前所述,代码不起作用的原因是文件命名约定。

默认情况下,selenium-side-runner将选择文件.side.yml而不是<somename>.side.yml

因此,如果您只是重命名文件,它将为您选择正确的详细信息

更新:7月16日

经过大量的调试,看来您遇到的是一个错误。所以发生的错误是很明显的

at new ServiceBuilder (selenium-webdriver/chrome.js:232:13)
at getDefaultService (selenium-webdriver/chrome.js:321:22)
at Function.createSession (selenium-webdriver/chrome.js:694:44)
at createDriver (selenium-webdriver/index.js:155:33)
at Builder.build (selenium-webdriver/index.js:662:16)
at buildDriver (jest-environment-selenium/dist/index.js:73:17)
at WebdriverEnvironment.setup (jest-environment-selenium/dist/index.js:39:32)

selenium-side-runner使用jest-environment-selenium包,并使用以下代码调用setup方法

async setup() {
    await super.setup();
    this.global.driver = await buildDriver(this.configuration);
  }

现在configuration正在使用jest通过,并且在package.json的动态生成的测试文件中存在

Config

如您所见,配置已通过。现在,我们来看一下jest-environment-seleniumbuildDriver函数

async function buildDriver(configuration) {
  const driver = new _seleniumWebdriver2.default.Builder().withCapabilities(configuration.capabilities);

  if (configuration.server) driver.usingServer(configuration.server);
  if (configuration.proxyType) {
    let prxy;
    if (configuration.proxyType === 'socks') {
      prxy = _proxy2.default.socks(configuration.proxyOptions.socksProxy, configuration.proxyOptions.socksVersion);
    } else {
      prxy = _proxy2.default[configuration.proxyType](configuration.proxyOptions);
    }
    driver.setProxy(prxy);
  }

  return driver.build();
}

驱动程序确实使用withCapabilities(configuration.capabilities)进行了初始化,功能也具有驱动程序路径,但是看来webdriver不会执行这些选项。启动器需要完成所有工作

如果我更新如下功能

async function buildDriver(configuration) {
  const driver = new _seleniumWebdriver2.default.Builder().withCapabilities(configuration.capabilities);

  if (configuration.server) driver.usingServer(configuration.server);
  if (configuration.proxyType) {
    let prxy;
    if (configuration.proxyType === 'socks') {
      prxy = _proxy2.default.socks(configuration.proxyOptions.socksProxy, configuration.proxyOptions.socksVersion);
    } else {
      prxy = _proxy2.default[configuration.proxyType](configuration.proxyOptions);
    }
    driver.setProxy(prxy);
  }

  if (configuration.capabilities && configuration.capabilities.chromeOptions) {
    var options = new _chrome.Options()
    var service = new _chrome.ServiceBuilder(configuration.capabilities.chromeOptions.binary || null)
    driver.setChromeService(service)
  }
  return driver.build();
}

现在测试开始工作。 jest-environment-selenium的仓库位于下面

https://github.com/applitools/jest-environment-selenium

您可以报告并讨论该问题。同时,可以通过运行以下命令来解决该问题

$ PATH=/Users/davea/Documents/workspace/starter_project/selenium/:$PATH selenium-side-runner -c "browserName=firefox" myTest.side