Forum Discussion

nish_b's avatar
nish_b
Contributor
5 years ago
Solved

Passing parameters from Organize Tests to test script

Hi,

 

How to pass parameters from a script test using Parameters column present in Organize Tests view and then read that value within the test script?


For example: I want to pass paramenters like browser value (such as Edge) and read this value into a variable within my test script and launch the specified browser accordingly.

 

Is this possible? If yes, please explain how? Thanks!

  • I must be honest and say that I don't quite understand how that is not addressed by the initial code I posted.  Perhaps you are trying to return the browser as an object from another script call ?  In that case, replace

     

    Browsers.Item(browsername,url).Run();

    with

    return Browsers.Items(browsername,url);

     

    Then in your calling function, rather than

    StartBrowser('edge','www.mywebsite.com');

    do:

    var newBrowser = StartBrowser('edge','www.mywebsite.com');

    newBrowser.Run();

  • You can use a function in script with a parameter/mutiple parameters.  Create the function in the initial post.  Now drag that script unit into your window.  All the functions in your script will be added.  Remove the ones you don't want, then update the parameters as required - just like setting in in a KWT. Alternatively, add new test item.  Click elipses in the test column and select the script.  This process looks the same as "Run Script" from within a KWT

     

     

     

     

11 Replies

  • Yes, it can be done.

     

    You have to change the signature of your script function to accept a parameter e.g.

     

    function StartBrowser(browsername, url)
    {
      //This following logic handles when your call to the function doesn't supply a value for the first parameter
      if(browsername==undefined || browsername==null){
       browsername = 'iexplore'
      }
    if(url == undefined || url==null{
      url ='www.mywebpage.com';
    }
     //start the browser - can't recall the command exactly for this, since it's one of my tested applications so I don't need to worry
    Browsers.Item(browsername).Run(url);
    }
    
    function CallStartBrowser(){
    StartBrowser('edge','www.website2.com');
    }

    If you drag your StartBrowser script into your keyword designer, you will be able to double click the parameters column.  This will bring up an operation parameters box where you can specify the details

    • nish_b's avatar
      nish_b
      Contributor

      Hi Rudolf,

       

      Thanks for your reply! But, I am somehow unable to figure out how to do this: If you drag your StartBrowser script into your keyword designer, you will be able to double click the parameters column.  

       

      Still new to the tool, so could you provide a screenshot or elucidate more on the step please?

      • RUDOLF_BOTHMA's avatar
        RUDOLF_BOTHMA
        Community Hero

        The best place to get some help would be the TC help files. From your TC application open help (F1) and look up "Run script routine operation" You can also look at "Checking operation Result" these two work together to get to what you are trying to achieve

        There are two ways of getting a script to run from your KWT.

        1. Select the "Run Script Routine" operation, select the script you want to run, then complete the operation parameters
        2. Take the script object from the project workspace->project explorer and drag it into the KWT window. From here it is the same as "Run Script Routine"