4

When automating tests using the Robot framework, is it possible to read messages logged to the JS console via console.log? We are also using the selenium 2 library.

We're using a third-party library that unfortunately does not provide events or fields for accessing the information that our QA Automation team wants to test, but the information is logged into the console. I mention this because workarounds such as "publish an event" or "expose a field", are not going to be acceptable solutions.

I am also not looking for a solution that involves overriding window.console.log, because this is a hack and may not be reliable.

Kir
  • 2,905
  • 2
  • 27
  • 44
  • Have you tried to use the following solution? http://stackoverflow.com/questions/20907180/getting-console-log-output-from-chrome-with-selenium-python-api-bindings – gbajson Nov 17 '16 at 10:14

1 Answers1

1

You need to create a python script to capture the current browser and then run the get_logs command. Something like this:

    from robot.libraries.BuiltIn import BuiltIn

def get_logs():
    se2lib = BuiltIn().get_library_instance('Selenium2Library')

    try:
        return se2lib._current_browser().get_log("all")

    # issues while retrieving logs: return empty
    except Exception as e:
        print(str(e))

    return []

And call on Robot Framework:

*** Settings ***
Resource          utils.robot

Library           get_logs.py
*** Keywords ***
Run On Failure
    Capture Page Screenshot
    Get Logs
Ramon Medeiros
  • 2,272
  • 2
  • 24
  • 41