You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过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:

Opening Chrome's Network Panel Automatically

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.

Toggling Chrome Offline Mode via Katalon

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 v118 in 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 19:17:39