java自定義jar包讓jmeter使用的方法
上一篇文章中,提到怎么生成jar包讓jmeter使用,這次我們來試試做參數(shù),因?yàn)榘l(fā)現(xiàn)調(diào)包的時(shí)候其實(shí)更多還是參數(shù)化,那么開始改造吧
1.在httpclientpost這個(gè)類中替換參數(shù),且打印參數(shù)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
public class httpclientPost {
public static int sendpost(String email,String value) throws ClientProtocolException, IOException {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost post = new HttpPost("https://user.zaful.com/m-users-a-act_sign.htm?pipeline=zf");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("password", value));
post.setEntity(new UrlEncodedFormEntity(params));
CloseableHttpResponse response2 = httpclient.execute(post);
int code = response2.getStatusLine().getStatusCode();
HttpEntity http = response2.getEntity();
InputStream instreams = http.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(instreams));
StringBuffer buffer = new StringBuffer();
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line + "br ");
}
reader.close();
System.out.println("email: "+email +" password:"+value);
System.out.println(code +" respones:"+buffer);
return code;
}
}
在addcomputerInfo中實(shí)現(xiàn)getDefaultParameters方法,這步很重要
//參數(shù)化方法
@Override
public Arguments getDefaultParameters() {
// TODO Auto-generated method stub
Arguments arguments=new Arguments();
arguments.addArgument("email","");
arguments.addArgument("value","");
return arguments;
}
public SampleResult runTest(JavaSamplerContext arg0) {
// TODO Auto-generated method stub
SampleResult result=new SampleResult();
result.sampleStart(); //事務(wù)啟動(dòng)
try { //參數(shù)化方法的使用
int responeCode=httpclientPost.sendpost(arg0.getParameter("email"),arg0.getParameter("value"));
if (responeCode==200) {
result.setSuccessful(true);
}else {
result.setSuccessful(false);
}
} catch (ClientProtocolException e) {
result.setSuccessful(false);
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
result.setSuccessful(false);
e.printStackTrace();
}
result.sampleEnd();//事務(wù)關(guān)閉
return result;
}
public static void main(String[] args) {
new addcomputerInfo().runTest(new JavaSamplerContext(new Arguments()));
}
三、重新打包
四:jmeter使用
可以看到已經(jīng)加載了兩個(gè)參數(shù),我們給下面參數(shù)做個(gè)參數(shù)化,增加一個(gè)計(jì)數(shù)器

增加計(jì)數(shù)器,每次遞增1,每次填充0001

使用:

運(yùn)行,因?yàn)槎际菦]有注冊的用戶,所以都是錯(cuò)誤


以上就是本次介紹的全部相關(guān)知識(shí)點(diǎn),感謝大家的學(xué)習(xí)和對腳本之家的支持。
相關(guān)文章
Java實(shí)現(xiàn)Excel導(dǎo)出并添加水印
這篇文章主要為大家詳細(xì)介紹了Java如何使用poi-ooxml包導(dǎo)出xlsx添加水印,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-11-11
如何用匿名內(nèi)部類實(shí)現(xiàn) Java 同步回調(diào)
這篇文章主要介紹了如何用匿名內(nèi)部類實(shí)現(xiàn) Java 同步回調(diào),幫助大家更好的理解和學(xué)習(xí)Java,感興趣的朋友可以了解下2020-10-10
java基于正則表達(dá)式實(shí)現(xiàn)時(shí)間日期的常用判斷操作實(shí)例
這篇文章主要介紹了java基于正則表達(dá)式實(shí)現(xiàn)時(shí)間日期的常用判斷操作,簡單說明了正則表達(dá)式常用元字符含義并結(jié)合實(shí)例形式分析了java基于正則表達(dá)式針對常用日期時(shí)間格式的判斷操作技巧,需要的朋友可以參考下2017-10-10
關(guān)于SpringBoot大文件RestTemplate下載解決方案
這篇文章主要介紹了SpringBoot大文件RestTemplate下載解決方案,最近結(jié)合網(wǎng)上案例及自己總結(jié),寫了一個(gè)分片下載tuling/fileServer項(xiàng)目,需要的朋友可以參考下2021-10-10
springboot項(xiàng)目docker分層構(gòu)建的配置方式
在使用dockerfile構(gòu)建springboot項(xiàng)目時(shí),速度較慢,用時(shí)比較長,為了加快構(gòu)建docker鏡像的速度,采用分層構(gòu)建的方式,這篇文章主要介紹了springboot項(xiàng)目docker分層構(gòu)建,需要的朋友可以參考下2024-03-03

