Thursday, October 29Be an Automation Engineer

Tag: Protractor Example

Take screenshot for every failed spec in protractor+jasmine

Jasmine, Protractor, TypeScript
Why we need screenshots?

Generally we need screenshot of the browser where the protractor got failed. It would increase our chances to quickly figure out the issue before getting into the code debug. 

How to take a screen shot in protractor?

Below is the code to take a screenshot using protractor.

browser.takeScreenshot().then(function (png) { var dirPath = './reports/screenshots/'; if (!fs.existsSync('./reports')) » Continue Reading.
Protractor with jasmine data provider – Write once test many times

Protractor with jasmine data provider – Write once test many times

Jasmine, JavaScript, Protractor
What is data provider?

When it comes to automation, data provider is an approach to pass test data to the automation tests. Each and every automation tool has it’s own way of providing test data to the automation When we take TestNG framework, it has @DataProvider annotation which will help to pass test data to the automation test.

Why we » Continue Reading.
Execute protractor tests using blocking proxy

Execute protractor tests using blocking proxy

blocking-proxy, Protractor

Before going to seen an example, let us know about blocking proxy.


What is blocking-poxy?

Blocking proxy is a tool which provides some additional functionality for the selenium based automation tools before hitting selenium server. Blocking proxy sits in between our automation code and the selenium server. We can use blocking-poxy to set some barriers to » Continue Reading.

Execute Asynchronous Javascript in protractor

JavaScript, Javascript Executor, Protractor

Protractor has two functions to execute javascript code in tests.

  • executeScript
  • executeAsyncScript
  • We’ve explained about executeScript with examples here.

    Now, Lets know about executeAsyncScript.

    browser.executeAsyncScript(Asnynchronousjavascript, args…)

    Basically protractor provided this method to execute any asynchronous javascript code. We need to use this method to execute a javascript which has ajax calls or timeouts in it.

    executeAsyncScript takes one » Continue Reading.

    Javascript Executor in protractor

    JavaScript, Javascript Executor, JS, Promise, Protractor

    Most of the time we interact with web elements using selenium internal methods like click, sendKeys, select etc..

    Why we need javascript executor? Selenium is written in the way that it should not interact hidden elements on the webpage. Real user can not interact with the hidden elements in the web page so selenium guys are also not allowing » Continue Reading.
    Find elements using javascript in protractor

    Find elements using javascript in protractor

    JavaScript, JS, Protractor

    There are many element location strategies available in protractor. Click here to know about element locators in protractor.

    by.js is one more element locating strategy available in protractor. We need to pass javascript code as a string or as a function to by.js to get single/multiple element(s).

    Pass javascript code as a string:

    Element identification in protractor

    Element Identification, Protractor

    In any UI automation tool, the most important and required step is element identification. Protractor has many element locating strategies like selenium webdriver. You can go through different element locating strategies available in protractor Here and Here.

    Lets know about element identification in protractor.

    Element identification is different for different situations. Some times we may need to » Continue Reading.