Set a project wide variable

10 posts, 1 answers
  1. Nate
    Nate avatar
    32 posts
    Member since:
    Feb 2011

    Posted 07 Mar 2011 Link to this post

    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.
  2. Answer
    Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 07 Mar 2011 Link to this post

    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!
  3. Nate
    Nate avatar
    32 posts
    Member since:
    Feb 2011

    Posted 07 Mar 2011 Link to this post

    Thanks, I haven't tried this yet, but your explanation makes sense.
  4. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 07 Mar 2011 Link to this post

    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!
  5. Nate
    Nate avatar
    32 posts
    Member since:
    Feb 2011

    Posted 07 Mar 2011 Link to this post

    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?
  6. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 08 Mar 2011 Link to this post

    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!
  7. Nicklas
    Nicklas avatar
    1 posts
    Member since:
    Aug 2011

    Posted 28 Sep 2011 Link to this post

    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.

  8. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 29 Sep 2011 Link to this post

    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
  9. Vasu
    Vasu avatar
    5 posts
    Member since:
    Nov 2011

    Posted 26 Jan 2012 Link to this post

  10. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 26 Jan 2012 Link to this post

    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
Back to Top