cancel
Showing results for 
Search instead for 
Did you mean: 

Let TryFind() return (a lot) faster for processes

Occasional Contributor

Let TryFind() return (a lot) faster for processes

Hi,

 

I try to determine in a loop whether certain processes are running and in turn handle different messageboxes that might appear. I noticed, that using 

driver.TryFind<IProcess>(new ProcessPattern() { ProcessName = "notExistingProcess" }, 1, 0, out var process);

takes more than 3 seconds on my machine, whereas 

Process.GetProcessesByName("notExistingProcess");

returns in a few (<10) milliseconds. I hoped that the timeOut parameter lets TryFind() return immediately, but obviously it's not the case.

 

Finding an existing process is fast:

driver.TryFind<IProcess>(new ProcessPattern() { ProcessName = "Explorer" }, 1, 0, out var process);

This takes 4 milliseconds.

 

Is there something I can do about it? Or do I have to use .NET Process class to check for the existing process first and only if it exists, use TestLeft to find the IProcess?

 

Thanks in advance!

4 REPLIES
Community Hero

Re: Let TryFind() return (a lot) faster

Hi,

 

As a kind of wild guess, what if for timeout you specify not zero, but some small value? Say, 100 or 500 (milliseconds). Does it help?

Otherwise, you may contact Support directly via the https://support.smartbear.com/message/?prod=TestLeft form.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Occasional Contributor

Re: Let TryFind() return (a lot) faster

Hi,

 

thank you for your reply, but no, it doesn't speed up things. I ended up with a workaround. I created an C# extension method, that inserts that .NET framework call before it calls TrayFind().

 public static class TestLeftExtensions
    {
        public static IProcess TryFindProcess(this IDriver driver, string processName)
        {
            if (System.Diagnostics.Process.GetProcessesByName(processName).Length == 0)
            {
                return null;
            }

            return Instances.Driver.Find<IProcess>(new ProcessPattern() { ProcessName = processName });
        }
    }

It can be used like this:

var process = this.Driver.TryFindProcess("NonExistingProcess");

I would not consider this behaviour a "bug", but for me it's a "major inconvenience".

 

I think this fix could be easily integrated into TestLeft directly.

Community Hero

Re: Let TryFind() return (a lot) faster

Hi,

 

While it is good to know that you have (quite a pretty, from my point of view) a workaround for the problem, the problem itself sounds strange for me and I would really recommend to contact Support via the link mentioned earlier and listen for what they will reply. (You may reference this thread if you like and update it with Support's response for the benefit of others.)

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Highlighted
Contributor

Re: Let TryFind() return (a lot) faster for processes

Try set search depth parameter to zero. 

Update to TestLeft 2.3
Labels