1. 程式人生 > 實用技巧 >jmeter之BeanShell Sampler實現提取的引數加減

jmeter之BeanShell Sampler實現提取的引數加減

  1. https://www.cnblogs.com/only-love-you-519920/archive/2004/01/13/8135497.html
  2. 首先建立一個請求,新增正則提取響應資料中的引數(測試資料:訪問的是百度主頁,提取的是width欄位),以下是+,減的話在java檔案中修改return即可

  3. 新增一個前置處理器-->使用者引數,使用者存放提取的資料

  4. 編寫一個java加減指令碼,(在此申明的變數a為String型別,b為int型別)

  5. 將儲存的java檔案引用在BeanShell Sampler中

  6. 寫入提取的引數

  7. 檢視執行結果

  8. 如果是兩個提取的數相加,則要改java檔案型別

  9. 檢視結果

    public class PrintScore {
        public static void main(String[] args) {
    
            // 建立物件,物件名為a
            PrintScore a = new PrintScore();
    
            int rSum;  //設定一個int型變數,用來接收方法的返回值
    
            // 呼叫方法,傳入兩門課程的成績
            rSum = a.calcSum(78,99);
            System.out.println("總分:"+ rSum);
        }
    
        /*
         * 功能:計算兩門課程考試成績的總分並輸出總分
         * 定義一個包含兩個引數的方法,用來傳入兩門課程的成績
         */
        public int calcSum(int a, int b){
                int sum= a + b;
                return sum;
        }
    }
  10. 。。。。。。。。。。。。。。