Can I log browser console errors?

Just like this error. The most important for me is error type.

According to this article: https://stackoverflow.com/questions/25431380/capturing-browser-logs-with-selenium, you can apply it in Katalon Studio using the same approach. Please find below sample code:

import org.openqa.selenium.WebDriver
import org.openqa.selenium.logging.LogEntries
import org.openqa.selenium.logging.LogEntry

LogEntries logs = driver.manage().logs().get(“browser”)

for (LogEntry entry : logs) {
println entry.getMessage()
}

1 Like

Thanks a lot :slight_smile:

Can you please share details of where to enter this snippet?

Benjamin McFerren said:

Can you please share details of where to enter this snippet?

It should be entered AFTER ‘Open Browser’ step to retrieve its driver.

thanks Vinh. Being new to Katalon and new to e2e in general, I was a bit lost when I wrote this earlier. In an effort to help future newbies like myself: this goes inside Katalon studio (not Katalon chrome extension). It goes in the Script tab and is responsible for generating additional command strings that intermingle with new commands entered when in the Manual tab

Vinh Nguyen said:

According to this article: https://stackoverflow.com/questions/25431380/capturing-browser-logs-with-selenium, you can apply it in Katalon Studio using the same approach. Please find below sample code:

import org.openqa.selenium.WebDriver

import org.openqa.selenium.logging.LogEntries

import org.openqa.selenium.logging.LogEntry

LogEntries logs = driver.manage().logs().get(“browser”)

for (LogEntry entry : logs) {

println entry.getMessage()

}

can you please explain a but more how to use it? i pasted it after open browser but do not know how and when to use the for loop. should i use it after every step to retrieve the console logs or at the end?

1 Like

I have the same question as tamanna
How do I use this code properly?
For example I have this test (made manually):

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpointimport static com.kms.katalon.core.testcase.TestCaseFactory.findTestCaseimport static com.kms.katalon.core.testdata.TestDataFactory.findTestDataimport static com.kms.katalon.core.testobject.ObjectRepository.findTestObjectimport com.kms.katalon.core.checkpoint.Checkpoint as Checkpointimport com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactoryimport com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywordsimport com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobileimport com.kms.katalon.core.model.FailureHandling as FailureHandlingimport com.kms.katalon.core.testcase.TestCase as TestCaseimport com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactoryimport com.kms.katalon.core.testdata.TestData as TestDataimport com.kms.katalon.core.testdata.TestDataFactory as TestDataFactoryimport com.kms.katalon.core.testobject.ObjectRepository as ObjectRepositoryimport com.kms.katalon.core.testobject.TestObject as TestObjectimport com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywordsimport com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSimport com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywordsimport com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUIimport internal.GlobalVariable as GlobalVariableWebUI.openBrowser('')WebUI.navigateToUrl(GlobalVariable.baseUrl)WebUI.setText(findTestObject('MyProject/input_form-control input-lg lo'), GlobalVariable.ownerLgn)WebUI.setText(findTestObject('MyProject/input_form-control input-lg lo_1'), GlobalVariable.ownerPwd)WebUI.click(findTestObject('MyProject/span_Login'))WebUI.verifyElementPresent(findTestObject('MyProject/h1_HOME PAGE'), 10)WebUI.closeBrowser()

So basically I want to catch all errors that can occur on baseUrl and after login

I understand it’s should be easy but can someone show me how to use this code in the test that I provided above?

I have made a demo for getting JavaScript Console log from Google Chrome browser to Katalon Studio:

Here is the link to my demo test case:

-----

Please note: You can not get JavaScript Console log from FireFox browser. You can get it from Google Chrome though.
See http://forum.katalon.com/discussion/comment/19634 also

3 Likes

kazurayam thanks a lot. It works like a charm
I don’t quite understand what for is the “if” statement here, but at least it works now and shows me all of the errors.
I will continue to dig deeper for better understanding

I don’t quite understand what for is the “if” statement here,

The if statement in the test case script is solely because of my own special reason. The reason is described in the following post:

You can safely delete the if statement, so that you will have a single line:

WebUI.openBrowser('')

kazurayam said:

I don’t quite understand what for is the “if” statement here,

The if statement in the test case script is solely because of my own special reason. The reason is described in the following post:
Google Chrome crashed on my PC --- 2 reasons found - Tips & Tricks - Katalon Community

You can safely delete the if statement, so that you will have a single line:

WebUI.openBrowser('')

In case I delete the IF statement at the begging of the test this test fails: executedBrowser is not defined

This method doesn’t seem to be working for Firefox. What’s the way to get console Logs for Firefox??

See my previous post just for your information.

W3C WebDriver Specification does not support querying console log. Firefox strictly complies with the W3C specification. Therefore Firefox intentionally does not support passing console logs out.

No hope. You should give up.

Okay. Thanks for the info.

Conclusion: We can’t get Console Logs from Firefox with Katalon.

By the way, Katalon Studio has a plugin to integrate with Chrome Developer Tool Set

1 Like

2 posts were split to a new topic: How to get Katalon Info logs

@kazurayam I just tried to do this

driver.get(SuiteVars.WebTabUrl()) ---- > I am opening the application which is deployed on web

WebUI.delay(15)

WebDriver driver = DriverFactory.getWebDriver()

LogEntries logs = driver.manage().logs().get(“browser”)

for (LogEntry entry: logs){

println(entry.getMessage())

}

Hi all,

I tried to use the code to print the console errors in Katalon.

WebDriver driver = DriverFactory.getWebDriver()
LogEntries logs = driver.manage().logs().get(“browser”)
for (LogEntry entry : logs)
{
println entry.getLevel().toString() + " " + entry.getMessage()
}

However, it prints several error messages that doesn’t actually appear in the browser Console when I checked the Devtools. The error messages printed in Katalon is shown below: