【问题标题】:Cannot call a command with multiple method arguments无法调用具有多个方法参数的命令
【发布时间】:2016-11-01 20:59:44
【问题描述】:

每次我尝试使用基本的 PHPUnit Selenium 断言之一时,测试都会出错并显示以下消息:

Exception: You cannot call a command with multiple method arguments.

http://phpunit.de/manual/3.7/en/selenium.html,它显示的用法是:

void assertElementValueEquals(string $locator, string $text)

当我打电话给它时

$this->assertElementValueEquals( 'id=date_1_formatted', '2013-01-01' );

测试每次都会产生上述错误,即使这种相同的格式似乎适用于其他格式,例如问题Using PHPUnit with Selenium, how can I test that an element contains exactly something?

【问题讨论】:

  • 我建议尝试'#date_1_formatted'"[id='date_1_formatted']"
  • 感谢您的建议,但每个建议仍然会产生相同的错误。
  • 我找不到任何明确指出 $locator 应该是什么的特定文档,但它可能只接受 xpath。在这种情况下,我会尝试"//[@id='date_1_formatted']"
  • 没有区别。我在 try/catch 块中使用 $this->byXPath( '//input[@value="2013-01-01"]' ) 来确定是否存在具有该值的元素。这不是一个好方法,但它现在有效。

标签: php unit-testing selenium phpunit


【解决方案1】:

assertElementValueEquals 未在 Selenium2TestCase 中实现。在您的链接中提到了 SeleniumTestCase(Selenium RC 版本)。

此外,您在 $this->byXPath 中使用了正确的结构,例如 https://github.com/sebastianbergmann/phpunit-selenium/blob/master/Tests/Selenium2TestCaseTest.php

你也可以使用$this->byId()

$element = $this->byId('date_1_formatted');
$this->assertEquals('2013-01-01', $element->value());

P。 S.:如果你熟悉 Selenium IDE,可以试试这个command line tool

【讨论】:

  • 如果您想获取包含在开始和结束标签之间的值,例如在<a href="example.com">Hello</a> 中获取Hello,请使用$element->text(),假设$elementa 元素。
【解决方案2】:

也走进了这个,在我的情况下,这是我自己的自定义方法,所以我认为这是一条线。
原来我在测试类和 phpunit 之间使用的“缓冲区”类与我想象的不同。但是因为它使用了很多 __call(),所以它给了 ↑ 那个错误而不是“未定义的方法”。

【讨论】:

    猜你喜欢
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多