JMeter中BeanShell用法總結(一)

2022-06-22 15:57:13 字數 1159 閱讀 6318

一、什麼是bean shell

二、jmeter有哪些bean shell

三、beanshell的用法

通過例項講解beanshell的用法

使用場景:手機號註冊,登入,綁卡業務

實現隨機生成不重複的手機號的兩種方式:

1.註冊介面引數:

merchant_id=00000001&bizcode=uums_user_register&mobile=13$&password=888888

此種方式,是通過jmeter自帶的random函式,生成某個範圍內的隨機數,然後後面的登入業務,直接引用13$即可

登入介面:

merchant_id=00000001&bizcode=uums_login&login_type=104&login_account=13$&password=888888

方式2:

通過beanshell實現:

string time = "$"

;int arr = ;

int index=(int)(math.random()*arr.length);//

產生0-(arr.length-1)的整數值,也是陣列的索引

int rand =arr[index];

string time =time.substring(6,13

);vars.put(

"phone

",rand+""+$+""+time+""+$);

//如果在測試過程中,存在重複,也可以構造其他隨機數

//1476063656393

//6063697317

//063754461

注意:beanshell放置註冊取樣器的下面和放在測試用例下的區別:

每次都會執行beanshell sampler一次

放在註冊取樣器下:每次只執行一次:

Jmeter後置處理器之BeanShell

1.log 列印日誌,寫入資訊到jmeber.log檔案。2.sampleresult 獲取sampleresult物件,能通過這個物件獲取想要的資訊。3.response 獲取response物件,能通過這個物件獲取響應資訊。4.failure 檢視介面調使用能否成功,假如返回false是成功的,...

Jmeter七 jmeter中的引數化

引數化是為了更好的模擬真實的業務場景 csv data set config元件 1.更容易使用和理解 2.適合大參數量場景 3.設定方便靈活 eof end of file 沒有找到檔案 comma delimited 逗號分隔 不指定變數名時,第一行作為變數名。檔案最末尾有一行空行不影響 當用逗...

JMeter中BeanShell實現寫入檔案

1.首先f test.txt檔案為空 2.定義jmeter引數 3.編寫beanshell public static void execparam string getdata vars.get v2 string getdata string filename f test.txt filewr...