我试图使用一些关于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中使用FeatureContext,控制台会返回每个函数都声明了两次(至少,MincContext::PressButton,但如果问题发生在其他方面,我也不会感到惊讶)。
当我从behat.yml和FeatureContext中删除它时,它不会识别任何东西,并要求我定义这些函数,我想这是有意义的。
当我只在behat文件或FeatureContext文件中使用FeatureContext时,我会收到这样的错误:
没有在Mink上下文类上设置Mink实例。你启用Mink分机了吗?(RuntimeException)
我使用的是DMore Chrome驱动程序,因为我无法正确地使用Selenium运行Chrome,而且我觉得在构造函数中安装Mink会带来一些麻烦。
这是一种委婉的说法,说我完全不知道该做什么。
我该如何解决这个问题?
提前谢谢你
发布于 2018-02-05 07:46:38
您只需要extend MinkContext一次,否则每次扩展它时,它都会看到重复的步骤。
behat.yml的上下文之一已经扩展了MinkContext,因此您需要:
FeatureContext中扩展它或
FeatureContext不应该扩展MinkContext,而应该扩展RawMinkContexthttps://stackoverflow.com/questions/48584134
复制相似问题