[英]PHPUnit with selenium
我正在嘗試將PHPUnit與Selenium一起使用
我啟動服務器java -jar c:/xampp/selenium-server-standalone-2.18.0.jar
這是我的考驗
require_once 'PHPUnit/Extensions/Selenium2TestCase.php';
class WebTest extends PHPUnit_Extensions_Selenium2TestCase {
protected function setUp() {
$this->setBrowser("*chrome");
$this->setBrowserUrl("http://localhost/");
}
public function testMyTestCase() {
$this->url('my/url/index.php');
$link = $this->byId('1-m-0');
$this->assertEquals('11', $link->text());
}
}
頁面上存在id =“ 1-m-0”的項目,但測試失敗,因為它獲取的元素為null。 我已經嘗試過其他元素,SeleniumTestCase類(與同一台服務器一起使用),但是沒有運氣!
我做錯了什么?
好的,找到了。 現在這是我的課:
class WebTest extends PHPUnit_Extensions_SeleniumTestCase {
protected function setUp() {
$this->setBrowser("*firefox");
$this->setBrowserUrl("http://localhost/");
}
public function testPlay() {
$this->open('http://localhost/my/url/index.php');
$this->waitForPageToLoad(4000);
// Wait for ajax to load
$this->waitForCondition("selenium.browserbot.getCurrentWindow().$('#mytable').length > 0");
$ids = array(
'1-m-0',
'2-n-1',
);
// Click ids
foreach ($ids as $v) {
$xpath = "xpath=//button[@id='{$v}']";
$this->assertElementPresent($xpath);
$this->click($xpath);
}
}
}
本文對我有幫助: http : //devzone.zend.com/1014/acceptance-testing-of-web-applications-with-php/
我正在使用以下硒服務器:selenium-server-standalone-2.18.0.jar
如果您發現phpunit庫有些混亂,我們創建了一個與Selenium Json Wire協議交互的庫,但我們的目標是與官方文檔示例盡可能地使其相似。 因此,來自Java硒站點的示例在php中的語法幾乎相同。
簽出: https : //github.com/Nearsoft/PHP-SeleniumClient
如果您喜歡它,請參與其中,進行分叉或隨心所欲:)
問候,馬克。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.