Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
demisx opened this issue Mar 23, 2014 · 5 comments
Closed

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

demisx opened this issue Mar 23, 2014 · 5 comments

Comments

@demisx
Copy link

demisx commented Mar 23, 2014

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
Copy link
Member

juliemr commented Mar 26, 2014

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.

@juliemr juliemr added the docs label Mar 26, 2014
@demisx
Copy link
Author

demisx commented Apr 1, 2014

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.

@demisx demisx closed this as completed Apr 1, 2014
@ryancat
Copy link

ryancat commented Mar 16, 2015

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

@demisx
Copy link
Author

demisx commented Mar 16, 2015

@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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants