有没有办法告诉SeleniumRunner驾驶员在哪里使用命令行?

时间:2019-07-09 20:26:06

标签: selenium command-line environment-variables selenium-chromedriver

我刚刚在Mac(Mojave)上安装了Selenium Runner,但稍后我还将在CentOS 7上运行它。当我从命令行运行chromedriver时,有什么方法可以告诉我的进程chromedriver的路径吗?目前,我正在这样运行...

/usr/local/bin/selenium-side-runner /tmp/0ba4e59f-53d5-43ff-b7ff-127499868cf3.side

但收到此错误

  ● Test suite failed to run

    The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver from http://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.

在阅读了https://www.seleniumhq.org/selenium-ide/docs/en/introduction/command-line-runner/的说明之后,有很多关于在PATH环境变量中添加驱动程序路径的讨论。但是,我从一个无法访问我的PATH的单独进程运行脚本,因此我想对如何告诉Selnium Runner驱动程序在哪里有更多的控制。

编辑:使用塔伦解决方案,我得到以下奇怪的结果...

localhost:selenium davea$ selenium-side-runner  -c "chromeOptions.binary='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'" myTestFile.side
info:    Running myTestFile.side
 FAIL  ./DefaultSuite.test.js
  ● Test suite failed to run

    TypeError: Target browser must be a string, but is <undefined>; did you forget to call forBrowser()?

编辑2:

“。side.yml”文件的内容以及chromedriver的路径...

localhost:selenium davea$ cat .side.yml 
capabilities:
  browserName: 'chrome'
  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$ ls -al /Users/davea/Documents/workspace/starter_project/selenium/chromedriver_mac
-rwxr-xr-x 1 davea staff 14994520 Jun 11 19:42 /Users/davea/Documents/workspace/starter_project/selenium/chromedriver_mac

但是我仍然得到相同的结果,抱怨找不到驱动器...

localhost:selenium davea$ selenium-side-runner myTestSpike.side 
info:    Running myTestSpike.side
 FAIL  ./DefaultSuite.test.js
  ● Test suite failed to run

    The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver from http://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.

3 个答案:

答案 0 :(得分:2)

您可以尝试 ChromeOptions类。您可以创建ChromeOptions实例,该实例提供了用于设置ChromeDriver特定功能的便捷方法。

// Create ChromeOptions instance
ChromeOptions options = new ChromeOptions();

// Set your custom path of the chrome driver to the options
options.setBinary("/path/to/chrome/binary");

// Pass the options object to the ChromeDriver instance
ChromeDriver driver = new ChromeDriver(options);

从Selenium版本3.6.0开始,Java中的ChromeOptions类还实现了Capabilities接口,允许您指定其他特定于ChromeDriver的WebDriver功能。

ChromeOptions options = new ChromeOptions();
// Add the WebDriver proxy capability.
Proxy proxy = new Proxy();
proxy.setHttpProxy("myhttpproxy:3337");
options.setCapability("proxy", proxy);

// Add a ChromeDriver-specific capability.
options.addExtensions(new File("/path/to/extension.crx"));
ChromeDriver driver = new ChromeDriver(options);

请通过此链接查看更多选项 Capabilities & ChromeOptions

请参阅此链接Command line runner

Chrome特定功能 如果您将Chrome安装在计算机的非标准位置,则可以指定路径,以便ChromeDriver知道要查找的位置。

selenium-side-runner -c "chromeOptions.binary='/path/to/non-standard/Chrome/install'"

借助Chrome特定功能,您也可以无头运行测试。

selenium-side-runner -c "chromeOptions.args=[disable-infobars, headless]"

答案 1 :(得分:0)

如果您看到他们的自述文件,他们会指定如何做

https://www.npmjs.com/package/selenium-side-runner

selenium-side-runner -c "chromeOptions.binary='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'"

您甚至可以创建一个.side.yml并在其中保存选项

capabilities:
  browserName: 'chrome'
  chromeOptions:
    binary: '/path/to/chromedriver'

在与此相关的另一个问题中查看我的更新

How do I run my selenium-side-runner to execute my test against Firefox?

答案 2 :(得分:0)

如果您在Shell中运行,则可以设置一个env变量,该变量将传递到您运行的进程中。所以只要这样做:

env "webdriver.chrome.driver=/path/to/chromedriver" /usr/local/bin/selenium-side-runner /tmp/0ba4e59f-53d5-43ff-b7ff-127499868cf3.side