I want to assign a variable in a function and then use that result to compare with some data that I retrieved from a csv file. If I want to compare these two in the function that is reading the element from the webpage, then the value of the data from the csv would be the last item in the array. And if I want to use the result of the function outside of the function and compare it with the data from csv, then the variable(pageProductName) that contains the result of the function (textValue) would be undefined, even though I defined the variable outside the function(globally).
What can I do to use the value of textValue outside of the function?
or
What can I do to have the retrieved data from csv in the right order in the function?
Here is part of my code that I have problem with:
reader.addListener('data', function(data){
allEntries.push(data);
});
reader.addListener('end', function(end)
{ var i=0;
console.log(allEntries.length);
for(var j=0; j<allEntries.length;j++)
{
ProductURLArray[i]=(BaseURL+allEntries[j]['col3']+".html");
ProductNameArray[i]=allEntries[j]['col2'];
var url = ProductURLArray[i];
var name = ProductNameArray[i];
driver.get(url);
driver.sleep(3000);
driver.findElement(webdriver.By.css('.product-name h1')).getText().then(function(textValue){
pageProductName=textValue;
});
console.log(pageProductName);
assert.equal(pageProductName, name);
}
});