Lubos Jerabek
Lubos Jerabek

Reputation: 833

Is there a way how to capture a page screenshot without logging it to the HTML log in Robot Framework?

Currently when I do:

Capture Page Screenshot  ${filename}

Alternatively in my library:

sel = BuiltIn().get_library_instance('SeleniumLibrary')
sel.capture_page_screenshot(path)

The screenshot file gets logged into the HTML log. I'd like to capture the screenshot but the file in the log is not necessary as I'm planning to do some more actions around the screenshot (comparison against baseline.)

How can I remove the file from the HTML log or just prevent logging it when capturing the screenshot?

Upvotes: 1

Views: 322

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386010

The underlying selenium library (the python library, not the keyword library) has a method named save_screenshot. You can get a reference to the underlying selenium driver and call that method directly.

Here's an example of a keyword that takes a screenshot and then saves it to a file with the given filename:

*** Keywords ***
Save screenshot
    [Arguments]  ${filename}
    ${selib}=  Get library instance  SeleniumLibrary
    Call method  ${selib.driver}  save_screenshot  ${filename}

To save a screenshot in the file "screenshot.png" in the current working directory, you would call it like in the following example:

*** Test Cases ***
Example
    Go to  http://www.robotframework.org
    Save screenshot  screenshot.png

Upvotes: 1

Related Questions