Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alternative to Switch case- Multi Select with value match
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
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
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
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.
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
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.
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
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.
Reply
#5
Solved: 11 Years, 4 Months, 3 Weeks ago
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.
Reply
#6
Solved: 11 Years, 4 Months, 3 Weeks ago
Sample code for?
Reply
#7
Solved: 11 Years, 4 Months, 3 Weeks ago
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.
Reply
#8
Solved: 11 Years, 4 Months, 3 Weeks ago
Could you message me your email address?
Reply
#9
Solved: 11 Years, 4 Months, 3 Weeks ago
I have sent you an email. You can edit your previous post and remove you email if you want. Thanks.
Reply
#10
Solved: 11 Years, 4 Months, 3 Weeks ago
Dear Anshoo Arora,
if you share your code with evreyone it is going to be very helpful instead of sending email.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question what is the shortcut key used to switch between keyword view and expert view in qtp. shaileshanand86 5 11,768 02-13-2019, 03:58 AM
Last Post: zia003
  type mis match vishnu 2 4,413 01-14-2012, 12:12 PM
Last Post: vishnu
Rolleyes How to select multiple choices from Multi-Select weblist blavanya 3 9,938 01-03-2012, 05:55 PM
Last Post: shivu.hanu
  Not Invoked particular Test Case kotaramamohana 6 4,351 12-30-2011, 05:39 PM
Last Post: ravi.gajul
  FOR loop with nested CASE wheelercha 2 3,541 12-12-2009, 10:45 PM
Last Post: upadhyay40

Forum Jump:


Users browsing this thread: 4 Guest(s)