Micro Focus QTP (UFT) Forums

Full Version: Alternative to Switch case- Multi Select with value match
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello All,

I have come across a typical issue for decreasing performance overhead and reduce size of code in Automation Scriting through QTP.

I have a variable which gets value dynamically (abbreviated form).
From pool of data i have to compare and match to which string this value of variable is related to.

Eg: In state variable, i get value VA. State = VA
Now VA Corresponds to Virgina (state in US)

[ I have Pool of data with values - Virgina, Washington, Albama, Masachuestts, Alaska, New York, North Carolina, South Carolina, FLorida and so on-51 states ]

Going by traditional way was to use SELECT CASE

Code:
Select Case a

    Case "VA" State= Virgina
    Else State = "Invalid State"
End Select

The problem here is i have 50 odd states and
12-15 fields like States to compare and match. So the switch case increase scripting and performance overhead.

It would be very helpful if i get some idea as to declare the match part in some data definition format and decrease time instead of using SWITCH case.

Please suggest. Thanks is Advance

Luv & Regards,
Aakansha
You can either use an Excel Sheet (I prefer this) or QTP's DataTable and store the value in a variable, and compare/match that value in column B and retrieve its corresponding value from column A and use that instead. This only requires a simple Loop.

Something in the lines of this:

Code:
Column A     Column B

Alabama        AL
Alaska         AK
...            ...
...            ...
Wyoming        WY

So, all you have to do is match the value that you retrieve from the form, compare it with the value in Column B, and retrieve the value from its corresponding row in Column A.
Hi Anshoo,

Thanks for valueable suggestion. The solution seems to be prefect.

The problem with my case is that like the State field ,
i have atleast 12-15 fields to be compared. So i think, creating excels and importing it for all case would increase time and performance overload.
Also there are almost 100odd test case to be tested and for each of this case importing and searching from excel would futher incerease complexity of the Issue.

Please suggest if i am right/ wrong.
Also please suggest if any alternative if possible.
Thanks in Advance.

Luv & Regards,
Aakansha.
Aakansha,

The only piece of code that you need to write is to retrieve data from an Excel Sheet. I recommend this method because regardless of what changes that your application encounters, all you will have to do is modify the Excel Sheet, without having the need to even touch any of your functions. This is the same for the case where you have to omit some values or add some.

To start, you will need to just load the Excel sheet with the required data that needs to be read and compared with. To make it easier, you can give each column heading a name (@ Row = 1). For example, in your State case:

Column 1: StateLong
Column 2: StateShort

In your comparison, you will read from the 'StateShort' column and compare the value in the corresponding row from Column 1. Everytime you need to do this comparison, you will call the same function, making it easier for you to read when you encounter an error and also easier for you to modify the function/Excel sheet.

This is going to work like a charm regardless of the number of test cases in your test suite. In my Framework, I have used a similar approach to check application values from Checkpoint columns and I can run a single test for different values by just modifying my Excel Sheet.
Hi Anshoo,

Thanks for the solution. Its seems to be perfect. It would more help if you could please provide some sample code, to have a insight of the solution you provided. I implemented the solution and its working very fast. Please if you could assist me with some sample code, i could fine tune it for my case.

Thanks a Lot.

Luv & Regards,
Aakansha.
Sample code for?
As you said : " I have used a similar approach to check application values from Checkpoint columns".
I would be very grateful ,if possible you could suggest it via Sample code implementing the excel logic, for better understanding the process.
Could you message me your email address?
I have sent you an email. You can edit your previous post and remove you email if you want. Thanks.
Dear Anshoo Arora,
if you share your code with evreyone it is going to be very helpful instead of sending email.
Pages: 1 2