when i execute the following code using protractor it works. I am passing nested json to for loop. Because of asynchronously working of for loop it print all values of variable i and reaches to last value because of this it always access last pair of username and password. How can i solve this issue?
var data = require('.../testdata.json');
describe('homepage Test', function() {
  it('candidate login', function() {
    browser.driver.get('https://abcxyz.com');
    for (i in data.testdata) {
      element(by.id('tool_btn3')).click();
      console.log(i);
      browser.getTitle().then(function(title) {
        console.log("Title: " + title)
        if (title === "<page title>") {
          browser.driver.sleep(3000);
          element(by.id('email_input')).sendKeys(data.testdata[i].username);
          element(by.id('pwd_input')).sendKeys(data.testdata[i].password);
          element(by.xpath('//*[@id="signIn_btn"]/div[2]')).click();
          browser.sleep(3000);
          element(by.id('setting_img')).click();
          browser.sleep(2000);
          element(by.id('logout_div')).click().then(function() {
            console.log('success');
          });
        } else {
          console.log("problem");
        }
      });
    }
  });
}); 
    