BeanShell Assertion in Jmeter

以下为几个beanshell assertion的栗子:

if (ResponseCode != null && ResponseCode.equals ("200") == false )
{
// this is standard stuff
Failure=true ;
FailureMessage ="Response code was not a 200 response code it was " + ResponseCode + "." ;
print ( "the return code is " + ResponseCode);   // this goes to stdout
log.warn( "the return code is " + ResponseCode); // this goes to the JMeter log file
} else {
String body= new String(ResponseData);
if(!body.contains("pagekey-abook_imported_contacts_to_invite"))
{
Failure= true ;
FailureMessage = "expected pagekey-abook_imported_contacts_to_invite != " + vars.get("pagekey");
print("DisplayImportedContacts failed for ticketId=" + vars.get("polling_id"));
log.warn("DisplayImportedContacts failed for ticketId=" + vars.get("polling_id"));
}
}

或者

String result = vars.getObject("result").get(0).get("mobile");

String actresult = "18XXXX405";

if(result.equals(actresult)){
log.info("注册人的推荐用户测试通过");
} else {
Failure = true;
FailureMessage="注册人的推荐用户测试失败:"+"预期结果为"+actresult+", 实际结果为"+result;
log.info("注册人的推荐用户测试失败:"+"预期结果为"+actresult+", 实际结果为"+result );
}

 http://www.beanshell.org

原文地址:https://www.cnblogs.com/yingchen/p/5191142.html