angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

browser.driver vs browser. Which one to use? #634

Closed demisx closed 10 years ago

demisx commented 10 years ago

Can someone please explain in plain English (or point to docs) on when I should use browser.driver and when browser when calling methods? For example:

browser.get() or browser.driver.get()?
browser.getAllWindowHandles() or browser.driver.getAllWindowHandles()?
browser.getCurrentUrl() or browser.driver.getCurrentUrl()?

Thanks.

juliemr commented 10 years ago

In https://github.com/angular/protractor/blob/master/docs/getting-started.md#writing-tests, this is addressed: If you need to interact with a non-Angular page, you may access the wrapped webdriver instance directly with browser.driver

I'll try to make this a bit more prominent when redoing the docs, if it's confusing.

demisx commented 10 years ago

Thank you Julie. I get it at a high-level, but what was a little confusing why I had to use browser.driver.getCurrentUrl().toMatch... in the test below, whereas the same call without driver browser.getCurrentUrl().toMatch would fail with a protractor sync error.

it "opens Facebook popup when clicked on FB login button", ->
    loginPage.get()
    loginPage.clickFBLoginButton()

    browser.getAllWindowHandles().then (handles) ->
      browser.switchTo().window handles[1]
      expect(browser.driver.getCurrentUrl()).toMatch /https:\/\/www.facebook.com\/login.php.*/
    return

Perhaps, when if I start testing at window handles level, I need to work with the webdriver directly. Would be nice to have some docs pointing out scenarios on when to use one vs. other. Thank you.

ryancat commented 9 years ago

Hi @demisx do you have the answer to your question on April 1, 2014? I am confused on this as well.

demisx commented 9 years ago

@ryancat Hi there. As far as I understood, browser.driver.x is for interaction with non-Angular pages and browser.x methods are wrappers for interacting with Angular pages.

MarkAPhillips commented 9 years ago

Just to add to this - I find that browser.driver works better on AngularJS apps that take time to sync. I have tried both and for some reason browser.driver is more reliable.

I think more clarity needs to added in relation to this as why not just use browser.driver as it works on both Angular and non-Angular apps and therefore eliminates this confusion as to which one to use.