如何将Web服务的JMeter脚本转换为此Web服务的LoadRunner脚本?

时间:2013-09-03 11:25:34

标签: web-services jmeter loadrunner

我有JMeter脚本,它向Web服务发送3种类型的XML请求。

例如,对于第二种类型 - 我发送的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脚本的结构应该是什么?

1 个答案:

答案 0 :(得分:2)

请参阅web_custom_request()和web_add_header(),了解将请求推送到具有HTTP虚拟用户类型的服务器的机制。其余的与您对C编程语言的了解直接相关,与LoadRunner无关。