【发布时间】:2018-02-02 13:51:54
【问题描述】:
我正在尝试围绕 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,控制台会告诉我每个函数都被声明了两次(至少,MincContext::PressButton,但如果问题发生我不会感到惊讶用别的东西)
当我从 behat.yml 和 FeatureContext 中删除它时,它无法识别任何内容,并要求我定义这些函数,我猜这很有意义。
当我仅在 behat 文件或 FeatureContext 文件中使用 MinkContext 时,我收到一条错误消息:
Mink 实例尚未在 Mink 上下文类中设置。您是否启用了 Mink 扩展程序? (运行时异常)
我正在使用 DMore Chrome 驱动程序,因为我无法正确运行带有 Selenium 的 Chrome,而且我觉得在构造函数中实例化 Mink 会造成一些麻烦。
委婉地说,我完全不知道应该做什么。
我该如何解决这个问题?
提前谢谢你
【问题讨论】: