Archive for the ‘Scripting’ Category.

Removing Zero from the Date in VuGen LoadRunner

Challenge:



Enter start date and end date and date should not include zero before actual value of month and day.

E.g.

Invalid date format: 04/27/2011

Valid date format: 4/27/2011


Solution:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//variable declaration
char month[10], day[10], year[10], startDate[10], endDate[10];
int nonZeroDay, nonZeroMonth;

/*if you want to run script for multiple interactions then you have to nullify
the concatenated string before starting new iteration otherwise it
will keep the old value*/

strcpy(startDate, "");
strcpy(endDate, "");

//original date which contain zero in the date
lr_save_datetime("Today’s Date is: %m/%d/%Y", DATE_NOW, "normalDate");
lr_output_message(lr_eval_string("{normalDate}"));

//for generating non zero start date

//to assign the current date parts to a parameter
lr_save_datetime("%m", DATE_NOW, "month");
lr_save_datetime("%d", DATE_NOW, "day");
lr_save_datetime("%Y", DATE_NOW, "year");

//to remove zero from the string. e.g.getting '4' from '04'

nonZeroMonth = atoi(lr_eval_string("{month}"));
lr_save_int(nonZeroMonth, "month");

nonZeroDay = atoi(lr_eval_string("{day}"));
lr_save_int(nonZeroDay, "day");

//creating a date string using concatenation of nonzero date parts and separator '/'
strcat(startDate, lr_eval_string("{month}"));
strcat(startDate, "/");
strcat(startDate, lr_eval_string("{day}"));
strcat(startDate, "/");
strcat(startDate, lr_eval_string("{year}"));

lr_save_string(startDate, "p_StartDate");
lr_output_message("Start Date is: %s", lr_eval_string("{p_StartDate}"));

//for generating non zero end date by incrementing date by one day offset
lr_save_datetime("%m", DATE_NOW + ONE_DAY, "month");
lr_save_datetime("%d", DATE_NOW + ONE_DAY, "day");

lr_save_datetime("%Y", DATE_NOW + ONE_DAY, "year");
nonZeroMonth = atoi(lr_eval_string("{month}"));
lr_save_int(nonZeroMonth, "month");

nonZeroDay = atoi(lr_eval_string("{day}"));
lr_save_int(nonZeroDay, "day");

strcat(endDate, lr_eval_string("{month}"));
strcat(endDate, "/");
strcat(endDate, lr_eval_string("{day}"));
strcat(endDate, "/");
strcat(endDate, lr_eval_string("{year}"));

lr_save_string(endDate, "p_endDate");
lr_output_message("End Date is: %s", lr_eval_string("{p_endDate}"));



Output:



Today’s Date is: 04/27/2011
Start Date is: 4/27/2011
End Date is: 4/28/2011

RTE protocol script recording in VuGen LoadRunner

Terminal Emulation (RTE):



Emulation of users who submit input to, and receive output from, character-based applications. VuGen LoadRunner has its own internal terminal emulator using which it connects to the application.

RTE Vuser:

  • RTE Vuser operates terminal emulator in order to load test client/server base applications.
  • Terminal emulator session is a collection of a real user’s actions.
  • RTE Vuser types character input into a terminal emulator, submits the data to a server, and then waits for the server to respond.
  • LoadRunner uses PowerTerm as a terminal emulator for emulating RTE session.
  • PowerTerm works like a standard terminal emulator, supporting common protocols such as IBM 3270 & 5250, VT100 and VT220.
  • VuGen records the terminal setup and connection procedure into the script.

Procedure:

  1. Click on New Script.
  2. Select Single Protocol Script and in All Protocols category choose Terminal Emulation (RTE).



  3. Click on Create for creating script and then click on Start Recording.
  4. PowerTerm Emulator will show up.
  5. Click on Communication menu and then click on Connect.



  6. In Connect window choose Terminal type: 3270 Display
  7. It will automatically set the default settings like Session Type, Terminal ID, and Port Number according to your Terminal Type value.
  8. You can change them according to your need.
  9. Enter Host Name, which is given in Test Plan.
  10. Click on Connect, it will connect to the server then follow the business flow given in test plan.
  11. When you are done with your business flow then stop recording.
  12. Now you can enhance your recorded script with transactions and synchronization functions.

Challenge 1: Finding blank row on Terminal screen to add user inputs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
char text[100];

/* suppose top rows are reserved for function description and user can input data from 6<sup>th</sup> row onwards and total rows are 22 */

int row=6;

int flag=TRUE;

//Finding the blank row to add user inputs

while (flag){

//If it’s End of page then start from next page

if (row==22) {

TE_type("");

TE_wait_sync();

row=6;

}

TE_get_text_line(5,row,1, text);

if (strcmp(text,"_")==0){

flag=FALSE;

break;

}

row++;

}

TE_set_cursor_pos(2,row);


Challenge 2: Handling transaction status using Text Check on terminal screen


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
lr_start_transaction("T01_Modify_AccountDetails");

TE_type("{p_Amount}");

TE_wait_sync();

iReturn=TE_find_text ("RECORD(S) PROCESSED SUCCESSFULLY.", 1,22,40,22, &col, &row, match);

lr_output_message("value:%d", iReturn);

if (iReturn==0){

lr_end_transaction("T01_Modify_AccountDetails ",LR_PASS);

}else{

lr_end_transaction("T01_Modify_AccountDetails ",LR_FAIL);

}