phpunit - 在 Chrome 和 IE 中启动 phpunit-selenium2 测试

标签 phpunit selenium-webdriver

我使用本教程创建了测试 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。这是我的测试

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

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

最佳答案

对于 Chrome:

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

我还没有尝试过 IE 驱动程序,所以我无法为您做更多的事情,然后指向 docs .

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

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

关于phpunit - 在 Chrome 和 IE 中启动 phpunit-selenium2 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14768933/

相关文章:

PhpUnit 与 Zend Framework 内存问题

php - 在单元测试 Laravel 期间保存变量

php - 使用 PHPUnit 和 Mockery 模拟 Symfony 实体进行单元测试

java - 使用 Selenium Webdriver 连接远程数据库并通过 eclipse 从本地机器运行测试用例

selenium - 在运行时将值传递给 xpath

Drupal 8 PHPUnit 测试自定义模块

PHP fatal error : Class 'WP_UnitTestCase' not found when trying to run test-sample

java - Selenium 无法使用 xpath 定位元素,但 firebug 可以

java - 如何在 Selenium WebDriver 中滑动{移动} slider

java - 无法将 BASE64 解码为 Selenium 2 中的图像文件