如何通过Katalon打开Chrome Network面板并控制浏览器离线/在线
Got it, let's break down how to handle both your requirements in Katalon Studio—opening the Chrome Network panel and toggling offline mode. Here's a step-by-step guide tailored to your test workflow:
To launch Chrome with the Network panel pre-opened (so you can verify offline mode visually if needed), you can configure Chrome's launch arguments in Katalon. Follow these steps:
- Open your Katalon test case and switch to the Script view.
- Add the following code to set up ChromeOptions with the devtools flags:
import org.openqa.selenium.chrome.ChromeOptions import com.kms.katalon.core.webui.driver.DriverFactory ChromeOptions options = new ChromeOptions() // Auto-open DevTools for every new tab options.addArguments("--auto-open-devtools-for-tabs") // Set DevTools to default to the Network panel options.addArguments("--devtools-panel=network") // Apply these options to the Chrome driver DriverFactory.changeWebDriver(DriverFactory.getChromeDriver(options))
This will launch Chrome with DevTools automatically opened and focused on the Network panel right from the start.
To programmatically enable/disable offline mode (mirroring the "Offline" checkbox in the Network panel), you’ll use the Chrome DevTools Protocol (CDP) through the active WebDriver instance. Here’s how to integrate this into your test steps:
Enable Offline Mode
Add this snippet where you need to switch your test to offline:
import org.openqa.selenium.devtools.DevTools import org.openqa.selenium.devtools.v118.network.Network import com.kms.katalon.core.webui.driver.DriverFactory import java.util.Optional // Get the active ChromeDriver instance def driver = DriverFactory.getWebDriver() DevTools devTools = driver.getDevTools() // Initialize the Network domain in DevTools devTools.createSession() devTools.send(Network.enable()) // Emulate full offline conditions devTools.send(Network.emulateNetworkConditions( true, // offline status 0, // latency (ms) 0, // download throughput (bps) 0, // upload throughput (bps) Optional.empty() // connection type )) // Optional: Add a short delay to ensure the setting takes effect WebUI.delay(2)
Restore Online Mode
When you’re ready to run the remaining test steps online, use this code:
// Re-enable network connectivity devTools.send(Network.emulateNetworkConditions( false, // offline status set to false 1000, // normal latency 100000, // normal download speed 100000, // normal upload speed Optional.empty() )) // Clean up: Disable the Network domain if no longer needed devTools.send(Network.disable())
Key Notes:
- Ensure your Katalon Studio uses a ChromeDriver version that matches your installed Chrome browser (this avoids compatibility issues with the CDP commands).
- The
v118in the import path (org.openqa.selenium.devtools.v118.network.Network) corresponds to Chrome version 118. Adjust this number to match your Chrome’s major version if you’re using a newer or older build.
内容的提问来源于stack exchange,提问作者srianoop

