0

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?

Nadezhda T
  • 262
  • 8
  • 24

1 Answers1

2

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.

James Pulley
  • 5,606
  • 1
  • 14
  • 14
  • **@James Pulley**, yes, I know these functions of LR. My difficulty is that I haven't experience with programming on C and any experience in creating algorithms and code structure for programming on C. Could you please advice me any sources for novices with short examples on C, how this or similar type of tasks is solved, if it is possibly? May be, are there any video lessons about solving similar tasks? And the 2nd question is - can I use the java-script code, which I already have? What is the way to embed it in code for LR? – Nadezhda T Sep 04 '13 at 08:27
  • I don't want to sound like an ass but i think it is time the company hired a professional with Loadrunner experience. You have to do more than just convert the scripts, if that was the only thing required you could reach out to a in-house developer with experience in C to guide you but you have to know how the different settings work in loadrunner to have a successful and meaningful test run using loadrunner. If you just want to know how to send an xml using loadrunner check out this [blog](http://abhishekasthana.com/lr-web-service/) – Abhishek Asthana Sep 05 '13 at 12:56
  • Knowledge and acumen in the language of your performance testing tool is a foundation skill for the performance tester, independent of tool. You will need to partner up with two people two be successful at this point, (1) Someone who is very conversant with C, time structures and strings and (2) Someone who is very well seasoned in the LoadRunner space. You will find that some of the items you are doing in code can be handled in more efficient ways with LR than just a straight 1:1 translation of your prior effort – James Pulley Sep 05 '13 at 14:50