Micro Focus QTP (UFT) Forums
Alternative to Switch case- Multi Select with value match - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Alternative to Switch case- Multi Select with value match (/Thread-Alternative-to-Switch-case-Multi-Select-with-value-match)

Pages: 1 2


Alternative to Switch case- Multi Select with value match - Aakansha_d - 06-04-2008

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


RE: Alternative to Switch case- Multi Select with value match - Anshoo Arora - 06-05-2008

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.


RE: Alternative to Switch case- Multi Select with value match - Aakansha_d - 06-05-2008

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.


RE: Alternative to Switch case- Multi Select with value match - Anshoo Arora - 06-05-2008

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.


RE: Alternative to Switch case- Multi Select with value match - Aakansha_d - 06-06-2008

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.


RE: Alternative to Switch case- Multi Select with value match - Anshoo Arora - 06-07-2008

Sample code for?


RE: Alternative to Switch case- Multi Select with value match - Aakansha_d - 06-09-2008

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.


RE: Alternative to Switch case- Multi Select with value match - Anshoo Arora - 06-09-2008

Could you message me your email address?


RE: Alternative to Switch case- Multi Select with value match - Anshoo Arora - 06-09-2008

I have sent you an email. You can edit your previous post and remove you email if you want. Thanks.


RE: Alternative to Switch case- Multi Select with value match - somisays - 06-09-2008

Dear Anshoo Arora,
if you share your code with evreyone it is going to be very helpful instead of sending email.