该步骤已声明或 Mink 实例尚未在 Mink 上下文中设置 class
Either the step is already declared or Mink instance has not been set on Mink context class
我正在尝试围绕 Drupal 项目进行一些测试(但 Behat 不在其中),但是我在 Mink 及其会话方面遇到了麻烦,我必须承认我对我的内容一无所知正在做。
到目前为止,这是我的文件:
FeatureContext.php
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
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
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 中使用 MinkContext,控制台 returns 我发现每个函数都被声明了两次(至少,MincContext::PressButton
但我不会如果问题会发生在其他事情上,请不要感到惊讶)
当我将它从 behat.yml
和 FeatureContext 中删除时,它无法识别任何东西,并要求我定义这些函数,我想这是有道理的。
当我只在 behat 文件或 FeatureContext 文件中使用 MinkContext 时,我收到一条错误消息:
Mink instance has not been set on Mink context class. Have you enabled the Mink Extension? (RuntimeException)
我正在使用 DMore Chrome 驱动程序,因为我无法正确使用 Selenium 运行 Chrome,而且我感觉在构造函数中实例化 Mink 正在创建一些烦恼。
委婉地说,我完全不知道我应该做什么。
我该如何解决这个问题?
提前致谢
您只需 extend MinkContext
一次,否则每次扩展时都会看到重复的步骤。
来自 behat.yml
的上下文之一已经在扩展 MinkContext
因此您需要:
- 删除 class 并在您的
FeatureContext
中扩展它
或
- 你的
FeatureContext
不应该扩展MinkContext
而是RawMinkContext
我正在尝试围绕 Drupal 项目进行一些测试(但 Behat 不在其中),但是我在 Mink 及其会话方面遇到了麻烦,我必须承认我对我的内容一无所知正在做。
到目前为止,这是我的文件:
FeatureContext.php
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
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
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 中使用 MinkContext,控制台 returns 我发现每个函数都被声明了两次(至少,MincContext::PressButton
但我不会如果问题会发生在其他事情上,请不要感到惊讶)
当我将它从 behat.yml
和 FeatureContext 中删除时,它无法识别任何东西,并要求我定义这些函数,我想这是有道理的。
当我只在 behat 文件或 FeatureContext 文件中使用 MinkContext 时,我收到一条错误消息:
Mink instance has not been set on Mink context class. Have you enabled the Mink Extension? (RuntimeException)
我正在使用 DMore Chrome 驱动程序,因为我无法正确使用 Selenium 运行 Chrome,而且我感觉在构造函数中实例化 Mink 正在创建一些烦恼。
委婉地说,我完全不知道我应该做什么。
我该如何解决这个问题?
提前致谢
您只需 extend MinkContext
一次,否则每次扩展时都会看到重复的步骤。
来自 behat.yml
的上下文之一已经在扩展 MinkContext
因此您需要:
- 删除 class 并在您的
FeatureContext
中扩展它
或
- 你的
FeatureContext
不应该扩展MinkContext
而是RawMinkContext