2016-01-23 156 views
5

我使用JavaScript驗證表單,我想測試驗證消息,因爲消息是少數語言的。然而,貝哈特拋出一個異常Behat測試驗證消息

無法打開連接:捲曲拋出錯誤HTTP POST到

http://localhost:4444/wd/hub/session使用參數: { 「desiredCapabilities」:{ 「標籤」:「流浪的Ubuntu的,值得信賴-32「,」PHP 7.0.1-2 + deb.sury.org〜trusty + 1「],」browser「:」firefox「,」ignoreZoomSetting「:false,」name「:」Behat feature suite「, 「browserName」:「firefox」}}

無法連接到本地主機端口4444:連接被拒絕(Behat \ Mink \ Exception \ DriverException)

特點:驗證形式接觸 在接觸形式看到驗證信息

@javascript 
    Scenario: Message validation in english lang 
    Given I am on "/" 
    When I fill in "name" with "behat" 
    And I fill in "email" with "[email protected]" 
    And I fill in "phone" with "111222333" 
    And I fill in "message" with "That test message, send via Behat." 
    When I press "Send Message" 
    Then I wait for the suggestion box to appear 
    Then I should see "Your message has been sent." 

類FeatureContext擴展MinkContext {

public function __construct() 
{ 
} 


/** 
* @Then /^I wait for the suggestion box to appear$/ 
*/ 
public function iWaitForTheSuggestionBoxToAppear() 
{ 
    $this->getSession->wait(5000, false); 
} 




default: 
extensions: 
    Behat\MinkExtension: 
    goutte: ~ 
    base_url: 'http://localhost.dev/' 
    javascript_session: selenium2 
    browser_name: firefox 
    selenium2: ~ 

我應該如何測試這種情況下?

回答

1

只是一個簡單的問題,你是否已經在端口4444上啓動了WebDriver?

因爲我只是通過關閉我的chromedriver來複製出錯。

 [Behat\Mink\Exception\DriverException]                                                                              
    Exception has been thrown in "beforeScenario" hook, defined in FeatureContext::windowSizeChange()                                                               
    Could not open connection: Curl error thrown for http POST to http://127.0.0.1:9515/session with params: {"desiredCapabilities":{"browserName":"chrome","version":"8","platform":"ANY","browserVersion":"8","browser":"firefox","name":"Behat test","deviceOrientation":"portrait","deviceType":"tablet","selenium-version":"2.31.0","max-duration":300}} 
    Failed to connect to 127.0.0.1 port 9515: Connection refused 

    [WebDriver\Exception\CurlExec]                                                                         
    Curl error thrown for http POST to http://127.0.0.1:9515/session with params: {"desiredCapabilities":{"browserName":"chrome","version":"8","platform":"ANY","browserVersion":"8","browser":"firefox","name":"Behat test","deviceOrientation":"portrait","deviceType":"tablet","selenium-version":"2.31.0","max-duration":300}} 
    Failed to connect to 127.0.0.1 port 9515: Connection refused  

硒的webdriver:java -jar selenium-server-standalone-<versionNumber>.jar -port 4444

對於chromedriver:chromedriver --port=4444

對於operadriver:operadriver --port=4444

而且也,是這一細分市場中的FeatureContext.php?

default: extensions: Behat\MinkExtension: goutte: ~ base_url: 'http://localhost.dev/' javascript_session: selenium2 browser_name: firefox selenium2: ~

因爲如果是,它是在錯誤的地方,需要在你的behat.yml文件。

0

您可以使用默認的鉻驅動程序爲最新的硒,它將只支持鉻瀏覽器。

放於behat.yml

default: 
    autoload: 
    '': %paths.base%/features/bootstrap 
    extensions: 
    Behat\MinkExtension: 
     base_url: your url 
     default_session: selenium2 
     files_path: features/Resources 
     show_cmd: 'open %s' 
     selenium2: 
     browser: chrome 
     wd_host: http://localhost:4444/wd/hub 

使用您的硒最後一個版本應該是52.3

0

我嘗試了很多選項來解決這個問題,但對我來說這是chromedriver版本。 我終於設法通過從http://www.seleniumhq.org/download/下載正確版本的chromedriver來解決它,因爲我擁有的那個版本並不好。