Question

I have the JMeter script, which sends 3 types of XML-requests to web-service.

For example, for the 2nd type - SOAPMethod 'getHeadlines' I send this XML-request:

<?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>

and I use

BeanShell preprocessor 2.1 - for getting random {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'

and analogically I use

BeanShell preprocessor 2.2 - for getting random {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'

The constant ${maxCount}` is predifined in User Defined Variables section of JMeter.

For getting variables as ${RandomStartDate} and ${RandomEndDate} (I need to get random interval from [06-01-2011; 07-31-2012], which has fixed predefined duration ${Interval0}) I use BSF PreProcessor with the following java-script:

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);

Now I need to convert this JMeter script to LR script.

Could you please advice me, how should I begin the implementation of this idea? The first thing I need to know is - what should be the structure of LR script for my case?

Was it helpful?

Solution

see web_custom_request() and web_add_header() for the mechanics of pushing the request to the server with the HTTP virtual user type. The rest is directly related to your knowledge of the C programming language, independent of LoadRunner.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top