Protractor : use browser or browser.driver methods?

后端 未结 2 1975
天命终不由人
天命终不由人 2021-01-13 13:34

When using protractor, the global variable browser appears to have all the functionality of browser.driver.

I am specifically

相关标签:
2条回答
  • 2021-01-13 14:17

    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 via browser.driver.


    There are though other takeaways, please take a look at this related threads:

    • Protractor browser.driver.getCurrentUrl vs browser.getCurrentUrl
    • browser.driver vs browser. Which one to use?
    0 讨论(0)
  • 2021-01-13 14:39

    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, and getCurrentUrl are copied over from WebDriver (see the browser.ts). So should you use browser or browser.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 use browser.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 use browser or browser.driver.

    0 讨论(0)
提交回复
热议问题