Skip to main content

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

  1. web_reg_find looks for "Home Page" in the response and stores the number of matches in home_count.
  2. lr_eval_string reads the saved value as text, and atoi converts it to a number.
  3. If the count is above zero, the login worked. If not, the script logs an error, marks the transaction as failed, and lr_exit stops 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.

Comments

  1. 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

    ReplyDelete
  2. Here 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

Post a Comment

Popular Posts

Pacing Time in LoadRunner

What is Pacing? Where and why to use it? -Pacing is the time which will hold/pause the script before it goes to next iteration. i.e Once the   Action   iteration is completed the script will wait for the specific time(pacing time) before it starts the next one. It works between two actions. eg, if we record a script there will be three default actions generated by the Load Runner:   vuser_init, Action   and   vuser_end,   the pacing will work after the   Action   block and hold the script before it goes to repeat it. The default blocks generated by LoadRunner is shown below: Actions marked in Red Now we know what is pacing and we use it between two iteration. The next question comes to mind is why we use pacing: Pacing is used to: To control the number of TPS generated by an user. To control number of hits on a application under test.     Types of Pacing: There are three options to control the pac...

What is Performance Testing and why it is important?

We spend most of our time by browsing Facebook, watching videos, uploading photos and many other online activities. Have you ever noticed if you are watching a video and all of sudden the website goes down? If you are trying to book an online ticket and on the payment page, the website stops responding? If you are adding the last available item on sale in the shopping cart and the website gets hung? Isn't it stressful? For every growing business, it's very crucial to keep a tap on the performance of their application. If a website takes more than 2 seconds to respond then users tend to move to some other website which can cause a huge business loss.  Let's say you are on a retail website and browsing for some item that takes around 2-3 seconds to respond to each click or loading the page. In most cases, the user will go for some other website. Performance Testing gives an idea about how the system is going to behave on load and can help the business owners to ...

What is Pacing and how it's different from the Think Time

What is pacing? Pacing is the wait between two iterations of a script. Once an iteration finishes, the script pauses for a set amount of time (the pacing time) before it starts the next one. When you record a script, LoadRunner generates three default blocks: vuser_init , Action and vuser_end . Pacing takes effect after the Action block, holding the script back before it repeats. The default blocks LoadRunner generates are shown below. Actions marked in red What is think time? Think time copies real user behavior by adding a delay between two actions or transactions, like the pause a person takes before clicking the next link. Can think time replace pacing? In an interview, I was once asked: if you add think time at the end of a script, won't it work as pacing too? If so, why did HP provide two separate settings for the same job? They are not the same, because each has a different purpose. With think time, the thread stays active and LoadRunner waits for the ...