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

Loading Global variables from a data source

8 Answers 161 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Asare
Top achievements
Rank 1
Asare asked on 03 Oct 2012, 12:07 PM
I have a created a static class MyGlobalVariables in my Test Studio project to hold 10 global variables.
I have then created a Web Test MyTenTests which is made of 10 Test as Step scripts.
I have bound a datasource (an XML file) with Global Values to MyTenTests test
I want to extract the Global values and store them in MyGlobalVariables.variable1, MyGlobalVariables.variable2, .. MyGlobalVariables.variable10 for use in the whole project.

The idea is to set the values in the XML file once per project and make the values available throughout the project.

Ideally this would be done for a  Project or TestList but that is not currently an option so I am using Test as Step as a workaround.

Note the class is within the namespace not the individual tests.
Declaration

    public static class MyGlobalVariables
    {      
  // Set project specific global variables

  public static string MYURL= (string) Data["MYURL"];
        public static string MYToolsReminders= (string)Data["MYToolsReminders"];
  public static string MYCountVisitorsToURL= (string)Data["MYCountVisitorsToURL"];
    } 


Usage
The error mesaage is : The name 'Data' does not exist in the current context

8 Answers, 1 is accepted

Sort by
0
Asare
Top achievements
Rank 1
answered on 05 Oct 2012, 10:33 AM
Step 1

Add a static class in the name space

    public static class HLGlobalVar
    {      
            HLGlobalVar.HLURL=(string)Data["HLURL"];
            HLGlobalVar.HLHomeID=(string)Data["HLHomeID"];
            HLGlobalVar.HLOwnerId=(string)Data["HLOwnerId"];        
            HLAdvertiserId=(string)Data["HHLAdvertiserId"];
            
            HLGlobalVar.HLCheckCountURL=(string)Data["HLCheckCountURL"];
            HLGlobalVar.HLToolsReminders=(string)Data["HLToolsReminders"];
            HLGlobalVar.HLAgentHomesConversion=(string)Data["HLAgentHomesConversion"];
            HLGlobalVar.HLRemoteServiceURL=(string)Data["HLRemoteServiceURL"];

            HLGlobalVar.HLWebService=(string)Data["HLWebService"];    
            HLGlobalVar.HLRAUS=(string)Data["HLRAUS"];
            HLGlobalVar.HLRTUS=HLWebService + @"/service_rates.asmx";
    
            // Database
            HLGlobalVar.HLDBDataSource= (string)Data["HLDBDataSource"];
            HLGlobalVar.HLDBUsername= (string)Data["HLDBUsername"];
            HLGlobalVar.HLDBPassword= (string)Data["HLDBPassword"];
            HLGlobalVar.HLDBDatabase= (string)Data["HLDBDatabase"];
    
            // Check Count login creddentials
            HLGlobalVar.HLCheckCountUsername= (string)Data["HLCheckCountUsername"];
            HLGlobalVar.HLCheckCountPassword= (string)Data["HLCheckCountPassword"];
    
    }
Step 2

I have created an empty web test and added an XML data file and Bound the data file to the test.

I then added an OnBeforeTestStarted method as below

        public override void OnBeforeTestStarted()
        {
            HLGlobalVar.HLURL=(string)Data["HLURL"];
            HLGlobalVar.HLHomeID=(string)Data["HLHomeID"];
            HLGlobalVar.HLOwnerId=(string)Data["HLOwnerId"];        
            HLAdvertiserId=(string)Data["HHLAdvertiserId"];
            
            HLGlobalVar.HLCheckCountURL=(string)Data["HLCheckCountURL"];
            HLGlobalVar.HLToolsReminders=(string)Data["HLToolsReminders"];
            HLGlobalVar.HLAgentHomesConversion=(string)Data["HLAgentHomesConversion"];
            HLGlobalVar.HLRemoteServiceURL=(string)Data["HLRemoteServiceURL"];

            HLGlobalVar.HLWebService=(string)Data["HLWebService"];    
            HLGlobalVar.HLRAUS=(string)Data["HLRAUS"];
            HLGlobalVar.HLRTUS=HLWebService + @"/service_rates.asmx";
    
            // Database
            HLGlobalVar.HLDBDataSource= (string)Data["HLDBDataSource"];
            HLGlobalVar.HLDBUsername= (string)Data["HLDBUsername"];
            HLGlobalVar.HLDBPassword= (string)Data["HLDBPassword"];
            HLGlobalVar.HLDBDatabase= (string)Data["HLDBDatabase"];
    
            // Check Count login creddentials
            HLGlobalVar.HLCheckCountUsername= (string)Data["HLCheckCountUsername"];
            HLGlobalVar.HLCheckCountPassword= (string)Data["HLCheckCountPassword"];

        }

