How to use Protractor to verify image upload?

I am testing a website that can be redirected in several ways, one of which is incorrect in all cases (and one of them is correct depending on the context).

The most direct way I can tell the difference is to carefully examine the image loaded in a specific area.

I also notice that the paths of CSS files (as well as image files) vary depending on the scenario, so it may be easier to test the paths instead of the images themselves (they are all the same).

Unfortunately, I cannot share this code, but in general terms, how could you use a protractor to collect the full path data for a specific css file (or image) of the page and compare it with what is expected?

+4
source share
2 answers

Without what you are trying or your code is hard to say, but there must be two ways to do this - 1. The image name can be checked from css. But in your case, the image names are the same. So this will not work. 2. Check the attributes of the image element. Height, width, etc. And compared with the expected attributes. You can use element.getAttribute("attribute")to get certain values.

+1
source

you can try this

mypic = element(by.css("img[src*='mypic.png']"));
expect(mypic.isPresent()).toBe(true);

Also, maybe you want to do something specific if this image is found, as shown below

mypic = element(by.css("img[src*='mypic.png']"));
browser.isElementPresent(mypic).then(function (result) {
    if(result){
        //  DO STUFF

    }
});
+1
source

Source: https://habr.com/ru/post/1599262/


All Articles