獲取 XHR 響應(網絡流量)並在 Katalon Studio 中解析 (Get XHR response (network traffic) and parse it in Katalon Studio)


問題描述

獲取 XHR 響應(網絡流量)並在 Katalon Studio 中解析 (Get XHR response (network traffic) and parse it in Katalon Studio)

如何讀取 XHR 響應並在 Katalon Studio 中解析它?

我目前使用一種解決方法來測試我的應用程序的響應能力:我使用各種 waitForElement_*_() (*=visible, clickable, present, not‑visible, not‑clickable, not‑present) 命令以測量各種元素的加載時間。

我想更具體一些並測量網絡請求的持續時間(可以在 DevTools ‑ 網絡流量中看到)。

可以做到嗎?


參考解法

方法 1:

I am not sure if it can be done using Katalon studio. I am replying to your post, because I use network traffic information to derive performance numbers, and I use browsermobproxy.

Needless to say, this reply does not answer your question, just an option of using browsermobproxy

How to access the values of Chrome's Dev tools Network tab's Request or summary using Selenium in python/java?

方法 2:

In Katalon 7 and with and with Chrome DevTools Protocol Integration plugin, as was described here you can intercept network requests.

The following example shows how to mock search requests in Wikipedia so that the result will always be “Katalon Studio”.

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.github.kklisura.cdt.protocol.commands.Fetch as Fetch
import com.github.kklisura.cdt.protocol.commands.Page as Page
import com.github.kklisura.cdt.services.ChromeDevToolsService as ChromeDevToolsService
import com.katalon.cdp.CdpUtils as CdpUtils
import com.kms.katalon.core.util.internal.Base64 as Base64
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject

WebUI.openBrowser('')
ChromeDevToolsService cdts = CdpUtils.getService()
Page page = cdts.getPage()
Fetch fetch = cdts.getFetch()
fetch.onRequestPaused({ def requestIntercepted ‑>
    String interceptionId = requestIntercepted.getRequestId()
    String url = requestIntercepted.getRequest().getUrl()
    boolean isMocked = url.contains('api.php')
    String response = '["Katalon Studio",["Katalon Studio"],["Katalon Studio is an automation testing solution developed by Katalon LLC."],["https://en.wikipedia.org/wiki/Katalon_Studio"]]'
    String rawResponse = Base64.encode(response)
    System.out.printf('%s ‑ %s%s', isMocked ? 'MOCKED' : 'CONTINUE', url, System.lineSeparator())
    if (isMocked) {
        fetch.fulfillRequest(interceptionId, 200, new ArrayList(), rawResponse, null)
    } else {
        fetch.continueRequest(interceptionId)
    }
})

fetch.enable()
page.enable()
WebUI.navigateToUrl('https://en.wikipedia.org/wiki/Main_Page')
TestObject searchInput = new TestObject().addProperty('css', ConditionType.EQUALS, '#searchInput')
TestObject containing = new TestObject().addProperty('xpath', ConditionType.EQUALS, "//div[div[contains(.,'containing...')]]")
WebUI.setText(searchInput, 'Intercept request')
WebUI.waitForElementVisible(containing, 10)

NOTES:

Original post on Katalon forum: https://forum.katalon.com/t/intercepting‑request‑with‑chrome‑devtools‑protocol/36081.

Sample project used in this topic: https://github.com/katalon‑studio‑samples/katalon‑studio‑chrome‑devtools‑protocol‑plugin‑samples.

The plugin uses https://github.com/kklisura/chrome‑devtools‑java‑client to connect to CDP.

(by Mate MršeSatishMate Mrše)

參考文件

  1. Get XHR response (network traffic) and parse it in Katalon Studio (CC BY‑SA 2.5/3.0/4.0)

#automated-tests #network-traffic #katalon-studio #selenium #XMLHttpRequest






相關問題

編寫“單元測試”代碼? (Writing "unit testable" code?)

按順序運行 TestNG 組並在每個組中並行測試 (Run TestNG groups sequentially and tests in each group in parallel)

需要從 VS2012 單元測試中識別我的 .csproj 文件 (Need to identify my .csproj file from VS2012 unit tests)

ANT 構建失敗並在 html 報告中給出 classNotFoundExceeption (ANT build fails and gives classNotFoundExceeption in html report)

測試有狀態的 Mojolicious 應用程序 (Testing stateful Mojolicious apps)

如何在 Rails 測試中斷言圖像源 (How to assert image source in rails test)

如果兩個塊中都出現錯誤,如何處理 Given/When/Then 語句和 AfterScenario 鉤子中的錯誤 (How to handle error in Given/When/Then statements and AfterScenario hook if error pops in both blocks)

如何發送帶有損壞 FCS 的以太網幀? (How do you send an Ethernet frame with a corrupt FCS?)

如何在嵌入式系統中執行回歸測試 (How to perform regression tests in embedded systems)

是否有 .NET 版本的 Concordion? (Is there a .NET version of Concordion?)

如何在 Ready API 中動態創建屬性? (How to create properties in Ready API dynamically?)

嘗試測試腳本 spec.ts 失敗,因為期望(如返回)在創建響應到來之前執行並在控制台中顯示未定義 (Trying Test Scripts spec.ts fails because expect(like return) executes before create response came and shows undefined in console)







留言討論