【问题标题】:Malformed field path "" (InvalidArgumentException)格式错误的字段路径“”(InvalidArgumentException)
【发布时间】:2015-04-30 02:12:00
【问题描述】:

我正在使用 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)

任何帮助将不胜感激,

谢谢!

【问题讨论】:

  • 你解决了这个问题吗?解决方案是什么?刚刚遇到这个问题,同时遇到了同样的问题。

标签: php behat automated-tests mink goutte


【解决方案1】:

这是因为您的字段中没有name="username" 属性。我遇到了类似的问题,但我正在尝试测试一个不能具有名称属性的 Stripe 实例。 idtitle 似乎不起作用。

【讨论】:

  • 您找到解决方法了吗?
【解决方案2】:

勾选的答案为我解决了这个问题。

我还发现您可以使用以下语法填写表格:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-28
    相关资源
    最近更新 更多