繁体   English   中英

PHPUnit和Selenium

[英]PHPUnit & Selenium

我有两个问题:

  1. 我在PHPUnit和Selenium中创建了很多测试用例,但我想将它们作为一个组而不是一次运行。
  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() );        
          }
       }

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/zh/selenium.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM