Hi all, We have issue in screenshot, we need screenshot if we have any unexpected error then we need screenshot, we don’t need screenshot in try failure or if condition failure.we need to stop screenshot if we don’t need in that, since log or other artifact’s size is big we can’t able to get the log. We need to avoid taking screenshot wherever it is not needed. Is there any way to achieve this?
I assume that this is question about browser errors? Both Selenium and Playwright have run_on_failure
(defaults to screenshots) setting that can be overridden on import.
yeah, we use playwright lib with this arguments run_on_failure=Take Screenshot \ EMBED. we need to avoid the scrennshot when the try or if condition failing. but we need screenshot if any unexpected error occur
You can set that value to None
and then add Take Take Screenshot \ EMBED
to the parts of the robot you would like to get info. For example EXPECT parts or ELSE parts of the robot.
if I’m getting a eroor/failure outside Try part or if condition. For example, i have a web automation i need to get a element, if there is no element with that xpath in that page, but the element should be there. in this case i need to take screenshot. If we give none, then in this place i will never get a screenshot right?
Yes on that case you would manually add the points where screenshots are taken. For example:
Minimal task
TRY
New Browser headless=${False} # starts in headless in Control Room
New Page https://robocorp.com/docs/development-guide/browser/playwright
Click id:random
EXCEPT
Take Screenshot EMBED
Log Not found
END
There is also keyword RPA.Browser.Playwright library | Robocorp documentation to set this on run time. So you leave the import as is, but before error heavy loop you set screenshots to None
will the screenshot visible if the failure is not in try except part but in some other place?
For example code no, you would need to implement that in places where you expect the unexpected error. For keyword screenshots will be taken by default unless you turn it off (like stated in the documentation).
can i able to give take screen shot in keywords like, click, Wait For Elements State and Get Element Count, because these are the places i will get a unexpected error
mute run on failure - can you explain this keyword
As it says in the documentation that keyword only works for Selenium library. It suppresses the default Selenium run_on_failure
setting.
can i able to give take screen shot in keywords like, click, Wait For Elements State and Get Element Count, because these are the places i will get a unexpected error
Let’s take it like this. I don’t wanna take a screenshot wherever it is needed. What I am looking for is, I want to avoid taking screenshots wherever I don’t need screenshots.
The need is to avoid taking screenshots for business exceptions bcoz they are unnecessary and making the log file go over the size limit.
For example let’s take a code written using RPA.Browser.Playwright library.
I have 10 different keywords. In a particular keyword let’s say keyword 5, I know there will be a business exception. Here what I am looking for is, if there is a failure in any keyword except the 5th keyword, I want a screenshot. If the failure is in the 5th keyword, I don’t want a screenshot. Also, I don’t wanna take a screenshot forcefully using the Keyword “Take Screenshot”. I just wanna use the default mechanism of taking screenshot on failure and avoid the same default mechanism at particular points.
Yes, and the answer is like before: there is no ready solution for that, however, you can implement that behavior either using RFW or Python syntax. Or you can try to implement your logic to avoid failure with that particular keyword
We found a solution for the Playwright keywords. There is a keyword in the Browser.Playwright library namely “Register Keyword To Run On Failure”. This keyword can be used for the issue we had. This keyword can be used to both disable and enable keyword failure actions at desired locations.
Yes, as mentioned here