Forum Discussion

helpdesk's avatar
helpdesk
Occasional Contributor
6 years ago

Script To Automatically Close 'Active' Window

Hi all,

 

I have another question that may sound silly. The application I am testing will open patient records in 2 different ways, half will be maximised view and the other half is a minimised view. Both views have a 'Minimise', 'Maximise' and 'Close' button. 

 

My issue is when setting up the automated tests I run into problems as sometimes the window will be maximised and others minimised so when I go to close the window the test case will fail as it is looking for the 'Close' function to be in a specific spot which it is not.

 

What I was wanting to do it run a script to close the window regardless of where it is place on the screen. I figured I could do this using the 'Run Code Snippet' feature but unfortunately, I am not a coder and the developers we use are through an external company. I tried googling and searching on this forum to see if there was a snipit of code for a Microsoft.Net program to execute the close button but I am not finding anything too helpful.

 

I was hoping someone might be able to point me to some information that may help me, If more information is needed or screenshots are needed please let me know.

 

Thank you and I hope my query makes sense. 

  • Hi,

     

    I assume that you are working with a desktop application...

    Usually, desktop windows have .Close() method that closes them. Check this with Object Browser.

    Alternatively, you may send keys combination to the window that closes it. Usually this is Ctrl-F4 or Ctrl-W.

    Both approaches should close the target window without the necessity to click its Close button.

     

  • helpdesk's avatar
    helpdesk
    6 years ago

    Thank you very much - Control F4 closes any active window within the application.

     

    I appreciate the response :)

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    I assume that you are working with a desktop application...

    Usually, desktop windows have .Close() method that closes them. Check this with Object Browser.

    Alternatively, you may send keys combination to the window that closes it. Usually this is Ctrl-F4 or Ctrl-W.

    Both approaches should close the target window without the necessity to click its Close button.

     

    • helpdesk's avatar
      helpdesk
      Occasional Contributor

      Thank you very much - Control F4 closes any active window within the application.

       

      I appreciate the response :)

  • mioani's avatar
    mioani
    Occasional Contributor

    Hello,

     

    Maybe you can use this code here https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/window-and-process/terminate-method-process-object.html choose the languange in which your project is and instead run code snippet use run script routine.

    Hope this helps.

     

     

    i'm sorry, didn't understand correctly, you want to close a window which is part of your application not another app that is called from the first one. My bad.