I have a short protractor-based test of a login page. I would like to test that the 'banner' image is at least plausibly correct (e.g., that its not a broken link). Following a similar question (How to validate if the image is display in the table using webdriver) I checked the naturalWidth property of the img element.
While this approach seems to work (the naturalWidth is 0 if there was an error loading the image, but non-zero normally) with PNG images, and works okay in Chrome with an SVG image, in Firefox the naturalWidth property of the img element is always zero for any of my .svg images. Is there some other way to programmatically determine if an image loaded correctly/completely?
Here is what the HTML looks like:
<img src="/static/img/logo.svg" style="width:300px">
And here is what the JavaScript console in Firefox says about the img:
a[0].src
"http://localhost:1080/static/img/logo.svg"
a[0].naturalWidth
0
a[0].width
300
Sadly, if I break the link, by changing the HTML to:
<img src="/static/img/INVALID.svg" style="width:300px">
I get the exact same result at the JavaScript console.