Forum Discussion

zoey's avatar
zoey
Occasional Contributor
6 months ago

Process still stuck in task manager after closing it .

Hi all , 

I have an issue  when I tried to close process by using Sys.WaitProcess(" app name ", 0).Close () , 

sometimes test complete  can't close  the process correctly and process still stuck , so  the next test can't start running because previous test not closed the application correctly . What's the reason for that ? 

 

Thanks . 

9 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Ignore my previous responses, just have a look at the code example I have provided. Run the code against Notepad, and understand the code. You should then be able to adapted the code for your application. 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Oops, I've just noticed you are using Sys.WaitProcess() and not Sys.Process()

     

    Here's an example,

    function Notepad()
    {
        // Assuming Notepad is opened.
        
        var process = Sys.Process("notepad");
        
        // Enter text
        process.Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1).SetText("Smartbear"); // Comment out line
        
        // Close application    
        Sys.Process("notepad").Close();
        
        // Respond to save dialog
        if (Sys.WaitProcess("notepad", 5000).Exists)
        {
            // Click 'don't save' button
            process.Window("#32770", "Notepad", 1).UIAObject("Notepad").Window("CtrlNotifySink", "", 8).Window("Button", "Do&n't Save", 1).Click();
        }
    }

    1. Launch Notepad, and run the script.

    2. Comment out the SetText() line. 

    3. Launch Notepad again, and run the script.

     

    The script deals with the 'Do you want to save changes to Untitled?' dialog appearing, as well it not appearing.

     

     

    • zoey's avatar
      zoey
      Occasional Contributor

      Hi ,

      Thanks again , but I would have a question do you mean my issue was when I used Sys.WaitProcess() and not Sys.Process() 

       so do you mean issue will solve when  close the application not using ( File->Exit )  and click on "No" button in close popup and check process if closed or not as before , but it will use Close method only to close it and check close popup , right ? 

      look at for my bellow code : 

       

       

       

       

       

       

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Does you application support the close window message or similar? With Windows application, you can send a signal to instruct the application to terminate. With TC, you do this via Sys.Process("notepad").Close(), providing your application supports it. Otherwise, you will have to do File -> Close via the menu.

    • zoey's avatar
      zoey
      Occasional Contributor

      I am not sure if understand you correctly , I think not support  when close my application using (file->exit ) the close popup appeared to save or not save the opened file , and when click on  "No " button in this close popup , I called this  Sys.WaitProcess("Spotfire.Dxp",0).Close() to close "Spotfire.Dxp" from task manager , but sometimes test complete can't close it , how can test complete close process correctly without happened any unexpected error ? do you mean I should be use Sys.Process("Spotfire.Dxp").Close()  instead of Sys.WaitProcess("Spotfire.Dxp",0).Close()?

       

      close popup :

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    What does Object Browser show for your process. For example, Notepad is shown like this

     

    Is Spotfire.Dxp an actual executable file e.g. Spotfire.Dxp.exe?

    • zoey's avatar
      zoey
      Occasional Contributor

      yes , object browser for the process it's appeared as "Spotfire.Dxp"

       

  • Hi zoey,

     

    If the process to be closed has an event handler that requires user final interaction, this can indeed block (dialog "do you want to save your file", etc.).

     

    In my opinion, the problem is more the method used.

     

    Personally, I've created a dedicated method that applies the Close() command and tests for correct closure, several times (in order to send the Close() command back to potentially open child dialogs) and as a last resort ends with the Terminate() command to guarantee closure (with an ultimate test for correct closure).

     

    For the exact reason of no closure of your process, it's more the process to be closed that contains it... Are there any logs to trace what happens when it receives the close message?

    • zoey's avatar
      zoey
      Occasional Contributor

      Hello ,

      Thanks in advance for your replied  , you mean close method doesn't work correctly when event handler that requires user final interaction  ? , my test finished by exit an application (File->exit ) and when exit an application  popup message appeared to ask if you want to save file or not  as you said "process to be closed has an event handler that requires user final interaction",

      my code here  applied to  exit without save the file  then check the process if still stuck in background or not ,   

      when I looked to test logs in the bellow seems test printed the message "before check process " in the logs but not close the process maybe unexpected error happened but I don't know what's the error , so process still stuck in task manager and next test can't start if not close correctly .

      so how can I fix this issue ? 

       

      Thanks .