Hi, I am using Selenium2 Library, robot framework with python in PyCharm 2023.2.2 (Community Edition). I am not able to view the screenshots in log.html. Previously it was working fine but before couple of days I changed my system and suddenly it stopped showing the screenshots in log.html. Any suggestions? Thanks !
Not sure why it suddenly stopped working, did you update robot framework or another library?
Also wondering why you are using Selenium2 Library and not SeleniumLibrary?
Going forward, all new development will happen in the new SeleniumLibrary project.
I would suggest trying with SeleniumLibrary and seeing if the problem persists.
First install this:-
pip install robotframework-screenshot
In RobotFramework there is a screenshot library which is independent of any specific browser automation library.
*** Settings ***
Capture Page Screenshot # this keyword takes the screenshot
Try this, it should work.
Thanks but it needs to add SeleniumLibrary.Capture Page Screenshot everywhere so it is not feasible to change it across all the scripts. And for other functions also It asked to make it start with SeleniumLibrary. Any other solution?
There is no any libary with the name robotframework-screenshot. Well there is another libary pip install robotframework-screencaplibrary It takes the screenshots but when using set screenshot library it is not saving the screenshots in that libary and it is saving it in script folder. @damies13 please check this too and let me know if you have anything in this libarary.
I meant to change your robot script to use SeleniumLibrary instead of Selenium2Library for everything:
Then you won’t need to update all your
Capture Page Screenshot calls.
As far as I know Selenium2Library is not being maintained anymore, so even if you have an issue with it it might be difficult to get any help, it was last updated in 2015 (over 8 years ago)
That only change can be done but for all the functions in the script I need to add text SeleniumLibrary and hence it is huge work. Let me check if anything else can be work. Thanks!
I tried by using SeleniumLibrary but still not able to get the screenshots in log.html.
Ok so I guess my next question is are the screenshots getting created in same folder as the log.html. file? And can you open the screenshots?
If yes to that, which browser are you opening the log.html with? Have you tried a different browser? (don’t rule out the browser being the issue)
If you’ve ruled out both those potential issues;
- Which version of robot framework are you using?
- Can you show the html section from log.html where the screenshot should be, as that might help identify if there is a problem with the generated html (I’ve never heard of any issues here)
Below are the details.
Chrome : Version 119.0.6045.200 (Official Build) (64-bit)
Pycharm : 2023.2.2 Community Edition
Robot Framework : 6.1.1
My automation scripts are on same drive where I save screenshots. Only difference is Screenshot folder is in different folder as it is to avoid display of large data in automation script folder while displaying on pycharm.
With the same configuration everything was working on my previous system. I just changed the system and it started giving issue.
I see, so I guess we just need to workout the difference between the 2 systems that’s causing the images not to load.
The way the screenshots are shown in the log is pretty simple it’s just a standard html image tag, here is one from a Browser Library log that display’s screenshot correctly
As you can see it’s referencing an image with the path
browser/screenshot/fail-screenshot-2.png which is relative to the location of the log.html file.
Use dev tools to inspect your log file on the failed keyword and find the equivalent <img> tag, see what src path is and make sure the image is actually in that path and can be opened.
perhaps the path the new machine is using to the screenshots folder is slightly different to the path the old machine used?
I Managed to find a log with a screenshot from a SeleniumLibrary to show you an example html
It’s basically the same, the important part is the path to the image (In this case the image is in the same folder)
As I dont have muich time to spend on it, I have already changed the path of the folder added it to folder of automation scripts.
In future whenever possible will work on this part.
Once again thanks buddy.
Screenshots from test failures is done via
Capture Page Screenshot.
If the error happens and keyword
Set Screenshot Directory has been called to use a different path than what it is by default; Screenshot is stored into that directory and its not automatically embedded into HTML.
So what happens:
decide_embedded() most likely returns
False for you and then just stores the file into what ever directory you have set it to store all files.
After brief looking into screenshot keywords, I’d say the library should expose
Get Screenshot Directory keyword to avoid issues like this or as suggested, use external screenshot library for rest of your screenshots and use selenium provided screenshot for the rest that you want to end up in your custom screenshot directory. ping @EdManlove