2012-02-01 37 views
2

我想使用PHPUnit的硒PHPUnit的硒

我啓動服務器 Java的罐子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類(與相同的服務器),但不幸運!

我做錯了什麼?

回答

4

好的,找到它。這裏是我的類現在:

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/

我米使用此硒服務器:硒的服務器獨立-2.18.0.jar

+4

waitForPageToLoad和waitForPageToLoad導致「BadMethodCallException:命令'waitForPageToLoad'不存在或不受支持。」它依賴於什麼? – 2013-06-05 16:36:01

0

如果你發現phpunit庫有點令人困惑,我們創建了一個與Selenium Json Wire Protocol交互的庫,但我們的目標是儘可能使其與官方文檔示例相似。因此,來自Java中的selenium站點的例子在php中的語法幾乎相同。

檢查出來:https://github.com/Nearsoft/PHP-SeleniumClient

如果你喜歡它分享,參與,叉,或請你做:)

問候,馬克。

相關問題