agent-Python-RobotFramework icon indicating copy to clipboard operation
agent-Python-RobotFramework copied to clipboard

reportportal.listener don't transfer screenshots provided by Browser library

Open IlkkaKoskinen opened this issue 1 year ago • 3 comments

To communicate with GUI we are using Browser library instead of SeleniumLibrary. When some error occurs, Browser library (like SeleniumLibrary) takes a screenshot about GUI, stores it into image file and links image file into Robot Framework log file. Everything works fine locally, but when the whole bunch is transferred into ReportPortal by using robotframework_reportportal.listener -component, image files are dropped out and only dead links remain in the log file.

I assume that the core reason for the problem is the location of screenshots files, because Browser library stores them into path ./browser/screenshots while at SeleniumLibrary time the path was something different (unfortunately I can't remember it exactly any more)

If my assumption is correct, is anybody able to add support also for screenshots of Browser library into reportportal.listener?

IlkkaKoskinen avatar Jun 07 '24 10:06 IlkkaKoskinen

Generally, your problem is links that are relative to HTML report location. I have a similar problem with different libraries. I already asked for the right solution in the Robot Framework forum.

Nobody answers me to now. You have generally two possible solutions.

  1. One is to change the links of the images to the absolute path (it will lead from the report portal to somewhere to your storage of results)
  2. upload images "manually" - rewrap Browser Library keywords/methods and put there a code in python that send attachment to the report portal...

2 - has code similar to: code from page robotframework-reportportal

The way 2 for screenshot library: I did it for the screenshot library where is one keyword named Take Screenshot - I created my keyword Take Screenshot. I put it in the execution order in RF as a priority to call my Take Screenshot and inside I recall Take Screenshot from the screenshot library... and take the image and upload it as an attachment to report portal.

RF test: test

Rewrap in python: rewrap

petr-kus avatar Jun 12 '24 17:06 petr-kus

By the way, I understand the idea and will automate way one or two.

Currently, I am writing a listener for RF that parses log messages. When it finds an image or link, it will update/upload the relevant items to the report portal. This functionality could be integrated into the report portal listener by default - maybe I will contribute this to the report portal listener. (this will solve the situation for all libs that attach something to logs... )

petr-kus avatar Jun 16 '24 19:06 petr-kus

To communicate with GUI we are using Browser library instead of SeleniumLibrary. When some error occurs, Browser library (like SeleniumLibrary) takes a screenshot about GUI, stores it into image file and links image file into Robot Framework log file. Everything works fine locally, but when the whole bunch is transferred into ReportPortal by using robotframework_reportportal.listener -component, image files are dropped out and only dead links remain in the log file.

I assume that the core reason for the problem is the location of screenshots files, because Browser library stores them into path ./browser/screenshots while at SeleniumLibrary time the path was something different (unfortunately I can't remember it exactly any more)

If my assumption is correct, is anybody able to add support also for screenshots of Browser library into reportportal.listener?

you can name your screenshot as EMBED :

https://marketsquare.github.io/robotframework-browser/Browser.html#Take%20Screenshot : If filename equals to EMBED (case insensitive) or ${NONE}, then screenshot is embedded as Base64 image to the log.html:

than it works ans screenshot is embedded into the RP failed keyword context. like resource config and kw config:

***Settings***
Library             Browser   run_on_failure=Take Screenshot

*** Keywords***
Take Screenshot    filename=EMBED

keef78 avatar Jun 17 '24 21:06 keef78

@IlkkaKoskinen, @petr-kus, Seamless logging for Selenium and Browser libraries implemented in this release: https://github.com/reportportal/agent-Python-RobotFramework/releases/tag/5.5.8

HardNorth avatar Oct 08 '24 12:10 HardNorth

@keef78 I do not recommend to do like that. I had such examples in the past, but deleted them by a good reason. In this case you just put these images inside your DB, instead of binary storage. This makes your DB bigger and puts additional pointless load on Analyzer (more CPU consumption) to process larger messages. And if we talk about managed services in Clouds, then DB space is usually more expensive, than binary storage.

HardNorth avatar Oct 08 '24 12:10 HardNorth

@keef78 I do not recommend to do like that. I had such examples in the past, but deleted them by a good reason. In this case you just put these images inside your DB, instead of binary storage. This makes your DB bigger and puts additional pointless load on Analyzer (more CPU consumption) to process larger messages. And if we talk about managed services in Clouds, then DB space is usually more expensive, than binary storage.

Yes, on the other hand, it’s not an issue if the retention period is set to a few weeks. In this case, if you don’t need results from long ago, the base64 data is automatically deleted, so there are no database space issues.

You could save screenshots as attachments (we do this as well), but it’s not very user-friendly to link the correct "failed" screenshot( in the case of multiple screenshots taken) to the test case, even if it’s named after the test case or keyword. This is simply because it isn’t in the context of the report.

if the new release 5.5.8 is the solution, I will update it of course .)

keef78 avatar Oct 08 '24 15:10 keef78