1

While using Karate I need to receive information from browser console (e.g. Firefox) when an error occurs.

How can I do it with Karate?

1) Is there any way to save the browser console log? (or attach it to features report)?

In Selenium I use this to log browser console in case error occurs:

if (webDriver != null) {
    LogEntries logs = webDriver.manage().logs().get(LogType.BROWSER);
    for (LogEntry entry : logs) {
        LOG.error(entry.getLevel() + " " + entry.getMessage());
    }
}

2) Is it possible to trigger it in similar way to take screenshot after scenario?

e.g (after scenario screenshot when some error occurs):

configuration:

karate.configure('afterScenario', read('afterScenarioScreenshot.js'));

afterScenarioScreenshot.js:

function()
{
if (karate.info.errorMessage) driver.screenshot()
}

Thank you for any idea.

Radim Bukovský
  • 337
  • 2
  • 11

1 Answers1

0

The only suggestion I have is to use showProcessLog: true in the driver config.

Now you should see any FireFox process (console) logs in-line with the HTML report.

There may be ways to switch on the detailed logging that you want. Note that you can add command line options using addOptions in the driver config: https://firefox-source-docs.mozilla.org/testing/geckodriver/TraceLogs.html

The "WebDriver" way to switch the log level is by using the driver "capabilities". Refer the above link and see if you can set this for FireFox. It would be good if you post back your findings so that it helps others. In Karate, you use the webDriverSession to configure this.

The logs will be in some file. You should be able to write some code to scrape from it any time during a test if they don't show up in the HTML report.

If you need something more, please consider contributing code.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248