This is a migrated thread and some comments may be shown as answers.

What is the Proper Way to Store Variables Across Tests/Sub-Tests?

1 Answer 179 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 27 Sep 2017, 05:48 PM

I have encountered several methods of storing variables that can be accessed across tests, and I am wondering what the recommended scenario is. My goal is to be able to run a master test with several sub-tests (and some with sub-tests themselves), but to have each primary sub-test store variables based on input, and then to react to those variables by skipping unnecessary tests or adding/subtracting/modifying values to fit certain constraints. Basically, I need to set and get variables across multiple tests in a longer process.

Here is what I know currently, but correct me if I'm wrong:

1. Extracted Values

Using SetExtractedValue(string dataBindVariableName, object value) I can create variables that are accessible across tests. This allows me to access the values via GetExtractedValue(string dataBindVariableName). The challenge is that these get/set methods automatically fail the test whenever the variable is not present (e.g., I used a "get" in a scenario where the variable has not been "set"), so I have to nest all of them in Try/Catch blocks. If I want to conditionally check to see if these values exist, I have to put each one in its own Try/Catch block so I can respond to each variable independently. While possible and functional, this gets tedious and very cluttered in code, so I have looked at 2 other options:

2. DataBound Variables

Using Data["variableName"] I know I can access the values stored in local or external data sources, based on the column name. My confusion is how this interacts with extracted values, as sometimes I seem to be able to switch back and forth between Data[""] and GetExtractedValue(""), but sometimes I can't. Also, the same rigid constraints exist on data bindings as with extracted values, meaning that I have toput them in try/catch blocks if I want to conditionally test for whether the variable is present yet or not.

3. Utility Classes

This might be the easiest option, and the limitation might be my programming knowledge here. I found documentation talking about creating a utility class in Test Studio standalone. It's a static class with static variables, which works great for some of the stock browser interactions I want to do in dozens of places throughout my test suite. The challenge is that I have to add in references to the Browser (for ActiveBrowser.Refresh/ActiveBrowser.RefreshDomTree), the Log (for Log.WriteLine), and the Manager (for Manager.Desktop). However, since a static class is not instantiated, my only option is to pass in all of these values every time I run a function. Not the end of the world, I suppose. I am currently using a standalone non-static class file (extending BaseWebAiiTest) to work around this, but I don't know of an easy way to pass this between tests and sub-tests. Is there one?

 

I imagine you will want code samples, and I can provide them, but I'm mostly looking for a general principle. My question is about the expected way these features function in general, and which one fits my need to pass variables and functions between tests.

 

Thanks ahead of time!

 

Regards,

Steven Klassen

1 Answer, 1 is accepted

Sort by
0
Elena
Telerik team
answered on 02 Oct 2017, 02:09 PM
Hi Steve,

Thanks for your detailed explanation of all you have tried and found. 

Though there are few things more I would like to know about your expectations of the test execution.

I understand there are plenty of dynamic extractions within your tests to use different values in run-time. It is important to set the tests and extractions in a way to ensure each extracted variable has value before it is called in the test. 

Otherwise it is expected that a test could fail if there is no value to pass to the certain action and if you would need to double check whether this is assigned or not the try..catch would be the option as you have suggested. 

In regards to the difficulties you are facing in switching between Data[""] and GetExtractedValue("") I would need some further details so that I could advise further. 

About using the standalone non-static class that extends the BaseWebAiiTest you could list this in the coded step after the class as well as in the project settings (please refer to the screenshot). 

It would be good to provide further examples if you would need additional assistance as this would be the best way to understand your requirements and difficulties you are facing. 

Thank you for your assistance in advance! 

Regards,
Elena Tsvetkova
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Steve
Top achievements
Rank 1
Answers by
Elena
Telerik team
Share this question
or