2013-02-08 27 views
11

我使用本教程http://net.tutsplus.com/tutorials/php/how-to-use-selenium-2-with-phpunit/創建測試。所有工作都很好,但我只能在Firefox上啓動此測試。我在網上閱讀了很多關於這方面的文章,但我沒有找到任何解決方案。我有Windows XP,PHP 5.4.7,Sebastian Bergmann的PHPUnit 3.7.13。在運行測試之前,我啓動了selenium-server-standalone-2.28.0.jar。還有就是我的測試在Chrome和IE中啓動phpunit-selenium2測試

<?php 
class Example extends PHPUnit_Extensions_Selenium2TestCase 
{ protected function setUp() 
    { 
    $this->setBrowser("firefox"); 
     $this->setBrowserUrl('http://test.com/'); 
    } 

    public function testogin() 
    { 
     $this->url('http://test.com/'); 
     $this->timeouts()->implicitWait(10000); 
     $username = $this->byId('user_login'); 
     $username->value('test.ru'); 
     $password = $this->byId('user_pass'); 
     $password->value('test'); 
     $this->byId('login_btn')->click(); 
    } 
} 
?> 

請幫我跑在其他瀏覽器測試。如果您需要更多信息,請問我。由於

+0

發佈錯誤日誌。 – Manigandan

+0

對於IE: 請參閱我的答案http://stackoverflow.com/questions/11982954/howto-start-internetexplorerdriver-in-phpunit-tests/15479565#15479565 –

回答

20

使用Chrome:

  • 概覽通過docs
  • 下載ChromeDrive
  • 開始硒與額外的參數:java -jar selenium-server-standalone-<version>.jar -Dwebdriver.chrome.driver=/path/to/chromedriver.exe
  • 現在,在您的設置做$this->setBrowser('chrome');() - 方法

我還沒有試過IE驅動程序,所以我不能爲你做更多的話指向docs

最後,儘量在所有這些瀏覽器中運行你的測試,你可以給一個數組與所有瀏覽器:https://phpunit.de/manual/4.8/en/selenium.html 再說一遍,我沒有嘗試這樣一個自己,所以我不能更具體的那麼這些文檔。

希望我已經給了你足夠的指點,現在... :)

+0

是的!這是工作!萬分感謝!! – user1802967

+1

謝謝你qrazi。它工作完美。我贊成你的答案。 –

+1

Chrome驅動程序下載的新網址:https://sites.google.com/a/chromium.org/chromedriver/ – Pavel

6

對於IE:

  • 下載InternetExplorerDriver
  • 開始用硒額外的參數:

    Java的罐子selenium-server-standalone -jar -Dwebdriver.chrome.driver =/path/to/chromedriver.exe -Dwebdriver.ie.driver =/path/to/IEDriverSe rver.exe

  • 現在做$ this-> setBrowser('iexplore');在你的setUp()方法中