Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

## v1.6.0

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


Expand Down
18 changes: 7 additions & 11 deletions src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
namespace Winium.Desktop.Driver.CommandExecutors
{
#region using

using Winium.Desktop.Driver.CommandHelpers;

#endregion

internal class CloseExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
if (!this.Automator.ActualCapabilities.DebugConnectToRunningApp)
{
if (!this.Automator.Application.Close())
{
this.Automator.Application.Kill();
}

this.Automator.ElementsRegistry.Clear();
}

return this.JsonResponse();
return TerminateApp.TerminateExcecutor(this.Automator, this.JsonResponse());
}

#endregion
Expand Down
11 changes: 0 additions & 11 deletions src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ protected override string DoImpl()
// Gives sometime to load visuals (needed only in case of slow emulation)
Thread.Sleep(this.Automator.ActualCapabilities.LaunchDelay);

// Update running application process pointing to the real process instead of the launcher in such cases
if (this.Automator.Application.HasExited())
{
// Add parse process name pass from request
var realProcessName = this.ExecutedCommand.Parameters["desiredCapabilities"]["realProcessName"];
// Update launched process by process name if it's exited
if (realProcessName != null)
{
this.Automator.Application.UpdateProcessByName(realProcessName.ToString());
}
}
return this.JsonResponse(ResponseStatus.Success, this.Automator.ActualCapabilities);
}

Expand Down
18 changes: 7 additions & 11 deletions src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
namespace Winium.Desktop.Driver.CommandExecutors
{
#region using

using Winium.Desktop.Driver.CommandHelpers;

#endregion

internal class QuitExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
if (!this.Automator.ActualCapabilities.DebugConnectToRunningApp)
{
if (!this.Automator.Application.Close())
{
this.Automator.Application.Kill();
}

this.Automator.ElementsRegistry.Clear();
}

return this.JsonResponse();
return TerminateApp.TerminateExcecutor(this.Automator, this.JsonResponse());
}

#endregion
Expand Down
45 changes: 45 additions & 0 deletions src/Winium.Desktop.Driver/CommandHelpers/TerminateApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace Winium.Desktop.Driver.CommandHelpers
{
#region using

using System.Collections.Generic;
using System.Diagnostics;

using Winium.Desktop.Driver.Automator;

#endregion

public static class TerminateApp
{
public static string TerminateExcecutor(object automatorObject, string jsonResponse)
{
Automator automator = (Automator)automatorObject;
if (!automator.ActualCapabilities.DebugConnectToRunningApp)
{
// If application had exited, find and terminate all children processes
if (automator.Application.HasExited())
{
List<Process> children = new List<Process>();
children = automator.Application.GetChildPrecesses(automator.Application.GetProcessId());
foreach (var child in children)
{
if (!child.HasExited && !automator.Application.Close(child))
{
automator.Application.Kill(child);
}
}
}

// If application is still running, terminate it as normal case
else if (!automator.Application.Close())
{
automator.Application.Kill();
}

automator.ElementsRegistry.Clear();
}

return jsonResponse;
}
}
}
1 change: 1 addition & 0 deletions src/Winium.Desktop.Driver/Winium.Desktop.Driver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<Compile Include="CommandExecutors\NotImplementedExecutor.cs" />
<Compile Include="CommandExecutors\SwitchToWindowExecutor.cs" />
<Compile Include="CommandLineOptions.cs" />
<Compile Include="CommandHelpers\TerminateApp.cs" />
<Compile Include="ElementsRegistry.cs" />
<Compile Include="Extensions\AutomationPropertyHelper.cs" />
<Compile Include="Extensions\ByHelper.cs" />
Expand Down