From 027b77a71e4487f44d4b85c5b9f50a6bc2c5f918 Mon Sep 17 00:00:00 2001 From: quangnt Date: Wed, 27 Apr 2016 13:18:32 +0700 Subject: [PATCH 1/3] * 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 error when get some attributes. --- CHANGELOG.md | 68 +++++++++++-------- .../GetElementAttributeExecutor.cs | 14 ++++ .../CommandExecutors/NewSessionExecutor.cs | 13 +++- 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e523b4..0ea37c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,27 +1,35 @@ -# Change Log - - - - ## v1.5.0 - +# Change Log + + + + +## 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 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)) @@ -30,14 +38,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 + + + diff --git a/src/Winium.Desktop.Driver/CommandExecutors/GetElementAttributeExecutor.cs b/src/Winium.Desktop.Driver/CommandExecutors/GetElementAttributeExecutor.cs index 55af92c..b94af0a 100644 --- a/src/Winium.Desktop.Driver/CommandExecutors/GetElementAttributeExecutor.cs +++ b/src/Winium.Desktop.Driver/CommandExecutors/GetElementAttributeExecutor.cs @@ -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) { @@ -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); + } + + var intValue = obj as Enum; + if (intValue != null) + { + return intValue.ToString(); + } + return obj; } diff --git a/src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs b/src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs index e9b448a..2c50786 100644 --- a/src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs +++ b/src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs @@ -31,7 +31,18 @@ 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); } From d595059ca11729318944bd73e1dede794117f06a Mon Sep 17 00:00:00 2001 From: quangnt Date: Thu, 5 May 2016 15:38:22 +0700 Subject: [PATCH 2/3] CHAT-2464 Find child processes in Quit,Close to fix issue Process Terminated. --- CHANGELOG.md | 3 +- .../CommandExecutors/CloseExecutor.cs | 18 +++----- .../CommandExecutors/NewSessionExecutor.cs | 11 ----- .../CommandExecutors/QuitExecutor.cs | 18 +++----- .../CommonHelpers/CommonHelpers.cs | 45 +++++++++++++++++++ .../Winium.Desktop.Driver.csproj | 1 + 6 files changed, 61 insertions(+), 35 deletions(-) create mode 100644 src/Winium.Desktop.Driver/CommonHelpers/CommonHelpers.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ea37c3..94523fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs b/src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs index 4cbbacd..93525e2 100644 --- a/src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs +++ b/src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs @@ -1,22 +1,18 @@ namespace Winium.Desktop.Driver.CommandExecutors { + #region using + + using Winium.Desktop.Driver.CommonHelpers; + + #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 CommonHelpers.TerminateExcecutor(this.Automator, this.JsonResponse()); } #endregion diff --git a/src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs b/src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs index 2c50786..982c73a 100644 --- a/src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs +++ b/src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs @@ -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); } diff --git a/src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs b/src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs index 59b6fb6..7d7d084 100644 --- a/src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs +++ b/src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs @@ -1,22 +1,18 @@ namespace Winium.Desktop.Driver.CommandExecutors { + #region using + + using Winium.Desktop.Driver.CommonHelpers; + + #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 CommonHelpers.TerminateExcecutor(this.Automator, this.JsonResponse()); } #endregion diff --git a/src/Winium.Desktop.Driver/CommonHelpers/CommonHelpers.cs b/src/Winium.Desktop.Driver/CommonHelpers/CommonHelpers.cs new file mode 100644 index 0000000..98e2797 --- /dev/null +++ b/src/Winium.Desktop.Driver/CommonHelpers/CommonHelpers.cs @@ -0,0 +1,45 @@ +namespace Winium.Desktop.Driver.CommonHelpers +{ + #region using + + using System.Collections.Generic; + using System.Diagnostics; + + using Winium.Desktop.Driver.Automator; + + #endregion + + public static class CommonHelpers + { + 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 children = new List(); + 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; + } + } +} diff --git a/src/Winium.Desktop.Driver/Winium.Desktop.Driver.csproj b/src/Winium.Desktop.Driver/Winium.Desktop.Driver.csproj index a6bcf99..09369c1 100644 --- a/src/Winium.Desktop.Driver/Winium.Desktop.Driver.csproj +++ b/src/Winium.Desktop.Driver/Winium.Desktop.Driver.csproj @@ -116,6 +116,7 @@ + From 4ab296dcf87a0050bee9aab6cf6eec64ae27ca45 Mon Sep 17 00:00:00 2001 From: quangnt Date: Fri, 8 Jul 2016 11:36:17 +0700 Subject: [PATCH 3/3] Address comments from LongTruong --- src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs | 4 ++-- src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs | 4 ++-- .../CommonHelpers.cs => CommandHelpers/TerminateApp.cs} | 4 ++-- src/Winium.Desktop.Driver/Winium.Desktop.Driver.csproj | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename src/Winium.Desktop.Driver/{CommonHelpers/CommonHelpers.cs => CommandHelpers/TerminateApp.cs} (94%) diff --git a/src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs b/src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs index 93525e2..41d90b5 100644 --- a/src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs +++ b/src/Winium.Desktop.Driver/CommandExecutors/CloseExecutor.cs @@ -2,7 +2,7 @@ { #region using - using Winium.Desktop.Driver.CommonHelpers; + using Winium.Desktop.Driver.CommandHelpers; #endregion @@ -12,7 +12,7 @@ internal class CloseExecutor : CommandExecutorBase protected override string DoImpl() { - return CommonHelpers.TerminateExcecutor(this.Automator, this.JsonResponse()); + return TerminateApp.TerminateExcecutor(this.Automator, this.JsonResponse()); } #endregion diff --git a/src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs b/src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs index 7d7d084..fa507be 100644 --- a/src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs +++ b/src/Winium.Desktop.Driver/CommandExecutors/QuitExecutor.cs @@ -2,7 +2,7 @@ { #region using - using Winium.Desktop.Driver.CommonHelpers; + using Winium.Desktop.Driver.CommandHelpers; #endregion @@ -12,7 +12,7 @@ internal class QuitExecutor : CommandExecutorBase protected override string DoImpl() { - return CommonHelpers.TerminateExcecutor(this.Automator, this.JsonResponse()); + return TerminateApp.TerminateExcecutor(this.Automator, this.JsonResponse()); } #endregion diff --git a/src/Winium.Desktop.Driver/CommonHelpers/CommonHelpers.cs b/src/Winium.Desktop.Driver/CommandHelpers/TerminateApp.cs similarity index 94% rename from src/Winium.Desktop.Driver/CommonHelpers/CommonHelpers.cs rename to src/Winium.Desktop.Driver/CommandHelpers/TerminateApp.cs index 98e2797..3855a28 100644 --- a/src/Winium.Desktop.Driver/CommonHelpers/CommonHelpers.cs +++ b/src/Winium.Desktop.Driver/CommandHelpers/TerminateApp.cs @@ -1,4 +1,4 @@ -namespace Winium.Desktop.Driver.CommonHelpers +namespace Winium.Desktop.Driver.CommandHelpers { #region using @@ -9,7 +9,7 @@ #endregion - public static class CommonHelpers + public static class TerminateApp { public static string TerminateExcecutor(object automatorObject, string jsonResponse) { diff --git a/src/Winium.Desktop.Driver/Winium.Desktop.Driver.csproj b/src/Winium.Desktop.Driver/Winium.Desktop.Driver.csproj index 09369c1..10f5fe0 100644 --- a/src/Winium.Desktop.Driver/Winium.Desktop.Driver.csproj +++ b/src/Winium.Desktop.Driver/Winium.Desktop.Driver.csproj @@ -116,7 +116,7 @@ - +