Forum Discussion

mikileung's avatar
mikileung
Occasional Contributor
4 years ago
Solved

Can I use variable in FindObject operation (Keyword Test)

Hi, 

 

I am writing a keyword test to find an object using "find object" with the criteria of contentText = "Manual entry, manual allocation"

 

However, I would like to change it to a variable, so that I can make it data driven. Is it possible? 

 

If not possible for keyword test, can I do that with a simple script? 

 

Thanks 

 

 

 

  • mikileung This KDT operation is a keyword test analog to searching for an object with the Find method and then calling a method or property of the found object. (https://support.smartbear.com/testcomplete/docs/keyword-testing/reference/test-actions/find-object.html)
    So, here are two parts: 1. when you are selecting the property and the value that are used to Find the object and 2. when you are calling the method or property of the object, doing something with the found object - e.g. click on it or changing the text.


    As far as I know this part - the operation is a keyword test analogue to searching for an object with the Find method - can't be parameterized (the one on your screenshot). The property will be the same that you choose.

     

    But this one - then calling a method or property of the found object - you can parameterize using KDT - instead of value in some cases you can use variable (e.g. for the SetText() method - see the screenshot)

     

     


    Alternatively, you can do it from script

     

     

    function Test1()
    {
      //JavaScript
      //Contents of the edit control, as text string.
      var PropNames, PropValues;
      PropNames = new Array("wText");
      PropValues = new Array("test");
      Aliases.notepad.Find(PropNames, PropValues, 1000, true).wText = "test1";
    }
    
    

     

     

    Try using this function and adding a loop and using PropValues not like an array, but rather a separate value and change it from Excel.
    An article for reference: https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/find-method.html 

2 Replies

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      mikileung This KDT operation is a keyword test analog to searching for an object with the Find method and then calling a method or property of the found object. (https://support.smartbear.com/testcomplete/docs/keyword-testing/reference/test-actions/find-object.html)
      So, here are two parts: 1. when you are selecting the property and the value that are used to Find the object and 2. when you are calling the method or property of the object, doing something with the found object - e.g. click on it or changing the text.


      As far as I know this part - the operation is a keyword test analogue to searching for an object with the Find method - can't be parameterized (the one on your screenshot). The property will be the same that you choose.

       

      But this one - then calling a method or property of the found object - you can parameterize using KDT - instead of value in some cases you can use variable (e.g. for the SetText() method - see the screenshot)

       

       


      Alternatively, you can do it from script

       

       

      function Test1()
      {
        //JavaScript
        //Contents of the edit control, as text string.
        var PropNames, PropValues;
        PropNames = new Array("wText");
        PropValues = new Array("test");
        Aliases.notepad.Find(PropNames, PropValues, 1000, true).wText = "test1";
      }
      
      

       

       

      Try using this function and adding a loop and using PropValues not like an array, but rather a separate value and change it from Excel.
      An article for reference: https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/find-method.html