Protractor instance vs browser

白昼怎懂夜的黑 提交于 2019-12-03 04:30:53

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!