Forum Discussion
Hi,
Again, exact implementation depends on your given tested application, but might be like this (untested JScript pseudocode):
var arImages = page.FindAllChildren("ObjectType", "Image", 100).toArray();
var boolAltMissed = false;
var oImage;
for (var i = 0; i < arImages.length; i++) {
oImage = arImages[i];
if ("" == oImage.alt) {
boolAltMissed = true;
Log.Error("alt property is empty for image", oImage.outerHTML, pmNormal, null, oImage.Picture());
}
}
if (!boolAltMissed)
Log.Checkpoint("All images have non-empty alt property", "", pmNormal, null, page.PagePicture());
- AlexKaras3 years agoChampion Level 3
Hi,
> this code checks if any image has a missing alt tag
Yes, correct.
> I want to check if the alt tag is displaying on the page which normally does if an image has not loaded
I would put it this way: it is browser that renders either image itself or the content of image's alt attribute (alt is an attribute of Image tag). So, unless you are checking browser itself, I would expect that the content of alt attribute will be rendered by the browser if it fails to load the image.
If for some reason you really need to check what happens when the image fails to load (for example, to check that page layout is not broken), then you need to install some proxy (ProxyMob is mentioned often in Selenium/Appium world) and setup this proxy to block all or certain image requests.
I am not sure as for subsequent validation: it is my expectation that page markup will still contain <img> tag for images that failed to load and I am not sure that it will be easy to check with TestComplete what is actually rendered on the screen - the image itself or the text from alt attribute. This is something that you will need to investigate.
Image comparison might work, but it depends on physical parameters of the hardware where the test is executed and thus is not always reliable. Third-party service like Applitools should work well, but it is commercial and requires additional licensing.
Related Content
- 11 months agoIrinaManea
- 2 years agomattb
- 9 years agoglenmetz