我正在使用Behat进行一些自动测试,并添加了带有Goutte驱动程序的Mink。我正在使用最新版本的Behat和Mink。
我已经将Mink扩展添加到功能上下文文件中,当我运行一个简单的功能时,它就可以工作了,比如:
Feature:...
Scenario: See A Blog Post
Given I am on the homepage
And I follow "login"
Then I should be on "/login"
And I should see "Login"
然而,当我尝试下一步并尝试填写一些字段时:
And I fill in "username" with "admin"
其中用户名:
<input class="input-field" type="text" id="username"/>
我得到以下错误:
Malformed field path "" (InvalidArgumentException)
任何帮助都将不胜感激,
谢谢!
这是因为字段中没有name="username"
属性。我遇到了类似的问题,但我正在尝试测试一个不能具有名称属性的Stripe实例。id
和title
似乎不工作。
勾选的答案为我解决了这个问题。
我还发现你可以使用以下语法填写表格:
When I fill in the following:
| username | admin |
| email | myemail@domain.com |
| password | 5uP3r5ecUr3P4s5w0rD|
我还创建了一个自定义FeatureContext函数来帮助查找其他元素:
protected function findElementBySelector($selector)
{
$page = $this->getSession()->getPage();
$element = $page->find('css', $selector);
if (null === $element) {
throw new 'Exception(
sprintf('Element with %s not found.', $selector));
}
return $element;
}
其他人使用此功能来查找元素并对其执行操作:
/**
* @Then I click the element :selector
*/
public function iClickTheElement($selector)
{
$link = $this->findElementBySelector($selector);
$link->click();
}
我在我的.功能中使用了这个:
And I ...
And I click the element ".my-link"
Then I ...
其中.my链接=<a href="http://domain.com" class="my-link">My Link</a>
下面的链接帮助创建了我的自定义FeatureContext函数:http://mink.behat.org/en/latest/guides/traversing-pages.html