Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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().

like image 855
Clandestine Avatar asked Jul 18 '13 18:07

Clandestine


People also ask

What does driver get URL do?

Get Current URL Command In WebDriver, this method fetches the string representing the Current URL of the current web page. It accepts nothing as parameter and returns a String value. The respective command to fetch the string representing the current URL can be written as: driver.

Which function is used to open an URL in selenium?

get() This method is used to launch a new browser and will open the given URL in the browser.

How do you select you drivers to launch a URL in selenium?

setProperty("webdriver. ie. driver", "Drivers\\IEDriverServer.exe"); WebDriver driver= new FirefoxDriver(); ((JavascriptExecutor) driver). executeScript(script);

Which methods navigates to a URL?

Google's Answer: get() is used to navigate particular URL(website) and wait till page load. driver. navigate() is used to navigate to particular URL and does not wait to page load.


1 Answers

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.

like image 65
Jade McGough Avatar answered Sep 25 '22 16:09

Jade McGough