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
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);
Byron
the Telerik team
Test Studio Trainings
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
Both answers are very helpful.
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.
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
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";
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
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
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