Selenium2 phpunit提交表单等待页面加载
我正在尝试运行一个测试,其中提交了一个空白表单,等待10秒以确保页面已重新加载,然后检查是否出现错误消息 我用的是硒,一开始就是硒Selenium2 phpunit提交表单等待页面加载,phpunit,selenium-webdriver,Phpunit,Selenium Webdriver,我正在尝试运行一个测试,其中提交了一个空白表单,等待10秒以确保页面已重新加载,然后检查是否出现错误消息 我用的是硒,一开始就是硒 java -jar /usr/local/bin/selenium-server-standalone-2.25.0.jar 我有一些测试,以确保字段存在,例如 public function testEmailFieldIsPresentById() { $element = $this->byCssSelector('#email'); $this-&g
java -jar /usr/local/bin/selenium-server-standalone-2.25.0.jar
我有一些测试,以确保字段存在,例如
public function testEmailFieldIsPresentById()
{
$element = $this->byCssSelector('#email');
$this->assertEquals(1, count($element));
}
根据我读过的不同文章,我尝试了不同的函数调用,但两者都不起作用
这就是我迄今为止两次尝试等待的结果
<?php
class LoginFormSubmitTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost/login');
}
public function testWithAllBlankFields()
{
// Submit the form
$this->byId('recording-form-login')->submit();
// Wait 10 seconds
//$this->waitForPageToLoad(10000);
//$this->timeouts()->implicitWait(10000);
}
}
我找到了两个很好的教程,它们解释了我们需要的是一个用于PHP的Selenium API的包装器
http://edvanbeinum.com/using-selenium-2-phpunit-to-automate-browser-testing
从我的代码中下载包装后,现在看起来如下所示,并捕获了tearDown函数失败时的屏幕截图
<?php
// Include the Facebook PHP Webdriver init file
require_once '../php-webdriver/__init__.php';
class loginFormSubmitTest extends PHPUnit_Framework_TestCase {
/**
* @var WebDriverSession
*/
protected $_session;
public function setUp()
{
parent::setUp();
$web_driver = new WebDriver();
$this->_session = $web_driver->session();
}
public function tearDown()
{
// Get the status of the test
$status = $this->getStatus();
// Check if the status has an error or a failure
if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
// Take a screenshot
$image_data = base64_decode($this->_session->screenshot());
file_put_contents(date('Y-m-d-H-i-s') . '.png', $image_data);
}
$this->_session->close();
unset($this->_session);
parent::tearDown();
}
public function test_submit_form_with_all_blank_fields()
{
$this->_session->open('http://localhost/login');
$this->_session->element(
'id',
'recording_form_login_submit'
)->click();
$email_label_span_text = $this->_session->element('css selector', '#recording-form-login label[for="email"] span')->text();
$this->assertSame(
'Required',
$email_label_span_text
);
}
}
语句
$this->setBrowserUrl('http://localhost/login');
实际上没有打开网页。setBrowserUrl==设置测试的基本URL
这应该适合您-请注意额外的一行$This->url('http://localhost/login');强>
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost/');
}
public function testWithAllBlankFields()
{
$this->url('http://localhost/login');
// Submit the form
$this->byId('recording-form-login')->submit();
// Wait 10 seconds
//$this->waitForPageToLoad(10000);
//$this->timeouts()->implicitWait(10000);
}
这里的打开方法是Selenium 1,相当于Selenium 2中的url方法