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

Create a variable to be used across tests

9 Answers 762 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 29 Mar 2013, 06:16 PM
Hello Everyone, this is my first post so be gentle.

I'm trying to automate a set of pages where a user that is already in the system can create requests to add other users.  Another user would then approve the request and create a username for that user.  There is some data that needs to be shared between those accounts (The tracking number request).  I was wondering if there was a way to store and edit this data during automated test execution where I can, perhaps, edit this variable from a scripted step or something of that nature; where in one test I could set the variable in one of my scripted steps and then in another test I could access that variable so that I can populate a field with that data.

Thanks for any help that can be provided.

9 Answers, 1 is accepted

Sort by
0
Accepted
Byron
Telerik team
answered on 01 Apr 2013, 09:14 PM
Hello David,

Welcome to the Test Studio forums. Using the Extraction and Test as Step features, you can pass a variable between tests. After extracting the variable and before passing it to another test, you can use a coded step to modify the variable. This example converts an extracted variable to all caps:

string myData = GetExtractedValue("varname").ToString();
myData = myData.ToUpperInvariant();
SetExtractedValue("varname", myData);

Greetings,
Byron
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Accepted
Himanshu
Top achievements
Rank 2
answered on 02 Apr 2013, 09:24 AM
Hi David

Just to add to Byron, using extracted value is the best option as it is very well integrated with Test Studio and eases re usability in other steps. Still, other things that can be done are:
1) To declare a variable in the project namespace outside the class for the current test and that can be used throughout project.
public class variable
    {
        public static int a;
    }
 use it as "variable.a" wherever you want it in any test in the same project but make sure that the test setting the value runs before the test using its value.

2) Also, you can use simple readstream and writestream to write the value to a txt file and use it from there. or wite the value to excel and fetch it back using interops. This way the value could be retained even after the test has closed( That was a specific requirement in our case).

Hope It Helps
0
David
Top achievements
Rank 1
answered on 02 Apr 2013, 01:37 PM
Thank you very much for the quick response.

Both answers are very helpful.
0
Vlas
Top achievements
Rank 1
answered on 14 Aug 2014, 08:58 AM
Hi,
we have the next scenario, which might also require a use of variables:

We want to be able to run a test list aginst multiple URLs without having to manualy change the Base URL in test list settings.

I was able to do that with a single test scenario by binding a .csv file with needed URLs to a Navigate step. So, no problem with that.

But what about the whole test list with a number of test scenarios - is it possible to automate a change of Base URLs in it? Maybe using variables?

Thanks in advance for any input.
0
Cody
Telerik team
answered on 15 Aug 2014, 04:17 AM
Hello Vlas,

If you don't mind running your test list from the command line, there you can specify an XML file containing specific settings for this run, which includes the BaseUrl setting.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
jippy
Top achievements
Rank 1
answered on 19 Aug 2015, 05:44 AM

Hello Himanshu, in context to your post which says

>>public class variable
{
public static int a;
}
use it as "variable.a" wherever you want it in any test in the same project but make sure that the test setting the value runs before the test using its value..<<

 

I have a Query please. Can we assign a value to this variable a which can be used by all other telerik tests just by referring as : "variable.a";

 

0
Boyan Boev
Telerik team
answered on 21 Aug 2015, 02:33 PM
Hello Jippy,

Please check out the utility class article.

It will contain global variables or functions in Test Studio Standalone version that are accessible from all the tests within the test project. 

Let me know if this is what you want to achieve.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
jippy
Top achievements
Rank 1
answered on 24 Aug 2015, 04:10 AM

Hi Boyan,

I already had a look at this Utility class.

However I was facing challenges picking up the value of global variable from excel(data driven approach) to be assigned in utility class and the same can be used in other scripts just by referring to the class.variable name.

 

I am just pasting some part of the class here :

namespace Web_Version_Testing
{
public static class DBConnectionString
{
public static void InitializeConnectionString()
{
string s = Data["server"].ToString();
string d = Data["db"].ToString();}
public string dbconnectionstring = "data source=" + s + ";database=" + d + ";uid=SYSADM;pwd=SYSADM;Persist Security Info=true;";

}}}

 

I am picking the server and db name fron excel which is binded to this test and then creating the db connection string which I want to use/refer in other tests.

Is this the right way to pursue?

 

Jippy

0
Boyan Boev
Telerik team
answered on 27 Aug 2015, 06:39 AM
Hello Jippy,

Unfortunately you cannot use Data method in the utility class since it doesn't extend BaseWebAiiTest class.

However you can read the Excel file entirely in code in the utility class and create public static variables.

Let me know if that approach works for you.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Byron
Telerik team
Himanshu
Top achievements
Rank 2
David
Top achievements
Rank 1
Vlas
Top achievements
Rank 1
Cody
Telerik team
jippy
Top achievements
Rank 1
Boyan Boev
Telerik team
Share this question
or