Skip to content

Commit ef8b13b

Browse files
author
quangnt
committed
Find child processes in Quit,Close to fix issue Process Terminated.
1 parent 027b77a commit ef8b13b

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
## v1.6.0
1010

11-
- Allow switching process name to `realProcessName` for an apps starting
12-
with a launcher. That can fix exception Process Not Found in close/quit function
11+
- Fix exception Process Not Found in close/quit function
1312
- Fix throw exceptions in getting some gui element's attributes
1413

1514

src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
namespace Winium.Desktop.Driver.CommandExecutors
22
{
3+
#region using
4+
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
8+
#endregion
9+
310
internal class CloseExecutor : CommandExecutorBase
411
{
512
#region Methods
@@ -8,7 +15,26 @@ protected override string DoImpl()
815
{
916
if (!this.Automator.ActualCapabilities.DebugConnectToRunningApp)
1017
{
11-
if (!this.Automator.Application.Close())
18+
// If application had exited, find and terminate all children processes
19+
if (this.Automator.Application.HasExited())
20+
{
21+
List<Process> children = new List<Process>();
22+
children = this.Automator.Application.GetChildPrecesses(this.Automator.Application.GetProcessId());
23+
if (children.Count == 0)
24+
{
25+
children = this.Automator.Application.GetAllPrecessesByName(this.Automator.Application.GetProcessName());
26+
}
27+
foreach (var child in children)
28+
{
29+
if (!child.HasExited && !this.Automator.Application.Close(child))
30+
{
31+
this.Automator.Application.Kill(child);
32+
}
33+
}
34+
}
35+
36+
// If application is still running, terminate it as normal case
37+
else if (!this.Automator.Application.Close())
1238
{
1339
this.Automator.Application.Kill();
1440
}

src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
namespace Winium.Desktop.Driver.CommandExecutors
22
{
3+
#region using
4+
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
8+
#endregion
9+
310
internal class QuitExecutor : CommandExecutorBase
411
{
512
#region Methods
@@ -8,7 +15,26 @@ protected override string DoImpl()
815
{
916
if (!this.Automator.ActualCapabilities.DebugConnectToRunningApp)
1017
{
11-
if (!this.Automator.Application.Close())
18+
// If application had exited, find and terminate all children processes
19+
if (this.Automator.Application.HasExited())
20+
{
21+
List<Process> children = new List<Process>();
22+
children = this.Automator.Application.GetChildPrecesses(this.Automator.Application.GetProcessId());
23+
if (children.Count == 0)
24+
{
25+
children = this.Automator.Application.GetAllPrecessesByName(this.Automator.Application.GetProcessName());
26+
}
27+
foreach (var child in children)
28+
{
29+
if (!child.HasExited && !this.Automator.Application.Close(child))
30+
{
31+
this.Automator.Application.Kill(child);
32+
}
33+
}
34+
}
35+
36+
// If application is still running, terminate it as normal case
37+
else if (!this.Automator.Application.Close())
1238
{
1339
this.Automator.Application.Kill();
1440
}

0 commit comments

Comments
 (0)