Step 3

I should be able to reference my global variables from the tests. Unfortunately, every reference to the Global Var

Yippee It is working!!
0
Accepted
Ivaylo
Telerik team
answered on 08 Oct 2012, 08:47 AM
Hello Asare,

It seems you have found the method OnBeforeTestStarted(). Is your issue solved now, do you have a running test? I am making that conclusion by your statement at the end of your second post:

 "Yippee It is working!!"

Please let me know if you need any additional assistance.

Regards,
Ivaylo
the Telerik team
Are you enjoying Test Studio? We’d appreciate your vote in the ATI automation awards.
Vote now
0
Asare
Top achievements
Rank 1
answered on 08 Oct 2012, 04:14 PM

Hi Ivaylo,

My work-a-round is working but it is a bit painful especially it is to be maintained by non-developers.

I think it would be a very useful feature request.

FEATURE REQUEST
1. The ability to attach a data source to a project and thus making it available to every test within the project.
2. It would remove the need for creating global variables in code.

3. Ensure running multiple test lists would not be an issue (would not cause conflict about which test or coded step holds the Global variables).


Regards,

Asare

0
Ivaylo
Telerik team
answered on 11 Oct 2012, 11:52 AM
Hello Asare,

Yes you can attach a data source to a project and make it available for every test within the project but you will need to data bind each test to the data source. Please check this article for more information.

All the best,
Ivaylo
the Telerik team
Are you enjoying Test Studio? We’d appreciate your vote in the ATI automation awards. 
Vote now
0
Asare
Top achievements
Rank 1
answered on 11 Oct 2012, 02:35 PM
Sorry, I think you misunderstood me.

I want to set values at the beginning of a project and then use them throughout all the tests.

0
Ivaylo
Telerik team
answered on 16 Oct 2012, 10:44 AM
Hello Asare,

Please excuse me for the misunderstanding.
Actually I missed to share that  instead of overriding you can build your own custom DLL containing the method OnBeforeTestStarted() that can be shared by multiple projects/tests. Here is an article I found on how to create your custom DLL. You can include all the methods you would like to share in this custom DLL and just add it as assembly to the project in which you would like it to be used. 
Here is our article on how to add an assembly reference.

Greetings,
Ivaylo
the Telerik team
Are you enjoying Test Studio? We’d appreciate your vote in the ATI automation awards.
Vote now
0
Gopal
Top achievements
Rank 1
answered on 12 Mar 2014, 01:40 PM
Hi Asare, 
It was a helpful post and I was able to load global varibales, using the public static class.

Now, my question is, When I update any of these variables in test1, it is not used as updated value when running test2. ( Running Quick Execution, Every time the runtime loads the class with default values).

Is there any work around for this purpose? 
0
Velin Koychev
Telerik team
answered on 17 Mar 2014, 12:45 PM
Hello Asare,

This is actually an expected behavior. Once the Quick Execution or test list execution is over, the next time you run the test (or the test list), it will use again the default settings that are stored in the dll file. 

However, there is an easy workaround. You just need to use test list and make sure that test1 will be executed before test2. 

Looking forward to hearing from you.
 
Regards,
Velin Koychev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Asare
Top achievements
Rank 1
Answers by
Asare
Top achievements
Rank 1
Ivaylo
Telerik team
Gopal
Top achievements
Rank 1
Velin Koychev
Telerik team
Share this question
or