Behat + mink + Selenium2 + chromeDriver:不要启动chrome浏览器

时间:2015-10-01 06:13:30

标签: selenium-webdriver selenium-chromedriver behat

我使用的是ubuntu 14.4。

当我运行测试时,它可以正常使用firefox,它会启动FF浏览器。

但是当我尝试使用Chrome时,测试会运行,但不会启动浏览器。

composer.json

{
    "require": {
    "behat/behat": "2.4.*@stable",
    "behat/mink": "1.5.*@stable",
    "behat/mink-goutte-driver": "*",
    "behat/mink-extension": "*",
    "behat/mink-selenium2-driver": "*"
    }
}

behat.yml

default:
 paths:
  features: features
  bootstrap: %behat.paths.features%/bootstrap
 extensions:
  Behat\MinkExtension\Extension:
    base_url:  'path-to-my-site'
    default_session: selenium2
    browser_name: 'chrome'
    goutte: ~
    selenium2:
        wd_host: "http://127.0.0.1:4444/wd/hub"

启动Selenium Server的命令

java -jar /path-to/selenium-server-standalone-2.47.1.jar -Dwebdriver.chrome.driver="/usr/local/share/chromedriver"

这是我上面命令的输出:

11:27:46.064 INFO - Launching a standalone Selenium Server
Setting system property webdriver.chrome.driver to /usr/local/share/chromedriver
11:27:46.101 INFO - Java: Oracle Corporation 24.72-b04
11:27:46.101 INFO - OS: Linux 3.13.0-32-generic amd64
11:27:46.113 INFO - v2.47.1, with Core v2.47.1. Built from revision 411b314
11:27:46.181 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match the current platform LINUX
11:27:46.182 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver registration is skipped:
registration capabilities Capabilities [{platform=WINDOWS, browserName=MicrosoftEdge, version=}] does not match the current platform LINUX
11:27:46.182 INFO - Driver class not found: com.opera.core.systems.OperaDriver
11:27:46.182 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
11:27:46.249 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
11:27:46.249 INFO - Selenium Server is up and running

Behat测试命令:

vendor/bin/behat

behat测试的输出

Feature: Home page
    I am on a home page

  Scenario: Visit homepage                       # features/test.feature:4
    Given I go to "home.html"                    # FeatureContext::visit()
    Then I should see "We can change the world!" # FeatureContext::assertPageContainsText()
    Then I follow "Register"                     # FeatureContext::clickLink()

1 scenario (1 passed)
3 steps (3 passed)

问题是测试工作,但Chrome浏览器未启动。我做错了什么?

1 个答案:

答案 0 :(得分:4)

您应该在方案之前添加@javascript标记,因为默认情况下使用的是goutte会话,而不使用selenium webdriver。有关Goutte driver

的更多信息
@javascript
Scenario: Visit homepage

或者behat.yml将默认会话设置为selenium2

extensions:
    Behat\MinkExtension\Extension:
      default_session: selenium2

但在那之后behat将启动firefox浏览器,特别是chrome启动 - 您应该添加browser_name: chrome选项

extensions:
    Behat\MinkExtension\Extension:
      browser_name: chrome

此外,您还应为wd_host配置参数

指定selenium2参数
extensions:
    Behat\MinkExtension\Extension:
      selenium2:
            wd_host: "http://127.0.0.1:4444/wd/hub"