如何通過Java編碼生成Jmeter儀表板報告。(不是Windows或Shell命令)
Summariser summer = null; String summariserName = JMeterUtils.getPropDefault('summariser.name', 'summary'); if (summariserName.length() > 0) {summer = new Summariser(summariserName); } String logFile = '/path/to/result.jtl'; ResultCollector logger = new ResultCollector(summer); logger.setFilename(logFile); testPlanTree.add(testPlanTree.getArray()[0], logger);然后,您需要設置HTML Reporting Dashboard目標:
JMeterUtils.setProperty(JMETER_REPORT_OUTPUT_DIR_PROPERTY, '/where/you/want/the/dashboard/to/be/generated');最后,您可以像這樣調用ReportGenerator類:
ReportGenerator generator = new ReportGenerator(logFile,null); generator.generate();
完整的代碼,以防萬一:
import org.apache.jmeter.engine.StandardJMeterEngine; import org.apache.jmeter.report.dashboard.ReportGenerator; import org.apache.jmeter.reporters.ResultCollector; import org.apache.jmeter.reporters.Summariser; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.collections.hashtree; import java.io.File; import static org.apache.jmeter.JMeter.JMETER_REPORT_OUTPUT_DIR_PROPERTY; public class RunJMeterTest {public static void main(String[] args) throws Exception { StandardJMeterEngine jmeter = new StandardJMeterEngine(); JMeterUtils.loadJMeterProperties('/path/to/your/jmeter/bin/jmeter.properties'); JMeterUtils.setJMeterHome('/path/to/your/jmeter'); JMeterUtils.initLocale(); SaveService.loadProperties(); hashtree testPlanTree = SaveService.loadTree(new File('/path/to/your/jmeter/bin/test.jmx')); Summariser summer = null; String summariserName = JMeterUtils.getPropDefault('summariser.name', 'summary'); if (summariserName.length() > 0) {summer = new Summariser(summariserName); } String logFile = '/path/to/your/jmeter/bin/result.jtl'; ResultCollector logger = new ResultCollector(summer); logger.setFilename(logFile); testPlanTree.add(testPlanTree.getArray()[0], logger); jmeter.configure(testPlanTree); jmeter.run(); JMeterUtils.setProperty(JMETER_REPORT_OUTPUT_DIR_PROPERTY, '/path/to/dashboard'); ReportGenerator generator = new ReportGenerator(logFile, null); generator.generate();} }
參考文獻:
生成報告儀表板在不使用JMeter GUI的情況下啟動JMeter測試的五種方法解決方法我必須通過Java編碼生成Jmeter儀表板報告。在Java代碼下面,我曾用來生成普通的jmeter報告。我必須通過Java生成儀表板報告。
public class JMeterFromExistingJMX { public static void main(String[] argv) throws Exception {// JMeter EngineStandardJMeterEngine jmeter = new StandardJMeterEngine();// Initialize Properties,logging,locale,etc.// JMeterUtils.loadJMeterProperties('/path/to/your/jmeter/bin/jmeter.properties');JMeterUtils.setJMeterHome('/path/to/your/jmeter');JMeterUtils.initLogging();// logJMeterUtils.initLocale();// Initialize JMeter SaveServiceSaveService.loadProperties();// Load existing .jmx Test PlanFileInputStream in = new FileInputStream ('/path/to/your/jmeter/extras/Test.jmx');HashTree testPlanTree = SaveService.loadTree(in);in.close();// Run JMeter Testjmeter.configure(testPlanTree);jmeter.run(); } } }
相關文章:
1. javascript - 如何用最快的速度C#或Python開發一個桌面應用程序來訪問我的網站?2. 前端 - 使用vue2服務端渲染的時候,如何在服務端請求數據,然后給vue渲染3. javascript - 看一些高手寫代碼單獨用 “$”和“_” 來表示變量,什么時候單獨使用這兩個字符?4. javascript - weex和node,js到底是怎樣一個關系呢?5. mysql 存儲過程 和 函數有什么用??6. python - 關于beautifulsoup獲取文檔內容7. java - springMVC配置的controller無法返回jsp文件8. html5 - video ios不能播放怎么辦?9. css - 如何選擇字體?10. mysql - jdbc的問題
