我正在使用Behat做一些自动测试,我增加了Mink和它的Goutte驱动程序。我用的是最新版本的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)任何帮助都会很感激,
谢谢!
发布于 2015-02-28 19:03:18
这是因为您的字段中没有name="username"属性。我有一个类似的问题,但我试图测试一个Stripe实例,您不能拥有名称属性。id和title似乎不起作用。
发布于 2016-04-18 20:47:24
滴答声帮我解决了这个问题。
我还发现您可以使用以下语法填写表单:
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();
}我在我的.feature中像这样使用了这个:
And I ...
And I click the element ".my-link"
Then I ...其中..my link= <a href="http://domain.com" class="my-link">My Link</a>
下面的链接帮助创建了我的自定义FeatureContext函数:http://mink.behat.org/en/latest/guides/traversing-pages.html
https://stackoverflow.com/questions/28763826
复制相似问题