Generic Test pass in parameters

2 posts, 0 answers
  1. Lisa
    Lisa avatar
    23 posts
    Member since:
    Nov 2017

    Posted 02 Jan Link to this post

    Hello,

    I have an issue that I have a feeling can only be addressed by coded steps, but I want to make sure I'm right on this (we are trying to avoid coded steps as much as possible).

    I have a test that I'd like to make very generic. It's a test to use one of our menus to navigate to different places in the application. I'd prefer not to record a version of this for each navigation that we do, so I created one that will take in a data source from the parent with the navigation variables, so far so good.

    The problem is this step might need to be used several times in a test, with different selections each time. This makes it hard/impossible to bind a specific value to it because the parent can only (as far as I know) send in the data it has been sent. There doesn't seem to be another way to pass from a parent test to a Test as Step test a set of variables.

    Let me know if I'm wrong.

  2. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    272 posts

    Posted 03 Jan Link to this post

    Hello Lisa,

    If I got this query right you need to pass data from parent to child test. One of the possibilities is to use the parent data source when use a test property option to "InheritParentDataSource". This will not allow you to have the child test binded and to loop over other variables set though. 

    It is possible in very simple code to store current data value in a static variable in the parent test that will be available for the child test when it will be executed. This way it will be possible to have binded the child test and to have the data from the parent test as well.

    public class ParentTest : BaseWebAiiTest
    {
        // variable to pass data to other tests
        public static string someVariable = string.Empty;
     
        [CodedStep(@"New Coded Step")]
        public void ParentTest_CodedStep()
        {
            // store current data value in a static variable
            someVariable = Data["DataColumnName"].ToString();
        }
    }

    The variable will be available in the child test trough parent test class. If execute this line in the child test coded step - the static variable value will be printed in the execution log:
    Log.WriteLine(" Parent test variable: " + ParentTest.someVariable.ToString());

    If you want to avoid using code in the child test, you could set the parent data value in an extraction variable in the parent test:

    this.SetExtractedValue("extractedVariableName", Data["DataColumnName"].ToString());

    Then in the child test it will be possible to use this variable trough data binding property of an input element for example. There is more information related to such scenario available here.

    Please, let me know whether this helps or additional directions/assistance is required.

    Best Regards,
    Nikolay Petrov
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top