GET Request : only return the response code for image

Hello,

In order to be sure that my image is not broken, I do a GET request like this :

    ${temp}=    Get Element Attribute    //div[@class="photo_bg"]/img    src 
    ${background}=    GET    ${temp}    expected_status=200

I only want the response code but when I execute my test, the image is “read” and on the console, there are characters like �5�����1 and my log is unreadable.

Have you an idea to only get the response code without reading the image ?

Thanks a lot

John.

I don’t know if there is a keyword for that in RESTLibrary (this is the one you used, right?), but here is my suggestion:

${temp}=    Get Element Attribute    //div[@class="photo_bg"]/img    src
${loglevel}=    Set Log Level    NONE
${background}=    GET    ${temp}    expected_status=200
Set Log Level    ${loglevel}

Hello,

Your idea seems to be good but when I try it, indeed the special characters have disappeared but when the test fails (for example I put a 400 expected_status, I don’t see anymore the error message)

I solved your original problem :slight_smile:

You have to add a different logic for different cases, for example:

    ${temp}=    Get Element Attribute    //div[@class="photo_bg"]/img    src
    ${loglevel}=    Set Log Level    NONE
    &{res}=    GET    ${temp}
    IF    ${res.status} == ${200}
        Log    Image link is OK
    ELSE IF    ${res.status} == ${400}
        Output    response body
    ELSE
        Log    Unexpected response!
        Output    response
    END
    Set Log Level    ${loglevel}

If you are interested in response code only maybe HEAD keyword would work for you better?

Hello,

Thanks for all your help.
Your solution is working ! I have tried the Helio’s one but it failed…

Thanks a lot :slight_smile:

For information, I have wrote :

${temp}=    Get Element Attribute    //div[@class="photo_bg"]/img    src 
${background}=    HEAD    expected_status=200