I am writing some tests in selenium webdriver (on node.js). and have made a custom function to check the css value of an iFrame Element. I'm a coding beginner.
The script tests an app where the user writes the image width they want (just putting in a number) and the image in an iFrame should change width. This is tricky because one must switch iFrames, wait for elements to become stale (as the new image width is loaded) then grab the new element and check its css value.
Often, the tests are flaky because sometimes it checks before the value has changed etc. I finally wrote a function that passed 120 times out of 120 times.
//function looks for 'el', then switches iframe and extracts the desired cssValur, then compares it to the 'value' we expect
Page.checkCssValue = function (el, cssValue, value){
//find function, the '0' represents the iframe index
var newEl = this.find(el, 0);
return newEl.getCssValue(cssValue).then(function(result){
if(result !== value){
console.log(result + " and " + value + " Do not Match.")
return Page.checkCssValue(el, cssValue, value);
}
else{
console.log(result + " and " + value + " Do Match!")
return result;
}
});
};
But I'm not sure if this is considered bad programming and if a while loop would be better?