【问题标题】:How to run phpunit tests with selenium2 on different browsers如何在不同的浏览器上使用 selenium2 运行 phpunit 测试
【发布时间】:2014-06-17 00:12:14
【问题描述】:

我想要一些关于在多个浏览器上使用 selenium2 运行 phpunit 测试的帮助。我有以下 phpunit 测试,它在 Firefox 浏览器上运行良好。如何针对 Chrome、IE、Opera、Safari 等其他工具运行它?

如果你能提供帮助,我已经添加了下面的测试用例。任何指向帮助网站的链接都将不胜感激。

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());
    }
}

【问题讨论】:

    标签: selenium-webdriver phpunit


    【解决方案1】:

    如果你使用 phpunit 命令,你可以在执行之前设置一个环境变量,并从测试脚本中读取值。

    在 Mac OS X 或 Linux 上,在控制台输入:

    export SELENIUM_BROWSER=chrome
    

    在 Windows 中:

    set SELENIUM_BROWSER='chrome'
    

    在脚本中:

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

    【讨论】:

      【解决方案2】:

      根据您的浏览器更改 .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>
      

      【讨论】:

        猜你喜欢
        • 2013-07-10
        • 2012-05-24
        • 1970-01-01
        • 1970-01-01
        • 2012-04-24
        • 2013-08-23
        • 2015-01-05
        • 1970-01-01
        • 2015-09-29
        相关资源
        最近更新 更多