首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Mink+Behat:缺少会话

Mink+Behat:缺少会话
EN

Stack Overflow用户
提问于 2014-06-01 02:45:46
回答 1查看 2.3K关注 0票数 0

我只是在试着学习http://docs.behat.org/cookbook/behat_and_mink.html教程

我使用以下composer.json安装了Mink+Behat:

代码语言:javascript
运行
复制
    "require": {
        "behat/behat": "2.4.*@stable",
        "behat/mink": "1.4.*@stable",
        "behat/mink-extension": "*",
        "behat/mink-goutte-driver": "*",
        "behat/mink-selenium2-driver": "*"
    },
    "minimum-stability": "dev",
    "config": {
        "bin-dir": "bin/"
    }
}

我完成了创建features目录的init。

代码语言:javascript
运行
复制
bin/behat --init

我在search.features目录中创建了一个功能:

代码语言:javascript
运行
复制
Feature: Search
  In order to see a word definition
  As a website user
  I need to be able to search for a word

  Scenario: Searching for a page that does exist
    Given I am on "/wiki/Main_Page"
    When I fill in "search" with "Behavior Driven Development"
    And I press "searchButton"
    Then I should see "agile software development"

  Scenario: Searching for a page that does NOT exist
    Given I am on "/wiki/Main_Page"
    When I fill in "search" with "Glory Driven Development"
    And I press "searchButton"
    Then I should see "Search results"

我更新了特性/bootstrap/FeatureContext.php以扩展MinkContext。

如果我运行bin/behat -dl,我会看到加载了以下定义:

代码语言:javascript
运行
复制
Given /^(?:|I )am on (?:|the )homepage$/
 When /^(?:|I )go to (?:|the )homepage$/
Given /^(?:|I )am on "(?P<page>[^"]+)"$/
 When /^(?:|I )go to "(?P<page>[^"]+)"$/
 When /^(?:|I )reload the page$/
 When /^(?:|I )move backward one page$/
 When /^(?:|I )move forward one page$/
 When /^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/
 When /^(?:|I )follow "(?P<link>(?:[^"]|\\")*)"$/
 When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/
 When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with:$/
 When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/
 When /^(?:|I )fill in the following:$/
 When /^(?:|I )select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/
 When /^(?:|I )additionally select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/
 When /^(?:|I )check "(?P<option>(?:[^"]|\\")*)"$/
 When /^(?:|I )uncheck "(?P<option>(?:[^"]|\\")*)"$/
 When /^(?:|I )attach the file "(?P[^"]*)" to "(?P<field>(?:[^"]|\\")*)"$/
 Then /^(?:|I )should be on "(?P<page>[^"]+)"$/
 Then /^(?:|I )should be on (?:|the )homepage$/
 Then /^the (?i)url(?-i) should match (?P<pattern>"([^"]|\\")*")$/
 Then /^the response status code should be (?P<code>\d+)$/
 Then /^the response status code should not be (?P<code>\d+)$/
 Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/
 Then /^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)"$/
 Then /^(?:|I )should see text matching (?P<pattern>"(?:[^"]|\\")*")$/
 Then /^(?:|I )should not see text matching (?P<pattern>"(?:[^"]|\\")*")$/
 Then /^the response should contain "(?P<text>(?:[^"]|\\")*)"$/
 Then /^the response should not contain "(?P<text>(?:[^"]|\\")*)"$/
 Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/
 Then /^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/
 Then /^the "(?P<element>[^"]*)" element should contain "(?P<value>(?:[^"]|\\")*)"$/
 Then /^the "(?P<element>[^"]*)" element should not contain "(?P<value>(?:[^"]|\\")*)"$/
 Then /^(?:|I )should see an? "(?P<element>[^"]*)" element$/
 Then /^(?:|I )should not see an? "(?P<element>[^"]*)" element$/
 Then /^the "(?P<field>(?:[^"]|\\")*)" field should contain "(?P<value>(?:[^"]|\\")*)"$/
 Then /^the "(?P<field>(?:[^"]|\\")*)" field should not contain "(?P<value>(?:[^"]|\\")*)"$/
 Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should be checked$/
 Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" (?:is|should be) checked$/
 Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should not be checked$/
 Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" should (?:be unchecked|not be checked)$/
 Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" is (?:unchecked|not checked)$/
 Then /^(?:|I )should see (?P<num>\d+) "(?P<element>[^"]*)" elements?$/
 Then /^print current URL$/
 Then /^print last response$/
 Then /^show last response$/

但我尝试实际测试search.features时,我得到了错误:

代码语言:javascript
运行
复制
PHP Fatal error:  Call to a member function getSession() on a non-object in /home/nishant/behat/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 103

我在谷歌上搜索了一下可能的错误,但没有找到比告诉将behat.yml放在正确的位置更有用的东西。

我的bin/behat -> ../->/behat/behat/bin/behat就是这个符号链接,我尝试将behat.yml放在供应商/behat/behat/behat.yml中。behat.yml上的内容

代码语言:javascript
运行
复制
default:
    extensions:
        Behat\MinkExtension\Extension:
            base_url: http://en.wikipedia.org
            goutte: ~
            selenium2: ~

任何帮助都将不胜感激!

如果我转到vendor/behat/behat并创建search.feature并运行bin/behat,我会得到以下错误:

代码语言:javascript
运行
复制
  [ReflectionException]
  Class Guzzle\Http\Client does not exist
EN

回答 1

Stack Overflow用户

发布于 2014-06-01 04:00:20

好的..。我设法解决了我的问题!

在features/bootstrap/FeatureContext.php的__construct()方法中添加了这些行

代码语言:javascript
运行
复制
$clientOptions = array();
$client = new \Behat\Mink\Driver\Goutte\Client();
$client->setClient(new \Guzzle\Http\Client('', $clientOptions));
$driver = new \Behat\Mink\Driver\GoutteDriver($client);

我还将我的composer.json更新为

代码语言:javascript
运行
复制
{
    "require": {
        "behat/behat": "2.4.*@stable",
        "behat/mink": "1.4.*@stable",
        "behat/mink-extension": "*",
        "behat/mink-goutte-driver": "1.0.*",
        "behat/mink-selenium2-driver": "*",
        "guzzle/http": "*"
    },
    "minimum-stability": "dev",
    "config": {
        "bin-dir": "bin/"
    }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23973690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档