T
T
Temirlan Savitov2018-07-20 10:02:17
Software testing
Temirlan Savitov, 2018-07-20 10:02:17

How to check the display of an image on a WebDriver page?

Hello ! In general, there is a user profile page. On this page, you can add a user avatar, and a page cover. It is necessary to check:
1. Whether the picture was loaded during loading. We click on the plus sign, select the picture on the computer, after loading the "Crop" button appears
2. Is the picture displayed on the page. After adding a picture to the avatar and cropping it, you need to refresh the page and make sure that the picture is in place.
I already checked the first one, by trial and error, I found the class I needed from the photo. And in the second case, I can't find neither Xpath nor
css
nor
class
String js = "return (typeof arguments[0].naturalWidth!=\"undefined\" && arguments[0].naturalWidth>0)";
Boolean isImageDisplayed = (Boolean) ((JavascriptExecutor) driver).executeScript(js, image);
assertTrue(isImageDisplayed);
System.out.println(isImageDisplayed);
}
Here is the whole code
public void CoverAndAvatarProfile(String user, String password) throws Exception {
app.reg().regNewUserMail(user, password);
app.icons().profile().click();
edit().click();
cover().click();
app.addFiles().AddFiles("photo1.jpg"); - adding photo
app.sleep_time(10000);
app.img().testImage2("//div[2]/div[1]/div[1]/div"); - photo check by Xpath (false after this point and the test fails) I also tried to search by class and css
addPhoto().click();
app.addFiles().AddFiles("photo.png");
app.img().testImage("crop__Crop__image___24B26"); (here I'm looking for class "y, true, finds)
app.magazines().clip().click();
app.sleep_time(2000);
save().click();
driver.navigate().refresh() ;
app.sleep_time(2000);
edit().click();
cover().click();
app.addFiles().AddFiles("photo4.jpg");
app.sleep_time(2000);
addPhoto(). click();
app.addFiles().AddFiles("photo3.jpg");
app.img().testImage("crop__Crop__image___24B26");
app.magazines().clip().click();
save().click();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2018-07-21
@dimonchik2013

https://www.linkedin.com/pulse/capturing-network-t...

V
Valery Glukhovtsev, 2018-07-24
@valera-glukhovtsev

Surely, if the picture did not load, some inscription or some picture is provided in its place. Try to act on the contrary - if such an inscription (picture) appears - the test is failed
The second option is to use testing with screenshots, and specifically, the A-shot framework from Yandex.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question