SeleniumLibrary icon indicating copy to clipboard operation
SeleniumLibrary copied to clipboard

Return base64 image in case of EMBED

Open hsj51 opened this issue 1 year ago • 4 comments

This can be useful in case if someone wants to reuse the image i.e set test message or set suite documentation

hsj51 avatar Oct 07 '24 08:10 hsj51

@hsj51 Could you explain a bit more the idea behind returning the string "EMBED" and give an example of how this change would be used?

emanlove avatar Oct 08 '24 00:10 emanlove

Changes I have suggested is to return the base64 string of the image instead of the word 'EMBED'. This will enable user to reuse the image somewhere else in the report.

Below is an example use case:

Setting for EMBED

Library    SeleniumLibrary    screenshot_root_directory=EMBED

And add below lines to this function https://github.com/robotframework/WebDemo/blob/c8d46736c8248c1ebdcd67ac77fcb5bdafdd4851/login_tests/resource.robot#L44

Welcome Page Should Be Open
...
    ${ss}=    Capture Page Screenshot
    Set Test Message    *HTML*Test Success<p><img src="data:image/png;base64,${ss}" width="256px">

Then this is what a report may look like image

And Log file image

This will allow an user to view the screenshots in the report itself and not search for it in the log file through a mountain of keywords.

Main goal for this change is reusability of the images. Current alternative for this is to use .png images, but then there will be multiple files to manage and sharing report become difficult.

hsj51 avatar Oct 16 '24 13:10 hsj51

@emanlove I have tried to explain my changes and a possible use cases. Please feel free to reach out for any more queries

hsj51 avatar Oct 16 '24 13:10 hsj51

Alright, I see better your use case. And appreciate you highlighting the issue of writing to file and then "there will be multiple files to manage and sharing report become difficult". I do wonder if the solution might be added functionality to rebot to do this in a post processing step? Let me think about this a bit more. I think having other opinions could also be good here. If you have an account on the Robot Framework community, could you share your idea and reasons for it within the #seleniumlibray channel. If you don't have an account I could post there as well.

emanlove avatar Oct 17 '24 23:10 emanlove

@hsj51 @emanlove We had similar requirement and applied same change in our local

Observation: Report size got increased from 3mb to 30mb due to embed screenshot in test message. Due to this report not loaded for long time

We have around 2k tests and around 400 tests has embed images (failed tests)

I tried couple of approaches like flatten, remove keywords but report file size not decreased.

Thought of sharing my observation before accepting this change

adiralashiva8 avatar Apr 17 '25 14:04 adiralashiva8

@hsj51 and @adiralashiva8 if you both could take a look at a slightly modified version on this within https://github.com/robotframework/SeleniumLibrary/pull/1939. I wanted to prevent current users who might not need the returned string from increasing their log files by this change.

emanlove avatar May 26 '25 02:05 emanlove

Fixed in #1939

emanlove avatar Aug 03 '25 20:08 emanlove