It may not be common, but it is definitely achievable.
Take a look at this:
You have the option to utilize the verifyEval command for confirming the outcome of a javascript code. Additionally, you can leverage storeEval to execute some javascript, fetch the result, and use it later on. If your goal is solely to perform javascript, you can also employ getEval.
If you want to ensure that there are no broken images on the page, you can do the following:
Command
verifyEval
Target
var allImg=window.document.getElementsByTagName("img"), i=0, img, result=true;
while (img = allImg[i++])
{if (img.complete && typeof img.naturalWidth != "undefined" && img.naturalWidth > 0)
{}
else
{result=false;}};
result;
Value
true
Alternatively, you could mark any broken\missing images to keep track of them. Below is an example that will trigger a failure if more than 5% of images on the page are broken:
Command
getEval
Target
var allImg=window.document.getElementsByTagName("img"), i=0, img;
while (img = allImg[i++])
{if (img.complete && typeof img.naturalWidth != "undefined" && img.naturalWidth > 0)
{img.setAttribute('tag','passed');}
else
{img.setAttribute('tag','broken');}};
Then:
storeXpathCount | //img | all
storeXpathCount | //img[@tag='broken'] | broken
verifyEval | storedVars['broken']*100/storedVars['all']>5 | true
Best of luck!