如果你想從頭學習Jmeter,可以看看這個系列的文章哦
https://www.cnblogs.com/poloyy/category/1746599.html
前提
BeanShell 有的內置變量,JSR223 也會有對應的變量,這里 JSR223 效率更高,所以以它為栗子
簡單介紹
- ctx 變量是JMeter JSR223功能最強大的內置變量之一
- 通過它可以輕松的訪問當前線程的上下文
- 在 JMeter 內部,ctx 映射為 org.apache.jmeter.threads 的 JMeterContext 類
- 由於JMeterContext 不具有線程安全性,故僅適用於在單線程中使用
- 官方文檔: https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
ctx 常用方法
getVariables
方法聲明
public JMeterVariables getVariables()
功能
獲取JMeter當前線程的所有變量
栗子
getProperties
方法聲明
public Properties getProperties()
功能
獲取所有的JMeter屬性
栗子
getPreviousResult
方法聲明
public SampleResult getPreviousResult()
功能
獲取前一個取樣器的結果
栗子
獲取前一個 sampler 的響應內容
getCurrentSampler
方法聲明
public Sampler getCurrentSampler()
功能
獲取當前取樣器對象
栗子
getPreviousSampler
方法聲明
public Sampler getPreviousSampler()
功能
獲取前一個取樣器對象
栗子
getThreadNum
方法聲明
public int getThreadNum()
功能
獲取當前線程組下的線程編號(編號從0開始)
栗子
getThread
方法聲明
public JMeterThread getThread()
功能
獲取線程對象
栗子
getThreadGroup
方法聲明
public AbstractThreadGroup getThreadGroup()
功能
獲取線程組對象
栗子