【发布时间】: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.
问题:
- 如何调试正在发生的事情?
- 如何使驱动程序可以将密钥发送到表单?
- 也许要填写表单,我应该使用与单击元素和发送键不同的方法?
【问题讨论】:
标签: forms selenium-webdriver phpunit functional-testing selenium-firefoxdriver