2014-04-30 60 views
1

我想要在多個瀏覽器上使用selenium2運行phpunit測試的一些幫助。我有以下phpunit測試,它可以在Firefox瀏覽器上正常運行。我如何對Chrome,IE,Opera,Safari等其他人運行它?如何在不同的瀏覽器上使用selenium2運行phpunit測試

如果可以幫忙,我已經在下面添加了測試用例。任何鏈接,以幫助網站將不勝感激。

class exampleTestcase2 extends PHPUnit_Extensions_Selenium2TestCase { 
    public function setUp() 
    { 
     $this->setHost('localhost'); // Set the hostname for the connection to the Selenium server. 
     $this->setPort(4444); // set port # for connection to selenium server 
     $this->setBrowser('firefox'); // set the browser to be usedRequest State Change 
     $this->setBrowserUrl('http://www.php.net/'); // set base URL for tests 
    } 

    public function testCMS() // Test the title on index page 
    { 
     $this->currentWindow()->maximize(); // open window in full screen 
     $this->url('index.php'); // Set the URL to access the login page    
     $this->assertEquals('PHP: Hypertext Preprocessor', $this->title()); 
    } 
} 

回答

0

如果您使用phpunit命令,您可以在執行它之前設置一個環境變量,並從測試腳本讀取該值。

在Mac OS X或Linux,請在控制檯:

export SELENIUM_BROWSER=chrome 

在Windows中:

set SELENIUM_BROWSER='chrome' 

而在腳本:根據

$browser = getenv('SELENIUM_BROWSER') ? getenv('SELENIUM_BROWSER') : 'firefox'; 
0

變化.xml文件到您的瀏覽器 請記住firefox geckodriver需要。

<selenium> 
    <browser 
     name="firefox on Windows" 
     browser="firefox" 
     host="http://localhost" 
     port="4450" 
     timeout="40000"/> 
</selenium> 

<php> 
    <const name="PHPUNIT_TESTSUITE" value="true"/> 
    <const name="PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST" value="127.0.0.1"/> 
    <const name="PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT" value="4445"/> 
    <const name="PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_BROWSER" value="firefox"/> 
    <const name="PHPUNIT_TESTSUITE_EXTENSION_SELENIUM2_BROWSER" value="firefox"/> 
    <const name="PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL" value="http://test.com/"/> 
    <const name="PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PATH" value="/tmp"/> 
</php> 
相關問題