cancel
Showing results for 
Search instead for 
Did you mean: 

Use Enum as a Parameter type in Keyword Tests

Use Enum as a Parameter type in Keyword Tests

Edit:  Added a specific Use Case for clarity

 

Like most users I use parameters for my KWTs.  Some parameters have a limited option pool e.g. paramater "WantACookie" can have 3 and only 3 values "Yes", "No" and "Not Sure"  This parameter is used to set the text of a combobox.  I could create it as a string that correlates with this and each other KWT or script that calls this KWT just needs to send the string.  Say, however the the marketing department decided that "Not Sure" is no longer broadcasting the right message and want to change it to "I'm Thinking About It"  All those other scripts and KWTs that used to set it to "Not Sure" will break.  Is it possible to create the parameter as a list of key->value pairs.  That way my other KWTs and scripts can say the vaule should be WantACookie.NotSure and all I have to do is go to my KWTs WantACookie paramter and change the value of the "NotSure" key to "I'm thinking About It"  You would probably have to define this KVP list in the parameter type itself I guess and when setting properties in the visual editor, this "Enum" should be available the same way Variables and Parameters are from a dropdown.

 

A specific Use Case:

 

The Enum is a way to define a limited amount of set options that you know won't change

Say I'm an e-commerce site.  I wan't to make sure users don't have a bad experience by accidentally buying something when they intended to just add it to the wish list.  Three tests:

 

1. Textbox1.Keys()->Textbox2.Keys(),texbox3.Keys,etc,-> buttonPlaceOrder.Click() -> Open Wishlist page -> Are ther items ? No -> Pass -> Open Basket -> Are there items? Yes ->Pass

 

2. Textbox1.Keys()->Textbox2.Keys(),texbox3.Keys,etc,-> buttonAddWishList.Click() -> Open Wishlist page -> Are ther items ? Yes -> Pass -> Open Basket -> Are there items? No ->Pass

 

3. Textbox1.Keys()->Textbox2.Keys(),texbox3.Keys,etc,-> buttonCance.Click()l -> Open Wishlist page -> Are ther items ? No -> Pass -> Open Basket -> Are there items? No ->Pass

 

All three tests have the data populate in common.  I don't really care what data is in there and I won't use it in a Data Loop so it can all be the same and be written into a single test so I don't have to duplicate all those .Keys() and .Clicks() into all my KWTs
So, create one KWT PopulateOrder that does the keypresses.

One step further I can see the only thing that distinguishes the process is what button gets clicked.  If I specify this as a parameter like PopulateOrder(OrderAction) I can change my tests to this by simply dragging the new KWT into my visualiser :

 

1. PopulateOrder(Order) -> Open Wishlist page -> Are ther items ? No -> Pass -> Open Basket -> Are there items? Yes ->Pass

 

2. PopulateOrder(WishList) -> Open Wishlist page -> Are ther items ? Yes -> Pass -> Open Basket -> Are there items? No ->Pass

 

3. PopulateOrder(Cancel)->Open Wishlist page -> Are ther items ? No -> Pass -> Open Basket -> Are there items? No ->Pass

 

The last steps in  my Populate order is an if statement: 

 

If(OrderAction equals "Order"){buttonPlaceOrder.Click()}

 

If(OrderAction equals "WishList"){buttonAddWishList.Click()}

 

If(OrderAction equals "Cancel"){buttonCancel.Click()}

 

If I drag the KWT into another KWT I can supply this parameter.  Problem is, if a user doesn't know the exact string required and they type in, say "PlaceOrder", the KWT will fail because none of the if statements match.  If on the other hand I can define the parameter as an enum that the user can choose from a dropdown I know the logic will always work e.g.

 

if(OrderAction equuals OrderActionEnum.Order) {buttonPlaceOrder.Click()}

 

It's something I would really have appreciated when I started using TC.   It would have helped standardise my tests by always having the option based parameters defined, thereby avoiding loads of rework due to early inexperience.
It still helps because I wouldn't have to open the PopulateOrder just to double check what string I need to send.

8 Comments
Community Hero

You could probably get the same behavior using a table variable and doing lookups on it. Not the best way, but would do as a workaround.

 

It would be much easier to write things like this in a code unit instead of a KWT though. 

Community Leader

You could probably get the same behavior using a table variable and doing lookups on it. Not the best way, but would do as a workaround.

 Agreed.  It does mean the user would have to create a data table for each of these "Enum" data objects.  It's a bit of a two ways to skin a cat scenario.  Not all users are comfortable with writing scripts.  Where I work, the product consultants write KWTs.  They wouldn't even be expected to do more than record an on-screen test.    They are the same users who won't be comfortable with using datatable objects as enums and doing lookups from them.  They are happy to create an onscreen action in the visual editor though.  The next level up is parameterising that recorded KWT  There are places where it is just more convenient to use the visual editor e.g.  Create a small, compact KWT with 3 parameters that does repeating tasks e.g. populate the same three comboboxes on a page but with different values.  A sub-function of a sort that I can drag into my current KWT or event run from a script.  This could be a created as a script, yes, but to call the script I still need to forward the parameter value to the script.  Now if that was just the value of an enum from the parameter supplied to the KWT that would be easier for non-power users and small little units.

Community Hero

Why does that parameter have any values other than "YES"?  

Community Leader

Why does that parameter have any values other than "YES"?


Personally I agree with you, but what if it's a site that keeps you motivated to stick to your diet.  Each time you select "No" it outputs a random motivational qoute and if you say "Yes" it sends you to that wonderful "Never gonna give you up" musical number on Youtube...

Community Hero

Diet or not, I still WANT the cookie.  The app is asking me to lie.  Bad UX.   Smiley Happy

Community Leader


Diet or not, I still WANT the cookie.

Send out the Persuadotron ! (a.k.a Steve from downstairs with the big biceps)

Community Hero

Steve can have a cookie too!

Community Leader

Sorted. 

WantACookie.JPG

 

I could still use an enum though