Skip to content

06 Global Variables

Biswajit Sundara edited this page Feb 23, 2021 · 3 revisions

When we talk about automating the web application. There are basically two initial steps start the browser and get the element before performing any action. Protractor API has made these as global variables and are directly imported to the spec file.

Browser

  • browser is a global variable in Protractor API
  • We don't have to do anything, just use browser in the it block and Protractor recognizes it as the browser driver
  • If you are wondering, how can we set which browser to use then that's handled in conf.js settings
  • This is like driver object of selenium
  • Example: browser.get('https://') to open any URL

Element

  • element is a global variable in Protractor API
  • It's a helper function for finding and interacting with DOM elements of the page.
  • The function uses locator strategy as the argument
  • This is like findElement of selenium
  • Example: element(by.css('a'))

By

  • by is a global variable in Protractor API
  • It's a collection of locator strategies to identify elements in DOM
  • Example: element(by.id('uname'))



Reference
https://www.protractortest.org/#/api-overview

Clone this wiki locally