Run a test with or without extracted step

5 posts, 1 answers
  1. Mariko
    Mariko avatar
    39 posts
    Member since:
    Jun 2011

    Posted 14 Dec 2011 Link to this post

    Hi Telerik,

    I want to create a stand alone test that can be included to the other tests so that it can use the ExtractedValue or execute itself without the extractedvalue step
    So i wrote this code
    if(Data["Name"].ToString() == "")
    {
        Item0Caret0.SetText(true, "Hello", 1, 10, false);
    }
    else
    {
        Item0Caret0.SetText(true, Data["Name"].ToString(), 1, 10, false);
    }

    Then i got this error
    InnerException:
    System.ArgumentException: The extracted variable 'Name' does not exist in the store. Make sure there is an extract step that has executed before executing this step.
       at ArtOfTest.Common.Design.Extensibility.ExtractionDataStore.GetValue(String name)
       at ArtOfTest.WebAii.Design.BaseWebAiiTest.TestData.get_Item(String column)

    I thought of adding a step to the other test so that the extracted variable can exist. But it may overwrite the real extracted variable when executed.

    Also i would like to ask if this is possible:
    I have a TestList that contains Test A and Test B
    Test A contains a extracted variable TestVar
    Is it possible that Test B can use the extracted variable TestVar? Without setting Test B as a Test step in Test A?

    Thanks
  2. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 15 Dec 2011 Link to this post

    Hello Mariko,
    when a certain value doesn't exist in the datasource it will return null and NOT an empty string as your code assumes. So just rework the code like so:
    if(Data["Name"] == null)
    {
        Item0Caret0.SetText(true, "Hello", 1, 10, false);
    }
    else
    {
        Item0Caret0.SetText(true, Data["Name"].ToString(), 1, 10, false);
    }

    Please note you'll need to set the test to inherit its parent's datasource.

    On your second question: yes this is possible but a bit a bit tricky. You have to store the extracted variable into a Utility class. Check out the following article which explains how to create a Utility class in Standalone:
    http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/utility-in-standalone.aspx 

    So if your Utility class looks like this:
    public static class Utility
         public  static String valueHolder;
         public static void writeToFile(String path,String content)
              {
              // Write the string to a file.
              System.IO.StreamWriter file = new System.IO.StreamWriter(path);
              file.WriteLine(content);
              file.Close();
              }
    }

    Here's the code that's going to store the Extracted variable in this class:
    Utility.valueHolder = this.GetExtractedValue("myExtractedVariable").ToString();

    And you can subsequently access it from other tests like so:
    Log.WriteLine("Value from Utility class:" + Utility.valueHolder.ToString()); //Write value to test Log

    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
  3. Mariko
    Mariko avatar
    39 posts
    Member since:
    Jun 2011

    Posted 16 Dec 2011 Link to this post

    Hi Stoich,

    The test still fails. Inherit parent datasource is already true and I've changed the code to 'null'.

    Thanks.
  4. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 16 Dec 2011 Link to this post

    Hello Mariko,
    send me the test so that I can examine it. Also please provide some additional details on error you're getting when it fails. If you don't want to share this data on a public forum, please go ahead and open a support ticket and attach it there. As a paying customer you have access to our support system.

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

    Posted 20 Dec 2011 Link to this post

    Hello Mariko,
    I apologize - I seem to have mislead you with the code sample I sent you initially. When you try to access a non-existent column in the datasource through code - an exception is throw. When an unhandled exception is thrown within a coded step, the step fails immediately.  I was under the impression that it would simply return null but it seems that assumption was incorrect.

    So in order to work around this, you need to handle the exception that is being throw. Here's one way to do that:
    Copy Code
    try {
    Item0Caret0.SetText(true, Data["Name"].ToString(), 1, 10, false);
    }
     catch(System.ArgumentException e) {
     Log.WriteLine("Column was not found!");
     Item0Caret0.SetText(true, "Hello", 1, 10, false); 
    }

    Also, keep in mind that if you've added no databinding at all to your test, you're still going to get the same exception when you try to access a column in the datasource (i.e. it will not inform you that you have no databinding at all).

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