Forum Discussion

vinodkumar_chau's avatar
vinodkumar_chau
Contributor
9 years ago

Parameterization of a “set of scripts”

Hi ,

 

I need to Parameterize set of scripts. 

For example , i have 10 scripts which needs to be run on win7 , MSOffice 2007 , and IE 10. All 3 conditions needs to be true before running the script. How should i do it in testcomplete with Jscript ?

3 Replies

  • Hello vinodkumar_chau,

     

    Are they connected scripts..? But generally you can check whether the process is existing ot not by the following syntax.

     

    if(Sys.Process("YXQ").Exists)

    {

    //Execute scripts;

     }

     

    function for getting the type of Operating System 

     

    function OSName ()
    {
    var strComputer, objWMIService, colOperatingSystemsList;
    var colOperatingSystems, objOperatingSystem;
    strComputer = ".";
    objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!//" + strComputer + "/root/cimv2");
    colOperatingSystemsList = objWMIService.ExecQuery("Select * from " + "Win32_OperatingSystem");
    colOperatingSystems = new Enumerator(colOperatingSystemsList);
    for ( ; !colOperatingSystems.atEnd(); colOperatingSystems.moveNext() )
    {
    objOperatingSystem = colOperatingSystems.item();
    Log.Message("OS: " + objOperatingSystem.Name);
    }

    return objOperatingSystem.Name;         
    }

     

     

     //From the above function you will get a long string with operating system and some other text extract the req string and compare 

     

     

    var OS_Name=OSName ();                          // getting and storing the extracted string in the variable using the above function ....

     

    if(Sys.Process("Word").Exists)

    {

    if(OS_Name=="Windows7")                       //Comparing the extracted string ....

    {

    //Test Scripts

    }else

    {

    Log.Message("Doesnt satisfy the conditions");

    }

    }

    • vinodkumar_chau's avatar
      vinodkumar_chau
      Contributor

      Hi ,

       

      Thanks iamraj09 for the reply.

      What i am looking for is that before my all 10 scripts run , there should be some method or mechanism  where in i first check the OS , IE version etc on the system where these 10 scripts will run and if it satisfies the conditions , then the scripts should run otherwise not.

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        The variation of the above advice is to create a function that will check conditions that you need and store the result into one or more (temporary) project variables (e.g. OSName and IsWordRunning).

        Then at the beginning of every function called from those 10 units you can add something like this:

        If (Not ("Win7" = Project.Variables.OSName And Project.Variables.IsWordRunning)) Then

          Exit Function

        End If

        ...