【问题标题】:Launch phpunit-selenium2 tests in Chrome and IE在 Chrome 和 IE 中启动 phpunit-selenium2 测试
【发布时间】:2013-01-24 00:06:06
【问题描述】:

我使用本教程 http://net.tutsplus.com/tutorials/php/how-to-use-selenium-2-with-phpunit/ 创建了测试。一切正常,但我只能在 Firefox 上启动此测试。我在互联网上阅读了很多关于此的文章,但我没有找到任何解决方案。我有 Sebastian Bergmann 的 Windows XP、PHP 5.4.7、PHPUnit 3.7.13。在运行测试之前,我启动了 selenium-server-standalone-2.28.0.jar。这是我的测试

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

请帮我在其他浏览器上运行这个测试。如果您需要更多信息,请询问我。谢谢

【问题讨论】:

标签: phpunit selenium-webdriver


【解决方案1】:

对于 Chrome:

  • 浏览docs
  • 下载ChromeDrive
  • 使用额外参数启动 Selenium:java -jar selenium-server-standalone-&lt;version&gt;.jar -Dwebdriver.chrome.driver=/path/to/chromedriver.exe
  • 现在在您的 setUp() 方法中执行 $this-&gt;setBrowser('chrome');

我还没有尝试过 IE 驱动程序,所以我不能为你做更多的事情,然后指向docs

最后,尝试在所有这些浏览器上运行您的测试,您可以为所有浏览器提供一个数组:https://phpunit.de/manual/4.8/en/selenium.html 同样,我自己还没有尝试过这个,所以我不能比那些文档更具体。

希望我现在已经给了你足够多的指点...... :)

【讨论】:

【解决方案2】:

对于 IE:

  • 下载InternetExplorerDriver
  • 使用额外的参数启动 Selenium:

    java -jar selenium-server-standalone-.jar -Dwebdriver.chrome.driver=/path/to/chromedriver.exe -Dwebdriver.ie.driver=/path/to/IEDriverServer.exe

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-24
    • 2018-05-12
    • 2015-04-02
    • 2012-08-12
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    • 2014-06-17
    相关资源
    最近更新 更多