亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 Java 代碼在 Jmeter .jmx 文件中添加正則表達式提取器和 cookie

如何使用 Java 代碼在 Jmeter .jmx 文件中添加正則表達式提取器和 cookie

波斯汪 2023-03-02 15:12:02
我正在使用 Java 代碼為 Jmeter GUI 編寫一個 .jmx 文件。我想從用于“登錄”的 HTTP 代理采樣器中提取 GET 響應,該響應用作識別用戶的會話 ID。此外,我需要下一個采樣器來使用正在提取的變量。此外,我還需要為每個線程組配備一個 cookie 管理器。我應該調用哪個 API 來將提取器添加到 http 代理采樣器并將 cookie 管理器添加到線程組?我已經創建了 http 采樣器,設置了路徑并設置了參數。我現在需要的只是一個提取器來幫助我獲取變量和一個 cookie 管理器下面是我創建線程組并將 http 采樣器添加到線程組的代碼HashTree testPlanTree = new ListedHashTree();        TestPlan testPlan = new TestPlan("Create JMeter Script From Java Code");        testPlanTree.add(testPlan);        HTTPSamplerProxy newSampler = null;        LoopController loopController;        ThreadGroup threadGroup = null;        HashTree threadGroupHashTree = null;        int i = 1; // exclude the first empty call        for (ArrayList<String> elementList : calls) {            if (elementList.size() == 3) {                System.out.println(elementList);                loopController = new LoopController();                loopController.setLoops(1);                loopController.setFirst(true);                loopController.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());                loopController.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());                loopController.initialize();            }
查看完整描述

1 回答

?
浮云間

TA貢獻1829條經驗 獲得超4個贊

  1. HTTP Cookie 管理器

    CookieManager cookieManager = new CookieManager();
    cookieManager.setName("HTTP Cookie Manager");
    cookieManager.setProperty(TestElement.TEST_CLASS, CookieManager.class.getName());
    cookieManager.setProperty(TestElement.GUI_CLASS, CookiePanel.class.getName());
  2. 正則表達式提取器

    RegexExtractor regexExtractor = new RegexExtractor();
    regexExtractor.setName("Regular Expression Extractor");
    regexExtractor.setProperty("RegexExtractor.useHeaders", "false");
    regexExtractor.setProperty("RegexExtractor.refname", "yourVariable");
    regexExtractor.setProperty("RegexExtractor.regex", "yourRegex");
    regexExtractor.setProperty("RegexExtractor.template", "yourTemplate");
    regexExtractor.setProperty("RegexExtractor.match_number", "yourMatchNumber");
    regexExtractor.setProperty("RegexExtractor.default", "yourDefaultValue");
    regexExtractor.setProperty(TestElement.TEST_CLASS, RegexExtractor.class.getName());
    regexExtractor.setProperty(TestElement.GUI_CLASS, RegexExtractorGui.class.getName());

查看在不使用 JMeter GUI 的情況下啟動 JMeter 測試的五種方法,以了解有關運行 JMeter 測試的不同選項的更多信息,包括以編程方式創建測試計劃。


查看完整回答
反對 回復 2023-03-02
  • 1 回答
  • 0 關注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號