How do I identify a console process?

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

How do I identify a console process?

Post by HansSchl » Wed Sep 19, 2018 10:14 am

I am using Ranorex 4.0 under Windows 8.1 64-bit. My test case requires to run a helper application that has no GUI, and to wait for this application to finish before the test case continues. I can launch the application by a "Run application" step, but how can I use "Wait for" to wait until the console application has finished?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How do I identify a console process?

Post by odklizec » Wed Sep 19, 2018 12:56 pm

Hi,

Ranorex 4.0 is pretty old and I doubt there is anyone who can even remember its coding possibilities? Generally speaking, you should be able to write a "search process" method, in which you can wait for the process termination.

Here are few process -related examples, whcih should help you with writing such method:
https://stackoverflow.com/questions/262 ... is-running
https://social.msdn.microsoft.com/Forum ... nning-in-c
https://support.microsoft.com/en-us/hel ... g-visual-c
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

Re: How do I identify a console process?

Post by HansSchl » Wed Sep 19, 2018 12:59 pm

Sorry... I read the wrong line in the "About" dialog. Ranorex version is 8.2.1 :-) Downloaded and installed today...

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How do I identify a console process?

Post by odklizec » Wed Sep 19, 2018 1:02 pm

Good ;) In any case, you will have to write your own method to wait for the end of process. The links I posted should help you with this task.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

Re: How do I identify a console process?

Post by HansSchl » Wed Sep 19, 2018 1:04 pm

I had hoped it's built into Ranorex. Thanks anyway...

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How do I identify a console process?

Post by odklizec » Wed Sep 19, 2018 1:06 pm

Nope, there is no such "wait" available. Existing wait actions are UI related ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

Re: How do I identify a console process?

Post by asdf » Wed Sep 19, 2018 1:12 pm

Hi,

The easiest way would be to start the application through code and wait for the exit code of it.

Code: Select all

using System.Diagnostics;
...
Process process = new Process();    // Configure the process using the StartInfo properties.
process.StartInfo.FileName = "process.exe";
process.StartInfo.Arguments = "-YourArguments";
process.Start();
process.WaitForExit();// Waits here for the process to exit.
Hope that helps.
ASDF

HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

Re: How do I identify a console process?

Post by HansSchl » Wed Sep 19, 2018 2:45 pm

Ok, that would be a complete action that launches the console app and only returns when the app has terminated. What if I wanted to do something else while the app is running, and at some later step of my test case wait for the app to terminate? Can I write a function with a signature like 'bool ProcessExists(string procName)', and use it in a 'Wait for' action?

HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

Re: How do I identify a console process?

Post by HansSchl » Thu Sep 20, 2018 7:39 am

I solved the problem. Thank you for pointing me into the correct direction :-)

Code: Select all

    	[UserCodeMethod]
    	public static void RunProgramAndWait(string path, string args, int waitSeconds)
    	{
    		Process process = new Process();    // Configure the process using the StartInfo properties.
			process.StartInfo.FileName = path;
			process.StartInfo.Arguments = args;
			if (!process.Start())
				throw new RanorexException("Could not create process '" + path + "'");
			if (!process.WaitForExit(waitSeconds * 1000))
				throw new RanorexException("Process '" + path + "' failed to terminate within " + waitSeconds.ToString() + " seconds");
    	}