What is the difference in setBrowserUrl() and url() in Selenium 2 web driver for phpunit?

automated-tests, phpunit, selenium, selenium-webdriver

Solution

setBrowserUrl() sets a base url, allowing you to use relative paths in your tests.

The example from the phpunit manual is kind of confusing - I believe setBrowserUrl() is being used during setup simply because it'll throw an error without it:

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

$this->url will use this base if a relative path is given.

Problem

In many examples, I have seen calls made to both webdriver->setBrowserURL(url) and webdriver->url(url). Why would I want to use one instead of the other. One such example shows using both in the same manner (taken from the phpunit manual): ``` <?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()); } } ?> ``` Why would setBrowserUrl() be called once in setup -- and then url() be called with the identical url in the test case itself? In other examples, I've seen url() called with just a path for the url. What is the proper usage here? I can find almost no documentation on the use of url().

Original source