Your test automation code is an important tool to evaluate your application.  You must ensure your test code is working/testing as you want it to be. the automated tests give confidence for the developer that the application behaves as expected and things are not broken after they change the code.

Recently, at our QA phase, the QA found a bug that should have been caught from our test automation. Therefore being suspicious I looked into the code.  Interesting enough, the way we used loops along with test blocks were not testing as we wanted. Below is an example of a test block with the bad approach we had. Then I listed down a working approach using loops.

The following is the console output. Notice that the value inside the test block is always the same value.


Here a solution is to use a function

Now the output looks as follows.







Published by Sinaru Gunawardena

Sinaru is a software developer at work and a painter in free time. He enjoys writing tech notes on his personal website. He currently lives in Dublin, Ireland.

Join the Conversation


  1. HI…
    I am new to protractor.
    I want to import excel values(from 6 rows) and to call same login function using for() loop. When i use , it() block inside function, function is called. but it() block doesnt executed.

  2. it should work fine if you use an arrow function “it (‘bar’, () => {…” instead of using “it (‘bar’, function() {…”

Leave a comment

Leave a Reply to Sinaru Gunawardena Cancel reply

Your email address will not be published. Required fields are marked *