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

Set a project wide variable

9 Answers 199 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nate
Top achievements
Rank 1
Nate asked on 07 Mar 2011, 04:58 PM
Hello,
         Is there a way a I can set a project wide variable that I can access from all the tests in the project? I would like to be able to use the same string throughout all of the tests in the project.

9 Answers, 1 is accepted

Sort by
0
Accepted
Stoich
Telerik team
answered on 07 Mar 2011, 05:24 PM
Hi Nate,
      open the code behind for New Test. Create a public static String variable inside the class but not inside a method (screenshot 1). Notice in the screenshot that the class name is New_Test.
public static String myVariable= new String();
 
Now you can access this varible from all other tests in this project like this:
New_Test.myVariable
See screenshot 2. Keep in mind that since it's a static variable, all tests will be working with the same instance. Any  changes you make to the variable will be "visible" from all the tests. 

Let me know if you're having any trouble getting this to work!

All the best,
Stoich
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Nate
Top achievements
Rank 1
answered on 07 Mar 2011, 05:27 PM
Thanks, I haven't tried this yet, but your explanation makes sense.
0
Stoich
Telerik team
answered on 07 Mar 2011, 05:39 PM
One more thing to keep in mind: In QA edition a code-behind file is compiled to latest changes when you run the test. If you change anything in any code-behind file it will only become visible to other tests once you run it. You don't actually need to wait for it to finish - just start it and immediately abort it. It will still have compiled.

Kind regards,
Stoich
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Nate
Top achievements
Rank 1
answered on 07 Mar 2011, 05:42 PM
That's a good tip, thanks for the info. If I remember correctly, you guys plan on increasing the frequency of compiler runs in the next release, correct?
0
Stoich
Telerik team
answered on 08 Mar 2011, 02:21 PM
Hi Nate,
    yes, changes in the way QA edition compiles tests will be implemented. However, I'm not 100% sure when that will happen.

Best wishes,
Stoich
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Nicklas
Top achievements
Rank 1
answered on 28 Sep 2011, 10:38 AM

What if I want to the global variable to get its value from a data source? I tried this:

public static String myVariable = (string)Data["Email"];

but it didn't work for me. I get this error msg: "...An object reference is required for the non-static field, method, or property...". I'm not a coder so don't really know what it means and how to resolve.

0
Stoich
Telerik team
answered on 29 Sep 2011, 03:23 PM
Hi Nicklas,
       you'll need to move the right side of that operation inside a function. Leave this in the class definition:
public static String myVariable = "some default value";
Then reset the value inside a function in the same test like this:
myVariable  = (string)Data["Email"];
Obviously the test will have to be databound.
The function can be a regular coded step or possible or possible the initializing function:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/knowledge-base/test-execution/execute-custom-scripts-before-after-test.aspx 

All the best,
Stoich
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vasu
Top achievements
Rank 1
answered on 26 Jan 2012, 03:27 PM
0
Anthony
Telerik team
answered on 26 Jan 2012, 04:10 PM
Hello Vasu,

Here is the new link for that article.

Regards,
Anthony
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Nate
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Nate
Top achievements
Rank 1
Nicklas
Top achievements
Rank 1
Vasu
Top achievements
Rank 1
Anthony
Telerik team
Share this question
or