Verify some Javascript errors from console browser

How add step to verify Javascript errors.
Into browser, how check console of F12 developer tools (Chrome or Firefox)

Thanks.

I have the same demand.

According to this topic: https://stackoverflow.com/questions/25431380/capturing-browser-logs-with-selenium-webdriver-using-java, you can apply the same code in Katalon Studio to generate Javascript error. Below code is an example regarding to PRINT it out, you need to add verifications by your own:

import org.openqa.selenium.WebDriver

import org.openqa.selenium.logging.LogEntries

import org.openqa.selenium.logging.LogEntry

import com.kms.katalon.core.webui.driver.DriverFactory

WebDriver driver = DriverFactory.getWebDriver()

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

for (LogEntry entry : logs) {

println entry.getLevel() + " " + entry.getMessage()

}

2 Likes

Is it possible to clear all logs Vinh ? @Vinh Nguyen

Vinh Nguyen said:

According to this topic: https://stackoverflow.com/questions/25431380/capturing-browser-logs-with-selenium-webdriver-using-java, you can apply the same code in Katalon Studio to generate Javascript error. Below code is an example regarding to PRINT it out, you need to add verifications by your own:

import org.openqa.selenium.WebDriver

import org.openqa.selenium.logging.LogEntries

import org.openqa.selenium.logging.LogEntry

import com.kms.katalon.core.webui.driver.DriverFactory

WebDriver driver = DriverFactory.getWebDriver()

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

for (LogEntry entry : logs) {

println entry.getLevel() + " " + entry.getMessage()

}

It should be noted this does not and will not work in Firefox.

https://bugzilla.mozilla.org/show_bug.cgi?id=1453962

Hi,

I have tried to use the script but I verified this error:

Test Cases/Javascript errors FAILED because (of) groovy.lang.MissingMethodException: No signature of method: java.util.logging.Level.plus() is applicable for argument types: (java.lang.String) values: [ ]
Possible solutions: parse(java.lang.String), use([Ljava.lang.Object;), is(java.lang.Object), split(groovy.lang.Closure), wait(), find()

The error has been verified for this line:

println entry.getLevel() + " " + entry.getMessage()

Can you help me please?

Thanks

As suggested here, try:

println entry.getLevel().toString() + " " + entry.getMessage()

Oh thanks! Now it’s works.

Can there be a way to sort messages by type of error?

Thank you very much!

import org.openqa.selenium.WebDriver as WebDriverimport org.openqa.selenium.logging.LogEntries as LogEntriesimport org.openqa.selenium.logging.LogEntry as LogEntryimport com.kms.katalon.core.webui.driver.DriverFactory as DriverFactoryimport internal.GlobalVariable as GlobalVariableimport com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUIimport com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobileimport com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSimport static com.kms.katalon.core.testobject.ObjectRepository.findTestObjectimport static com.kms.katalon.core.testdata.TestDataFactory.findTestDataimport static com.kms.katalon.core.testcase.TestCaseFactory.findTestCaseimport static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpointimport com.kms.katalon.core.model.FailureHandling as FailureHandlingimport com.kms.katalon.core.testcase.TestCase as TestCaseimport com.kms.katalon.core.testdata.TestData as TestDataimport com.kms.katalon.core.testobject.TestObject as TestObjectimport com.kms.katalon.core.checkpoint.Checkpoint as CheckpointWebUI.openBrowser('http://only-testing-blog.blogspot.com/2015/01/table-with-checkbox.html')appendBrowserLogs()void appendBrowserLogs() {    WebDriver driver = DriverFactory.getWebDriver()    LogEntries logs = driver.manage().logs().get('browser')    for (LogEntry logEntry : logs) {        if (logEntry.getMessage().toLowerCase().contains('error')) {            System.err.println('Error Message in Console:' + logEntry.getMessage())        } else if (logEntry.getMessage().toLowerCase().contains('warning')) {            System.out.println('Warning Message in Console:' + logEntry.getMessage())        } else {            System.out.println('Information Message in Console:' + logEntry.getMessage())        }    }}  

Which desired capabilities might you use for chrome to get the info logs? I’ve tried --enable-logging, --verbose and --log-level=INFO but no luck.

How to do that with IE browser?