0

我正在尝试自动化涉及两个没有通用基本 URL 的网站的用户场景。我怎样才能做到这一点?现在我没有成功尝试更改全局变量,但每次测试都会重置它们。

public $check = true;

protected function setUp() {
    $this->setBrowser("*googlechrome");
    if ($this->check==true)
        $this->setBrowserUrl("SITE A");
    else
        $this->setBrowserUrl("SITE B");
    $this->setPort(4444);
    $this->setHost("0.0.0.0");
}

public testA() { //requires SITE A, set check to false }
public testB() { //requires SITE B }
4

1 回答 1

0

您的代码将无法工作,因为在每个测试用例运行之前setUp()执行。

为什么不更明确地说明您要做什么?尝试以下操作:

private $sites = array('A' => 'a.com', 'B' => 'b.com');

protected function setUp() {
    $this->setBrowser("*googlechrome");
    $this->setPort(4444);
    $this->setHost("0.0.0.0");
}

public function testA() 
{
    $this->useSite('A');
}

public function testB() 
{
    $this->useSite('B');
}

private function useSite($site)
{
    $this->setBrowserUrl($this->sites[$site]);
}
于 2013-04-06T14:52:30.243 回答