Ranorex & Windows Shutdown

Experiences, small talk, and other automation gossip.
DownLoad
Posts: 4
Joined: Wed Aug 13, 2014 6:56 pm

Ranorex & Windows Shutdown

Post by DownLoad » Wed Aug 13, 2014 7:01 pm

Hi,

So I'm currently trying to run a test for one of our applications. The test should fail if the application finishes and restarts Windows. However currently if the application restarts Windows 7 during a test, Ranorex does not seem to have a log for that session.

So I guess my question is the following: Is there a way to capture a Windows 7 shutdown in a test and report a failure in a log/shutdown test execution nicely?

I've played around with SetConsoleCtrlHandler, however it seems capturing windows shutdowns is not possible for console applications in Windows 7.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Ranorex & Windows Shutdown

Post by krstcs » Thu Aug 14, 2014 1:20 pm

No, there is no way to capture shutdown on a Windows system with any automated testing tool due to the way Windows shutdowns work.

Once Windows starts shutting down, it kills all non-OS process that are running on the system, before it starts the actual shutdown process. This means that Ranorex (and any other 3rd-party tools) would be shutdown before it could even figure out that Windows was shutting down.
Shortcuts usually aren't...

DownLoad
Posts: 4
Joined: Wed Aug 13, 2014 6:56 pm

Re: Ranorex & Windows Shutdown

Post by DownLoad » Thu Aug 14, 2014 4:27 pm

krstcs wrote:No, there is no way to capture shutdown on a Windows system with any automated testing tool due to the way Windows shutdowns work.

Once Windows starts shutting down, it kills all non-OS process that are running on the system, before it starts the actual shutdown process. This means that Ranorex (and any other 3rd-party tools) would be shutdown before it could even figure out that Windows was shutting down.
Thanks for the reply. However... You actually can capture shutdowns in programs. For instance one of our programs captures the event using the SystemEvents.SessionEnding event, so we can shut it down gracefully. Unfortunately for my Ranorex tests I can only get a similar behaviour if I create a form and use the SessionEnding event there. I am still investigating and trying new things.

With that said, what's the best way to have a Ranorex test suite stop execution via code? So I can catch this shutdown event, and hopefully stop the tests in time for Ranorex to generate an actual report before Windows shutsdown.

Oh and all of my code is in C#.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Ranorex & Windows Shutdown

Post by krstcs » Thu Aug 14, 2014 4:57 pm

My apologies, I misread your post. I thought you meant the actual shutdown itself. :D You are correct, the OS does throw the shutdown event to all applications.

As far as stopping the test, my suggestion would be to look through the API documentation at http://www.ranorex.com/Documentation/Ranorex/

You might find something in there, but I'm not seeing anything in the public sections. You could raise an exception in your test that Ranorex would catch as a failure, but that is a bit of a kludge.
Shortcuts usually aren't...

DownLoad
Posts: 4
Joined: Wed Aug 13, 2014 6:56 pm

Re: Ranorex & Windows Shutdown

Post by DownLoad » Thu Aug 14, 2014 11:16 pm

Alright so right now I'm sort of stuck with how to catch SystemEvents. Perhaps someone here may have some ideas. The whole SystemEvents.SessionEnding events will only work on non-console applications. When we run our tests here we originally had the project as a Console Application so I tried switching it to Windows Application. However with that done, using the SystemEvents.SessionEnding still didn't work.

The only way I've been able to catch a SessionEnding has been if I made an actual Form in my test code, and then attached SystemEvents.SessionEnding in there. However for this form to work I'd have to invoke ShowDialog() on the Form, which would then cause my test code not too continue to execute due to the form.

I've tried putting this form into its own thread, however when I do this, it no longer catches (or maybe no longer receives) the events when Windows shuts down.

This is probably a pretty rare thing that I want to do, but hopefully someone has experience with this. Like I mentioned before we do have an existing application that catches the SessionEnding without an active form, and its code is extremely simple so I'm wondering if its perhaps its something with the way Ranorex runs the test code? Inside the Main function I see: error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);, could this be part of the reason?

Anyway I've been working on this on my side for a while, but may just drop this feature/these tests I'm trying to automate for now and come back later. Any advice or tips is greatly appreciated!

DownLoad
Posts: 4
Joined: Wed Aug 13, 2014 6:56 pm

Re: Ranorex & Windows Shutdown

Post by DownLoad » Tue Aug 19, 2014 6:43 pm

Just providing an update in case anyone's still looking at the thread. Currently I am able to detect a system reboot by overriding WndProc in a form in a separate thread than the main test one. When I detect a reboot I report a failure and save it before Windows shuts everything down.

Now unfortunately the code module says it is failing, but the actual code suite and test case say it passes. Looking through old threads it seems you cannot report a failure and have the test case of the module fail from a separate thread than the main one... As well I cannot use a global variable and have the main thread check for it since it gets shutdown before it can do anything (have not had any luck having the main thread check for Windows Messages)

So with that said does anyone have any other suggestions?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex & Windows Shutdown

Post by Support Team » Thu Aug 28, 2014 7:24 am

Hello DownLoad,

As already mentioned correctly, it is not possible to raise an error within the main thread from a ‚side-thread‘ (besides aborting the thread). We are currently working on a solution which allows Ranorex to close running tests whenever the system is shut down.

As a workaround I would suggest to lower the report interval in order to reduce the loss of information. The “Auto Save Interval” can be changed within the Test Suite Settings

Hope this information helps.

Regards,
Robert
.
Image