【问题标题】:"PHPUnit_Extensions_Selenium2TestCase_WebDriverException: sendKeysToActiveElement" when sending keys to a form in Selenium2 and PHP“PHPUnit_Extensions_Selenium2TestCase_WebDriverException: sendKeysToActiveElement”将密钥发送到 Selenium2 和 PHP 中的表单时
【发布时间】:2017-11-07 17:04:06
【问题描述】:

我正在做一个 PHPUnit 驱动的 Selenium2 测试用例。我正在填写表格。

一切正常的情况 - 绿条:

这是设置:

protected function setUp()
{
    $this->setBrowser( 'firefox' );
    $this->setBrowserUrl( 'http://my.nice.project/' );
}

通过这个测试用例,我得到一个“好的,绿色条”:

public function testLogin()
{
    $this->url( 'http://my.nice.project/' );

    $element = $this->byTag( 'h5' );
    $this->assertEquals( 'Access to the private area', $element->text() );

    $element = $this->byCssSelector( 'form input[name="email"]' );
    $element->click();
    //$this->keys( 'abc' );
}

请注意,->keys( 'abc' ) 已被注释掉。

为了测试工具链是否正常,我添加了第二个临时测试:

public function testToolchain()
{
    $this->url( 'http://example.com/' );
    $element = $this->byTag( 'p' );

    $this->assertContains( 'illustrative examples in documents', $element->text() );
}

如前所述,我得到:

vagrant@global-functional-tests:/vagrant$ vendor/bin/phpunit
PHPUnit 5.7.20 by Sebastian Bergmann and contributors.

..                                                                  2 / 2 (100%)

Time: 23.02 seconds, Memory: 4.00MB

OK (2 tests, 2 assertions)

工具链正在运行,因为如果我在两个测试中的任何一个中更改预期文本,我都会失败。因此,selenium 必然会启动 firefox、控制它、获取页面并探索内容。

问题

当我发送密钥时,使用此测试(这是前一个未注释行的测试):

public function testLogin()
{
    $this->url( 'http://my.nice.project/' );

    $element = $this->byTag( 'h5' );
    $this->assertEquals( 'Access to the private area', $element->text() );

    $element = $this->byCssSelector( 'form input[name="email"]' );
    $element->click();
    $this->keys( 'abc' );
}

我得到一个类型的异常:PHPUnit_Extensions_Selenium2TestCase_WebDriverException => 这是完整的phpunit 输出:

vagrant@global-functional-tests:/vagrant$ vendor/bin/phpunit
PHPUnit 5.7.20 by Sebastian Bergmann and contributors.

.E                                                                  2 / 2 (100%)

Time: 24.24 seconds, Memory: 4.00MB

There was 1 error:

1) Bibloos\MarmaladeDoughnut\Tests\NewPrivateZoneTest::testLogin
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: sendKeysToActiveElement
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'global-functional-tests', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-21-generic', java.version: '9-internal'
Driver info: driver.version: RemoteWebDriver

/vagrant/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Driver.php:165
/vagrant/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Driver.php:175
/vagrant/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/CommandsHolder.php:100
/vagrant/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:393
/vagrant/tests/NewPrivateZoneTest.php:48
/vagrant/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:348
/vagrant/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:314

ERRORS!
Tests: 2, Assertions: 2, Errors: 1.

问题:

  1. 如何调试正在发生的事情?
  2. 如何使驱动程序可以将密钥发送到表单?
  3. 也许要填写表单,我应该使用与单击元素和发送键不同的方法?

【问题讨论】:

    标签: forms selenium-webdriver phpunit functional-testing selenium-firefoxdriver


    【解决方案1】:

    第一个建议 - 您使用的 PHPUnit_Extensions_Selenium2 库不是最新的 Selenium 协议的最新更改(它也不再是 Selenium 2 - 当前的 Selenium 版本是 3.4.0),尤其是 Firefox 48+ 的更改和Geckodriver

    所以我建议改用 facebook/php-webdriver 库,因为它使用 Selenium 协议维护得更好并且是最新的。

    lmc-eu/steward 项目也很有用,它将 php-webdriver 库集成到 PHPUnit。另请参阅自述文件中的“Getting started”部分,该部分解释了如何设置您的系统以在不同的浏览器(或 Docker)中运行 Selenium 测试。

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-05
      • 1970-01-01
      • 2015-04-07
      • 1970-01-01
      相关资源
      最近更新 更多