When using protractor
, the global variable browser
appears to have all the functionality of browser.driver
.
I am specifically asking this because I am not sure whether to use browser.wait
or browser.driver.wait
as they both appear to be the same method, and I also saw that a lot of the browser.driver
methods are available in browser
(if not all).
So what is the recommended way to call those methods browser.method
or browser.driver.method
?
In theory the distinction is simple: If this is an Angular application under test - use browser, otherwise - browser.driver.
A little bit more to the story:
Protractor wraps around
WebDriverJS
- javascript selenium bindings - as a part of that it wraps the selenium driver object itself leaving you the access to the pure WebDriverJS driver viabrowser.driver
.There are though other takeaways, please take a look at this related threads:
Some browser methods are the same...
The browser object is made up by composition of WebDriver methods and Protractor specific methods. So methods like
sleep
,wait
, andgetCurrentUrl
are copied over from WebDriver (see the browser.ts). So should you usebrowser
orbrowser.driver
? Well, if it is listed in the link above, they are the exact same thing.Some browser methods are not...
However, not every method is just copied over. For methods like
get
, the browser is implemented differently in Protractor vs selenium-webdriver. For Angular pages, you should usebrowser.get
. This will wait for Angular to be stable before moving on to other commands before moving onto other commands.When in doubt, check out the documentation
So when you navigate to protractortest.org/#/api, you will see a list of
browser
methods that are Protractor specific and "inherited from webdriver.WebDriver". The methods that follow "inherited from webdriver.WebDriver" are the same method if you decide to usebrowser
orbrowser.driver
.