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 successful");
lr_end_transaction("login", LR_PASS);
} else {
lr_error_message("Logon failed for user %s", lr_eval_string("{pUserName}"));
lr_end_transaction("login", LR_FAIL);
lr_exit(LR_EXIT_ACTION_AND_CONTINUE, LR_FAIL);
}
Replace the URL, the field names and the parameters ({pUserName}, {pPassword}) with the ones in your own script.
How it works
web_reg_findlooks for "Home Page" in the response and stores the number of matches inhome_count.lr_eval_stringreads the saved value as text, andatoiconverts it to a number.- If the count is above zero, the login worked. If not, the script logs an error, marks the transaction as failed, and
lr_exitstops the current iteration so it doesn't carry on with a broken session.
A shorter option
If you only need the step to fail when the text is missing, you can skip the if/else and let LoadRunner do the check:
web_reg_find("Text=Home Page",
"Fail=NotFound",
LAST);
Use the longer version when you want a custom message, extra logging or a specific exit action.
Tips
- Choose text that appears only on success. A word that is also on the login page, like "Login", can give false passes.
- Use a short text that doesn't change, and avoid dates or names that differ for each user.
- Failed checks appear in the Vuser log, so you can see which user and iteration failed.
Can we use some kinds of extension that could tell us about errors before the execution of programming code? I would be grateful if you could tell me about this because I don't wanna see any error in my code. TheAcademicPapers.co.uk
ReplyDeleteHere are some steps to troubleshoot high memory utilization: Monitor Memory Usage: Use performance monitoring tools to track memory usage over time. Monitor both😊To excel in the pharmaceutical representative job search, start by obtaining a relevant degree and networking within the industry. Customize your resume and cover letter, highlighting your product knowledge and communication skills. Research companies thoroughly and consider informational interviews. Stay persistent and informed about industry trends to enhance your chances of securing a position.softpost
ReplyDelete