maxfair
November 26, 2025, 8:15am
1
For example, I created a html file that outputs a statement (test.html):
<body onload="console.log('test')"></body>
also created a function to test if console log is non-empty, which test() would be called during testing to check if there is any log printed:
package com.example.keywords
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.webui.driver.DriverFactory
import org.openqa.selenium.WebDriver
import org.openqa.selenium.logging.LogEntry
import org.openqa.selenium.logging.LogType
public class TestKeywords {
private static List<LogEntry> cachedLogs = []
@Keyword
def test() {
assert !DriverFactory.getWebDriver().manage().logs().get(LogType.BROWSER).getAll().isEmpty()
return true
}
}
When test.html is put into the server and run the test, the test passed:
but when move test.html out of server and change the url to local file, the test failed:
what is the reason?
2 Likes
Dear maxfair,
Thank you for your question, from what I have found in our library this can be explained this way:
It’s happening because of how the browser + WebDriver handle console logs for file:// pages , not because of Katalon or your code.
What’s going on?
When you open:
file:///.../test.html
most modern browsers (Chrome, Edge, etc.) treat this as a local file origin , which has a stricter / special security model.
Solution :
Use a Local Web Server (Recommended) Instead of opening the file directly, serve it locally:
// Use a simple HTTP server to serve your local HTML file
// Option A: Python (if installed)
// python -m http.server 8000
// Option B: Node.js (if installed)
// npx http-server
// Then access it via: http://localhost:8000/test.html
This can be the most reliable approach and aligns with how web applications are actually tested in production environments. This eliminates the security restrictions and ensures your tests behave consistently.
Let us know if that helps
Bella
1 Like
depapp
November 26, 2025, 8:32am
3
hi @maxfair
when you load via file://, chrome treats it as a "null origin" and the logging APIs behave differently (or just don’t work)
quickest fix: cd to your html folder and run python -m http.server 8080, then hit http://localhost:8080/test.html
so Navigate To Url value should be http://localhost:8080/test.html instead of file://Users/testUser/xxxxxx
2 Likes