Skip to main content

Posts

Showing posts from March, 2014

SAP GUI Text check (Error Handling)

SAP GUI Text check (Error Handling) sapgui_status_bar_get_text("paramStatusBarText",                    BEGIN_OPTIONAL,                              "Recorded status bar text: Material document 4900089763 posted",                              "AdditionalInfo=sapgui1067",                    END_OPTIONAL);           lr_end_transaction("S31_SAP_Fleet_MIGO_1090_ClkPost", LR_AUTO); i = sapgui_status_bar_get_param("1", "param1", LAST); lr_output_message("Material Document Number is: %s",lr_eval_string("{param1}")); if(i==1)            { lr_output_message("Material Document creation failed and input data used is : %s", lr_eval_string("{pUserName}"));       ...

Error handling using Text Check

When a script logs in, a request can return a successful HTTP status even though the login failed. The server might send back an error page that still says "200 OK". A text check solves this by looking for text that appears only when the step worked, such as "Home Page" after a successful login. Check the result with if/else web_reg_find searches the next response for your text and saves how many times it was found. Register it before the step it checks. web_reg_find("Text=Home Page", "SaveCount=home_count", LAST); lr_start_transaction("login"); web_submit_data("login", "Action=http://example.com/login", "Method=POST", ITEMDATA, "Name=username", "Value={pUserName}", ENDITEM, "Name=password", "Value={pPassword}", ENDITEM, LAST); if (atoi(lr_eval_string("{home_count}")) > 0) { lr_output_message("Logon succes...

Save a parameter in notepad file

Sometimes you need to keep a value that your script captured, such as an order ID or a session token, so you can look at it after the test. This code saves a captured value to a text file, one line per iteration. long fd; // Capture the value into the parameter "saveID". // LB and RB are the text just left and right of the value. web_reg_save_param("saveID", "LB=---", "RB=---", "ORD=1", LAST); web_url("Home", "URL=http://example.com/", LAST); fd = fopen("C:\\NotepadName.txt", "a"); // "a" adds to the end of the file if (fd == 0) { lr_error_message("Could not open the file"); return -1; } fprintf(fd, "%s\n", lr_eval_string("{saveID}")); // write the value, then a new line fclose(fd); // close the file What each part does web_reg_save_param captures a value from the next response. Set LB a...