首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >该步骤已经声明,或者Mink实例尚未在Mink上下文类上设置。

该步骤已经声明,或者Mink实例尚未在Mink上下文类上设置。
EN

Stack Overflow用户
提问于 2018-02-02 13:51:54
回答 1查看 492关注 0票数 0

我试图使用一些关于Drupal项目的测试(但是Behat已经退出了),但是我在Mink和它的会话上遇到了麻烦,我必须承认我不知道我在做什么。

到目前为止,这是我的档案:

FeatureContext.php

代码语言:javascript
复制
use Drupal\DrupalExtension\Context\RawDrupalContext; #not used
use Behat\Mink\Exception\ExpectationException;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Mink\Exception\ElementNotFoundException;
use Behat\Mink\Session;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Behat\Context\Context; #not used
use Behat\Mink\Mink;
use DMore\ChromeDriver\ChromeDriver;


/**
 * Defines application features from the specific context.
 */
class FeatureContext extends MinkContext implements SnippetAcceptingContext {

  protected $mink;

  /**
   * FeatureContext constructor.
   * Initializes context.
   * PLEASE NOTE THAT I'M NOT SURE ABOUT THIS, BUT IT SEEMS TO WORK SO FAR
   * Every scenario gets its own context instance.
   * You can also pass arbitrary arguments to the
   * context constructor through behat.yml.
   */
  public function __construct() {
    $this->mink = new Mink(array(
      'browser' => new Session(new ChromeDriver('http://localhost:9222', null, 'http://www.website.rec'))
    ));

  // The rest of my custom functions

  }
}

behat.yml

代码语言:javascript
复制
default:
  suites:
    default:
      contexts:
      - FeatureContext
      - Drupal\DrupalExtension\Context\DrupalContext
      - Drupal\DrupalExtension\Context\MinkContext
      - Drupal\DrupalExtension\Context\MessageContext
      - Drupal\DrupalExtension\Context\DrushContext
    extensions:
      DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~
      Behat\MinkExtension:
        browser_name: chrome
        base_url: http://www.spheria.rec
        sessions:
          default:
            chrome:
              api_url: http://localhost:9222

    Drupal\DrupalExtension:
      blackbox: ~

test.feature

代码语言:javascript
复制
Feature: Sample feature
    Scenario: Arrived on website, checking out what's around me
      Given I am an anonymous user
      And I go to "/"
      And I should see "Se connecter"
      And I should see "Nom d'utilisateur"
      And I should see "Mot de passe"
      When I fill in "admin@spheria.com" for "name"
      And I fill in "admin" for "pass"
      And I press "Se connecter"
      Then I should get a 200 HTTP response
      And the url should match "/dashboard"
      And I should see "Tableau de bord"

我的问题是,如果我在behat文件和FeatureContext中使用FeatureContext,控制台会返回每个函数都声明了两次(至少,MincContext::PressButton,但如果问题发生在其他方面,我也不会感到惊讶)。

当我从behat.yml和FeatureContext中删除它时,它不会识别任何东西,并要求我定义这些函数,我想这是有意义的。

当我只在behat文件或FeatureContext文件中使用FeatureContext时,我会收到这样的错误:

没有在Mink上下文类上设置Mink实例。你启用Mink分机了吗?(RuntimeException)

我使用的是DMore Chrome驱动程序,因为我无法正确地使用Selenium运行Chrome,而且我觉得在构造函数中安装Mink会带来一些麻烦。

这是一种委婉的说法,说我完全不知道该做什么。

我该如何解决这个问题?

提前谢谢你

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-05 07:46:38

您只需要extend MinkContext一次,否则每次扩展它时,它都会看到重复的步骤。

behat.yml的上下文之一已经扩展了MinkContext,因此您需要:

  1. 删除该类并在FeatureContext中扩展它

  1. 您的FeatureContext不应该扩展MinkContext,而应该扩展RawMinkContext
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48584134

复制
相关文章

相似问题

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