我有 JMeter 脚本,它将 3 种类型的 XML 请求发送到 Web 服务。
例如,对于第二种类型 - SOAPMethod 'getHeadlines' 我发送这个 XML 请求:
<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header/>
<S:Body>
<ns2:getHeadlines xmlns:ns2="http://******.com/">
<startDate>${startDate}</startDate>
<endDate>${endDate}</endDate>
<contributor>${randomNameContributor2}</contributor>
<topic>${randomNameTopic2}</topic>
<maxCount>${maxCount}</maxCount>
</ns2:getHeadlines>
</S:Body>
</S:Envelope>
我用
BeanShell 预处理器 2.1 - 用于获取随机 {randomNameContributor2}:
String[] argsCrnt21=vars.getObject("arrayOfContributors"); //initialization of array
int randomElement=(int)(Math.random()*argsCrnt21.length ); //random element number
vars.put("randomNameContributor2", argsCrnt21[randomElement] ); //initialization of random variable for 'randomNameContributor2'
并且类比我使用
BeanShell 预处理器 2.2 - 用于获取随机 {randomNameTopic2}:
String[] argsCrnt22=vars.getObject("arrayOfTopics"); //initialization of array
int randomElement=(int)(Math.random()*argsCrnt22.length ); //random element number
vars.put("randomNameTopic2", argsCrnt22[randomElement] ); //initialization of random variable for 'randomNameTopic2'
常量 ${maxCount}` 在 JMeter 的用户定义变量部分中预定义。
为了获取变量${RandomStartDate}
和${RandomEndDate}
(我需要从 [06-01-2011; 07-31-2012] 中获取随机间隔,它具有固定的预定义持续时间 ${Interval0}),我将 BSF PreProcessor 与以下 java 脚本一起使用:
var startDate = new Date();
startDate.setDate(1);
startDate.setMonth(06);
startDate.setYear(2011);
var startDateTime = startDate.getTime();
var endDate = new Date();
endDate.setDate(31);
endDate.setMonth(07);
endDate.setYear(2012);
var endDateTime = endDate.getTime();
var randomSDate = new Date();
var randomSDateTime = startDateTime+Math.random()*((endDateTime -${Interval0}) -startDateTime );
randomSDate.setTime(randomSDateTime);
var randomEDate = new Date();
var randomEDateTime = (randomSDateTime + ${Interval0}); // adds interval to start date
randomEDate.setTime(randomEDateTime); // transforms to string format
var rndSDate = randomSDate.getDate();
var rndSMonth = randomSDate.getMonth()+1 ;
var rndSYear = randomSDate.getFullYear();
var rndEDate = randomEDate.getDate(); // disassembles the end date to year-month-day format
var rndEMonth = randomEDate.getMonth()+1 ;
var rndEYear = randomEDate.getFullYear();
if (rndSDate.toString().length == 1) // add 0 to the left of month and day if they have only 1 symbol
rndSDate = "0" + rndSDate;
if (rndSMonth.toString().length == 1)
rndSMonth = "0" + rndSMonth;
if (rndEDate.toString().length == 1) // add 0 to the left of month and day if they have only 1 symbol
rndEDate = "0" + rndEDate;
if (rndEMonth.toString().length == 1)
rndEMonth = "0" + rndEMonth;
var RandomStartDate = rndSYear + "-" + rndSMonth + "-" + rndSDate;
vars.put ("RandomStartDate", RandomStartDate);
var RandomEndDate = rndEYear + "-" + rndEMonth + "-" + rndEDate;
vars.put ("RandomEndDate", RandomEndDate);
现在我需要将此 JMeter 脚本转换为 LR 脚本。
您能否建议我,我应该如何开始实施这个想法?我需要知道的第一件事是 - 对于我的案例,LR 脚本的结构应该是什么?