Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when close launched application new approach #107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
67 changes: 37 additions & 30 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
# Change Log

<!--## Unreleased
- Support GetCurrentWindowHandle and GetWindowHandles
- Add driver option --silent to disable logging
-->

## v1.5.0

# Change Log

<!--## Unreleased
- Support GetCurrentWindowHandle and GetWindowHandles
- Add driver option --silent to disable logging
-->


## v1.6.0

- Fix exception Process Not Found in close/quit function
- Fix throw exceptions in getting some gui element's attributes


## v1.5.0

- Add `SwitchToWindow` command
- Fix XPath attribute value if this ControlType
## v1.4.0
- Fix XPath attribute value if this ControlType


## v1.4.0

- Add `XPath` strategy for locating elements
- Add `GetCurrentWindowHandle` command
- Add `GetWindowHandles` command
- Add `--silent` option to a driver CLI (suppresses output)
- Fix logger timestamp format
## v1.3.0
- Fix logger timestamp format


## v1.3.0

- Fix error response format
- Add `args` capability for launching application with arguments
- Set default elements search timeout to 10 seconds (fixed in [Winium.Cruciatus 2.7.0](https://github.com/2gis/Winium.Cruciatus/releases/tag/v2.7.0))
Expand All @@ -30,14 +37,14 @@
- ComboBox (collapse, expand, is expanded, find selected item, scroll to item)
- DataGrid (row count, column count, find cell, scroll to cell, select cell)
- ListBox (scroll to item)
- Menu (find item, select item)
## v1.2.0
New features:
- Support Action Chains from bindings
- Add new script command for setting value to element using ValuePattern
- Menu (find item, select item)


## v1.2.0

New features:
- Support Action Chains from bindings
- Add new script command for setting value to element using ValuePattern



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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ protected override string DoImpl()
* string, bool, int - should be as plain text
* System.Windows.Automation.ControlType - should be used `ProgrammaticName` property
* System.Window.Rect, System.Window.Point - overrides `ToString()` method, can serialize
* Int32[] array - use `string.Join()` method, can serialize
* enum - use `ToString()` method, can serialize
*/
private static object PrepareValueToSerialize(object obj)
{
Expand All @@ -58,6 +60,18 @@ private static object PrepareValueToSerialize(object obj)
return controlType.ProgrammaticName;
}

var intArray = obj as Int32[];
if (intArray != null)
{
return string.Join(",", intArray);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do integer arrays need special serialization? By default the should be serialized as json object like other arrays, dictionaries, etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last time, I had problem when get specific property of GUI element which returns array of integers (not remember exactly its type, System.Int32[] or System.Int64[]) and throws exception that type of object is not serialized object. So I force it as Int32[] and put result as string.

}

var intValue = obj as Enum;
if (intValue != null)
{
return intValue.ToString();
}

return obj;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override string DoImpl()

// Gives sometime to load visuals (needed only in case of slow emulation)
Thread.Sleep(this.Automator.ActualCapabilities.LaunchDelay);

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