Protractor instance vs browser
Asked Answered
P

2

27

I have tried to looked up for similar QA's but i couldn't find one to satisfy me. So basically i saw that in some examples it's used

ptor = protractor.getInstance();
ptor.get(url);

And in some other examples it's used.

browser.get(url);

So th question is: What's the difference using protractor instance and browser for getting specific url? Also if my assumption in the P.S. is right, which is better practice: to use only protractor, or to mix them?

P.S. Also i saw same difference in usage with the debugger. I know that protractor is a wrapper over web driver and i assume that protractor.getInstance().get(url) is a implicit invocatin of browser.get(url).

Portamento answered 3/2, 2014 at 12:4 Comment(0)
S
39

browser is the new, preferred syntax. browser is the same as protractor.getInstance().

A few versions ago a new syntax was introduced. The major changes were:

  • browser is a protractor instance
  • element(locator) is the new syntax for ptor.findElement(locator)
  • by[strategy] is the new syntax for protractor.By.[strategy]

Here is the new documentation: http://angular.github.io/protractor/#/api

Scleroma answered 3/2, 2014 at 21:16 Comment(2)
ptor is actually a browser instance. (protractor.getInstance() === browser)is trueZemstvo
Thanks! Explains a lot, all the tutorials use the old syntax so glad I checked :)Wagstaff
Z
5

You could in the protractor source code that the browser and the protractor singleton instance are the same object.

var browser = protractor.wrapDriver(
    driver,
    config.baseUrl,
    config.rootElement);
browser.params = config.params;

protractor.setInstance(browser);

You could also verified that assertion in one your test :

describe('My page', function() {
  it('should display something', function() {
    console.log('test ' + (protractor.getInstance() === browser));
    ...
  });
});

My preference is to always use the protractor singleton instance. But i think there isn't any inconvenient to use the instance browser or both.

Zemstvo answered 3/2, 2014 at 13:38 Comment(2)
Cheers mate, that clarifies it a lot.Portamento
No problem. I didn't get your problem with the debugger.Zemstvo

© 2022 - 2024 — McMap. All rights reserved.