【问题标题】:PHPUnit & SeleniumPHPUnit & Selenium
【发布时间】:2013-12-19 22:00:02
【问题描述】:

我有两个问题:

  1. 我在 PHPUnit 和 Selenium 中创建了很多测试用例,但我想将它们作为一个组运行,而不是一次运行 1 个。
  2. 在多个浏览器上运行它们的最佳方式是什么。我已经查找了使用 webdriver 的示例,但不确定如何使用

我的 2 个测试用例是:

第一:

class AdminUserViewReqTabOptions 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 used
    $this->setBrowserUrl(''http://www.example.com');  // set base URL for tests
  }

  public function testShowRequestsOnHold()
  {
    $this->url('index.php'); // Set the URL to test
    // check for the existence of the string 'Show requests on hold'
    $this->assertRegExp( '/Show requests on hold/i', $this->source() );        
  }

  public function testShowOnlyPendingApprovals()
  {            
      $this->url('index.php'); // Set the URL to test
      // check for the existence of the string 'Show requests on hold'
      $this->assertRegExp( '/Show only Pending Approvals/i', $this->source() );        
  }

}

第二:

    class AdminUserViewReqTabOptions 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 used
           $this->setBrowserUrl('http://www.example.com');  // set base URL for tests
       }

       public function testDisplayServer()
             $this->url('index.php'); // Set the URL to test
             // check for the existence of the strin 'All Open'
             $this->assertRegExp( '/Server: Development/i', $this->source() );        
          }
       }

【问题讨论】:

    标签: php selenium selenium-webdriver phpunit


    【解决方案1】:
    【解决方案2】:

    1) 如果您所有的测试都位于同一个目录中,那么请尝试使用目录名而不是文件名来调用 phpunit。 Phpunit 将在给定目录中查找 *Test.php。

    2) 从您的 setUp() 函数中移除 setHost()、setPort() 和 setBrowser(),并改为在静态属性中声明您的浏览器。下面将在每个声明的浏览器中运行您的每个测试。

    public static $browsers = [
        [
            'host' => 'localhost',
            'port' => 4444,
            'browserName' => 'firefox'
        ],
        [
            'host' => 'localhost',
            'port' => 4444,
            'browserName' => 'chrome'
        ]
    ];
    

    https://phpunit.de/manual/current/en/selenium.html

    【讨论】:

      猜你喜欢
      • 2012-07-23
      • 2011-11-02
      • 2011-11-29
      • 2016-07-26
      • 2014-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      相关资源
      最近更新 更多