Forum Discussion

socaltester's avatar
socaltester
Contributor
7 years ago

How to add the following to my Project Suite?

I'm new to TestComplete and fairly new to scripting in general. I could use assistance in adding the following script to my Project Suite via a Keyword Test or if not a Keyword Test a standard script to be called. The issue to resolve is if an 'iexplore.exe' process is running it needs to be terminated prior to launching a new instance of IE.

 

The below script is found in this post: https://community.smartbear.com/t5/TestComplete-Functional-Web/Cannot-obtain-the-window-with-the-window-class-IEFrame-Error/m-p/140614/thread-id/29622/highlight/true

 

 

//To run this function : i.e  fn_closeProcess("iexplore")

 

function fn_closeProcess(str_ProcessName)
{
      var arr_Processes = null;
     
      if(str_ProcessName != "")
      {
            arr_Processes = Sys.FindAllChildren("ProcessName",str_ProcessName);
           
            if(arr_Processes != null)
            {
                  for(var b = 0 ; b < arr_Processes.length ; b++)
                  {
                        arr_Processes[b].Close();
                  }
            }
           
            //if any missed process will finish off here
            var b_Object = Sys.WaitProcess(str_ProcessName, 1000);
           
            while(b_Object.Exists)
            {
                b_Object.Terminate();
                Log.Message("We have tried mutliple times to close the process [" + str_ProcessName + "] hence terminating the process.");
            }
           
            var chkObj = Sys.FindChild("ProcessName",str_ProcessName);
           
            if(!chkObj.Exists)
            {
                  return true;    
            }
            else
            {
                  Log.Message("We have tried terminating the process [" + str_ProcessName + "] but no luck. Need to have a LOOK!");
                  return false;
            }
      } 
      return false;
}

 

 

Thank you in advance for your assistance.

 

2 Replies