如何运行selenium-side-runner对Firefox进行测试? [英] How do I run my selenium-side-runner to execute my test against Firefox?

查看:108
本文介绍了如何运行selenium-side-runner对Firefox进行测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  capabilities :
chromeOptions:
二进制文件:'/ Users / davea / Documents / workspace / starter_project / selenium / chromedriver_mac'
firefoxOptions:
二进制文件:'/ Users / davea / Documents / workspace / starter_project / selenium / geckodriver_mac'

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

  localhost:selenium davea $ selenium-side-runner -c browserName = firefox myTest.side 
信息:运行myTest.side
失败./DefaultSuite.test.js
●测试套件无法运行

在当前PATH上找不到geckodriver可执行文件。请从https://github.com/mozilla/geckodriver/releases/下载最新版本,并确保可以在PATH中找到它。

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

测试套件:1个失败,总共1个

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

解决方案

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



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



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



更新时间:7月16日



<经过大量的调试之后,看来您遇到的是一个错误。因此,在新的ServiceBuilder(selenium-webdriver / chrome.js:232:13)出现的错误中

 很明显在getDefaultService处使用b $ b(selenium-webdriver / chrome.js:321:22)在Function.createSession处使用
(selenium-webdriver / chrome.js:694:44)在createDriver处使用
(selenium-webdriver / index.js:155:33)Builder.build中的
(selenium-webdriver / index.js:662:16)buildDriver中的
(jest-environment-selenium / dist / index.js:73: 17)WebdriverEnvironment.setup上的
(jest-environment-selenium / dist / index.js:39:32)

selenium-side-runner 使用 jest-environment-selenium 程序包并调用 setup 方法,下面的代码

  async setup(){
等待超级。建立();
this.global.driver =等待buildDriver(this.configuration);
}

现在,此配置使用 jest 传递,并且在运行中生成的测试文件的 package.json 中存在





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

 异步函数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 ===袜子){
prxy = _proxy2.default.socks(configuration.proxyOptions.socksProxy,configuration.proxyOptions.socksVersion);
} else {
prxy = _proxy2.default [configuration.proxyType](configuration.proxyOptions);
}
driver.setProxy(prxy);
}

返回driver.build();
}

驱动程序确实使用 withCapabilities(configuration。功能)和功能也具有驱动程序路径,但是 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 ===袜子){
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 


I just installed selenium-side-runner on Mac Mojave and am trying to run a test from the command line using a test I recorded in the IDE. My test file name is "myTest.side". I created a "myTest.side.yml" file to tell selenium-side-runner where my drivers are ...

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

However, when I try and run my tests, I'm getting this error ...

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

How do I run my test from the command line using Firefox?

解决方案

As commented earlier, the reason your code doesn't work is the file naming convention.

By default the selenium-side-runner will pick the file .side.yml and not <somename>.side.yml

So if you just rename the file, it should pickup the correct details for you

Update: 16th July

After lots of hours of debugging, it seems what you are experiencing is a bug. So what happens is quite visible in the error

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 use jest-environment-selenium package and calls the setup method with below code

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

Now this configuration is being passed using jest and is there in the package.json of the test files generated on the fly

As you can see the configuration is passed. Now if we look at the jest-environment-selenium and the buildDriver function

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();
}

The driver does get initiated with withCapabilities(configuration.capabilities) and the capabilites do have the driver path also, but it seems webdriver will do nothing of these options. The initiator needs do all the work

If I update the function like below

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();
}

And now the test starts working. The repo for jest-environment-selenium is available on below

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

You can report and discuss the issue. In the meantime can workaround the issue by running the command like below

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

这篇关于如何运行selenium-side-runner对Firefox进行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