在PHPUnit中的所有测试之前运行函数

时间:2015-02-27 08:34:32

标签: php selenium phpunit

我正在寻找运行Selenium测试的PHPunit并且可以运行测试。但是缺少的是能够在运行测试之前运行一个函数(比如设置一些配置)。

<?php

require_once 'SeleniumTest.php';

class MyTest extends SeleniumTest
{

  public function testTest1()
  {
    $this->runSelenese(__DIR__ . '/test1.html');
  }

  public function testTest2()
  {
    $this->runSelenese(__DIR__ . '/test2.html');
  }
}

配置文件只是一个常规的html文件,但需要在运行其他任何内容之前运行一次

修改

setUp()函数的另一个阅读让我相信我的测试应该如下设置。

我想要模拟的是用户登录,设置一些配置,运行测试,然后在测试结束时退出应用程序。

这就是我想出来的;请告知我做错了什么,因为测试目前还没有。所有测试都超时:这是我应该如何接近这个?

<?php

require_once 'SeleniumTest.php';

class MyTest extends SeleniumTest
{

  public function setUp()
  {
    $login_path = '/login_path/Login.html';
    $logout_path = '/logout_path/Logout.html';  
    $config_path = '/config_path/config.html';
    $this->runSelenese($login_path);
    $this->runSelenese($config_path);
    $this->runSelenese($logout_path);
  }

  public function testTest1()
  {
    $this->runSelenese(__DIR__ . '/test1.html');
  }

 public function testTest2()
 {
    $this->runSelenese(__DIR__ . '/test2.html');
 }
}

0 个答案:

没有答案