在phpunit的Selenium 2 web驱动程序中,setBrowserUrl()和url()有什么区别?

Cla*_*ine 5 selenium phpunit automated-tests selenium-webdriver

在许多示例中,我看到了对webdriver-> setBrowserURL(url)和webdriver-> url(url)的调用.为什么我要使用一个而不是另一个.一个这样的例子显示以相同的方式使用两者(取自phpunit手册):

<?php
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
    protected function setUp()
    {
        $this->setBrowser('firefox');
        $this->setBrowserUrl('http://www.example.com/');
    }

    public function testTitle()
    {
        $this->url('http://www.example.com/');
        $this->assertEquals('Example WWW Page', $this->title());
    }

}
?>
Run Code Online (Sandbox Code Playgroud)

为什么setBrowserUrl()在setup中被调用一次 - 然后在测试用例本身中使用相同的url调用url()?

在其他示例中,我看到url()仅使用url的路径调用.这里的正确用法是什么?我几乎找不到关于url()使用的文档.

Jad*_*ugh 5

setBrowserUrl()设置一个基本URL,允许您在测试中使用相对路径.

phpunit手册中的例子有点令人困惑 - 我相信setBrowserUrl()在安装过程中被使用只是因为它会在没有它的情况下抛出错误:

public function start()
{
    if ($this->browserUrl == NULL) {
        throw new PHPUnit_Framework_Exception(
          'setBrowserUrl() needs to be called before start().'
        );
    }
Run Code Online (Sandbox Code Playgroud)

如果给出相对路径,则$ this-> url将使用此基数.