diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.Common/HttpResponseHelper.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.Common/HttpResponseHelper.cs index 4dacde5..ac9c885 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.Common/HttpResponseHelper.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.Common/HttpResponseHelper.cs @@ -44,7 +44,7 @@ public static Dictionary StatusCodeDescriptors public static string ResponseString(HttpStatusCode statusCode, string content) { - var contentType = statusCode == HttpStatusCode.BadRequest ? PlainTextContentType : JsonContentType; + var contentType = IsClientError((int)statusCode) ? PlainTextContentType : JsonContentType; string statusDescription; StatusCodeDescriptors.TryGetValue(statusCode, out statusDescription); @@ -59,6 +59,11 @@ public static string ResponseString(HttpStatusCode statusCode, string content) return responseString.ToString(); } + public static bool IsClientError(int code) + { + return code >= 400 && code < 500; + } + #endregion } } diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/AlertCommand.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/AlertCommand.cs index 2e8c802..b2d540c 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/AlertCommand.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/AlertCommand.cs @@ -56,7 +56,7 @@ public override string DoImpl() } invokeProv.Invoke(); - return null; + return this.JsonResponse(); } throw new AutomationException("No alert is displayed", ResponseStatus.NoAlertOpenError); diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/CommandBase.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/CommandBase.cs index 3f5ee0d..96fe773 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/CommandBase.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/CommandBase.cs @@ -84,6 +84,14 @@ public virtual string DoImpl() throw new NotImplementedException(); } + /// + /// The JsonResponse with SUCCESS status and NULL value. + /// + public string JsonResponse() + { + return JsonConvert.SerializeObject(new JsonResponse(this.Session, ResponseStatus.Success, null)); + } + public string JsonResponse(ResponseStatus status, object value) { if (status != ResponseStatus.Success && value == null) diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ExecuteCommand.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ExecuteCommand.cs index 88d68ff..a820b57 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ExecuteCommand.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ExecuteCommand.cs @@ -70,7 +70,7 @@ public override string DoImpl() throw new AutomationException(msg, ResponseStatus.JavaScriptError); } - return this.JsonResponse(ResponseStatus.Success, string.Empty); + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/GetElementAttributeCommand.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/GetElementAttributeCommand.cs index d93de50..368fd32 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/GetElementAttributeCommand.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/GetElementAttributeCommand.cs @@ -32,7 +32,7 @@ public override string DoImpl() if (attributeName == null) { - return this.JsonResponse(ResponseStatus.Success, null); + return this.JsonResponse(); } /* GetAttribute command should return: null if no property was found, @@ -47,7 +47,7 @@ public override string DoImpl() } catch (AutomationException) { - return this.JsonResponse(ResponseStatus.Success, null); + return this.JsonResponse(); } } diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ScreenCoordinatesHelper.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/Helpers/ScreenCoordinatesHelper.cs similarity index 97% rename from WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ScreenCoordinatesHelper.cs rename to WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/Helpers/ScreenCoordinatesHelper.cs index 32e9207..2ee195a 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ScreenCoordinatesHelper.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/Helpers/ScreenCoordinatesHelper.cs @@ -1,4 +1,4 @@ -namespace WindowsUniversalAppDriver.InnerServer.Commands +namespace WindowsUniversalAppDriver.InnerServer.Commands.Helpers { using System; using System.Reflection; diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ValueCommand.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ValueCommand.cs index 7b841a2..d32e9db 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ValueCommand.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/Commands/ValueCommand.cs @@ -30,7 +30,7 @@ public override string DoImpl() } TrySetText(textbox, this.KeyString); - return this.JsonResponse(ResponseStatus.Success, null); + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/WindowsUniversalAppDriver.InnerServer.csproj b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/WindowsUniversalAppDriver.InnerServer.csproj index 811a063..39da78d 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/WindowsUniversalAppDriver.InnerServer.csproj +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver.InnerServer/WindowsUniversalAppDriver.InnerServer.csproj @@ -67,7 +67,7 @@ - + diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ClickElementExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ClickElementExecutor.cs index b0a1e7d..69b824e 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ClickElementExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ClickElementExecutor.cs @@ -18,7 +18,7 @@ protected override string DoImpl() this.Automator.EmulatorController.LeftButtonClick(location.Value); - return null; + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/CloseExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/CloseExecutor.cs index caab948..4520570 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/CloseExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/CloseExecutor.cs @@ -8,7 +8,7 @@ protected override string DoImpl() { this.Automator.Deployer.Uninstall(); - return null; + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/CommandExecutorBase.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/CommandExecutorBase.cs index dc95977..bdef2f2 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/CommandExecutorBase.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/CommandExecutorBase.cs @@ -51,7 +51,9 @@ public string Do() } catch (NotImplementedException exception) { - return HttpResponseHelper.ResponseString(HttpStatusCode.NotImplemented, exception.Message); + return HttpResponseHelper.ResponseString( + HttpStatusCode.NotImplemented, + this.JsonResponse(ResponseStatus.UnknownCommand, exception.Message)); } catch (Exception exception) { @@ -70,6 +72,14 @@ protected virtual string DoImpl() throw new InvalidOperationException("DoImpl should never be called in CommandExecutorBase"); } + /// + /// The JsonResponse with SUCCESS status and NULL value. + /// + protected string JsonResponse() + { + return this.JsonResponse(ResponseStatus.Success, null); + } + protected string JsonResponse(ResponseStatus status, object value) { return JsonConvert.SerializeObject(new JsonResponse(this.Automator.Session, status, value)); diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ExecuteScriptExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ExecuteScriptExecutor.cs index 2482b89..539f7ef 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ExecuteScriptExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ExecuteScriptExecutor.cs @@ -43,7 +43,7 @@ protected override string DoImpl() break; } - return null; + return this.JsonResponse(); } internal void ExecuteMobileScript(string command) diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/GetCurrentWindowHandleExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/GetCurrentWindowHandleExecutor.cs index cab9c25..b39d640 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/GetCurrentWindowHandleExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/GetCurrentWindowHandleExecutor.cs @@ -1,5 +1,11 @@ namespace WindowsUniversalAppDriver.CommandExecutors { + #region + + using WindowsUniversalAppDriver.Common; + + #endregion + internal class GetCurrentWindowHandleExecutor : CommandExecutorBase { #region Methods @@ -7,7 +13,7 @@ internal class GetCurrentWindowHandleExecutor : CommandExecutorBase protected override string DoImpl() { // TODO: There is only one window for windows phone app, so it must be OK, or not? - return "current"; + return this.JsonResponse(ResponseStatus.Success, "current"); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/GoBackExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/GoBackExecutor.cs index b212e71..9fb22c0 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/GoBackExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/GoBackExecutor.cs @@ -1,7 +1,11 @@ namespace WindowsUniversalAppDriver.CommandExecutors { + #region + using System.Windows.Forms; + #endregion + internal class GoBackExecutor : CommandExecutorBase { #region Methods @@ -11,7 +15,7 @@ protected override string DoImpl() // F1 is shortcut for "Back" hardware button this.Automator.EmulatorController.TypeKey(Keys.F1); - return null; + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseClickExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseClickExecutor.cs index 4e00cf2..9930c5b 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseClickExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseClickExecutor.cs @@ -8,7 +8,7 @@ protected override string DoImpl() { this.Automator.EmulatorController.LeftButtonClick(); - return null; + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseDownExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseDownExecutor.cs index 2534e68..ea84472 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseDownExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseDownExecutor.cs @@ -8,7 +8,7 @@ protected override string DoImpl() { this.Automator.EmulatorController.LeftButtonDown(); - return null; + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseMoveToExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseMoveToExecutor.cs index a7af78e..c40e4b3 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseMoveToExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseMoveToExecutor.cs @@ -1,11 +1,15 @@ namespace WindowsUniversalAppDriver.CommandExecutors { + #region + using System; using System.Drawing; using System.Globalization; using WindowsUniversalAppDriver.Automator; + #endregion + internal class MouseMoveToExecutor : CommandExecutorBase { #region Methods @@ -30,7 +34,7 @@ protected override string DoImpl() this.Automator.UpdatedOrientationForEmulatorController(); this.Automator.EmulatorController.MoveCursorTo(coordinates); - return null; + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseUpExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseUpExecutor.cs index 8dabd72..34fafdf 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseUpExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/MouseUpExecutor.cs @@ -8,7 +8,7 @@ protected override string DoImpl() { this.Automator.EmulatorController.LeftButtonUp(); - return null; + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/NewSessionExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/NewSessionExecutor.cs index 8a6140d..fefc1ae 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/NewSessionExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/NewSessionExecutor.cs @@ -61,9 +61,7 @@ protected override string DoImpl() // Gives sometime to load visuals (needed only in case of slow emulation) Thread.Sleep(this.Automator.ActualCapabilities.LaunchDelay); - var jsonResponse = this.JsonResponse(ResponseStatus.Success, this.Automator.ActualCapabilities); - - return jsonResponse; + return this.JsonResponse(ResponseStatus.Success, this.Automator.ActualCapabilities); } private EmulatorController CreateEmulatorController(bool withFallback) diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ScreenshotExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ScreenshotExecutor.cs index 87a8c72..9aa4992 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ScreenshotExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/ScreenshotExecutor.cs @@ -1,12 +1,15 @@ namespace WindowsUniversalAppDriver.CommandExecutors { + using WindowsUniversalAppDriver.Common; + internal class ScreenshotExecutor : CommandExecutorBase { #region Methods protected override string DoImpl() { - return this.Automator.EmulatorController.TakeScreenshot(); + var base64Screenshot = this.Automator.EmulatorController.TakeScreenshot(); + return this.JsonResponse(ResponseStatus.Success, base64Screenshot); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/SendKeysToElementExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/SendKeysToElementExecutor.cs index 5f91b14..6ac5458 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/SendKeysToElementExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/SendKeysToElementExecutor.cs @@ -1,9 +1,13 @@ namespace WindowsUniversalAppDriver.CommandExecutors { + #region + using System.Collections.Generic; using System.Linq; using System.Windows.Forms; + #endregion + internal class SendKeysToElementExecutor : CommandExecutorBase { #region Methods @@ -42,7 +46,7 @@ protected override string DoImpl() this.Automator.EmulatorController.TypeKey(magicKey); } - return null; + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchFlickExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchFlickExecutor.cs index ce64cf2..818e87f 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchFlickExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchFlickExecutor.cs @@ -1,5 +1,7 @@ namespace WindowsUniversalAppDriver.CommandExecutors { + #region + using System; using System.Drawing; using System.Globalization; @@ -7,6 +9,8 @@ using WindowsUniversalAppDriver.Automator; using WindowsUniversalAppDriver.EmulatorHelpers; + #endregion + internal class TouchFlickExecutor : CommandExecutorBase { #region Methods @@ -38,7 +42,7 @@ protected override string DoImpl() this.Automator.EmulatorController.PerformGesture(new FlickGesture(startPoint, xSpeed, ySpeed)); } - return null; + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchScrollExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchScrollExecutor.cs index 0f12930..d18d6c6 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchScrollExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchScrollExecutor.cs @@ -1,5 +1,7 @@ namespace WindowsUniversalAppDriver.CommandExecutors { + #region + using System; using System.Drawing; using System.Globalization; @@ -7,6 +9,8 @@ using WindowsUniversalAppDriver.Automator; using WindowsUniversalAppDriver.EmulatorHelpers; + #endregion + internal class TouchScrollExecutor : CommandExecutorBase { #region Methods @@ -30,7 +34,7 @@ protected override string DoImpl() this.Automator.EmulatorController.PerformGesture(new ScrollGesture(startPoint, xOffset, yOffset)); - return null; + return this.JsonResponse(); } #endregion diff --git a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchSingleTapExecutor.cs b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchSingleTapExecutor.cs index c7e933e..8dd015f 100644 --- a/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchSingleTapExecutor.cs +++ b/WindowsUniversalAppDriver/WindowsUniversalAppDriver/CommandExecutors/TouchSingleTapExecutor.cs @@ -1,8 +1,12 @@ namespace WindowsUniversalAppDriver.CommandExecutors { + #region + using WindowsUniversalAppDriver.Automator; using WindowsUniversalAppDriver.EmulatorHelpers; + #endregion + internal class TouchSingleTapExecutor : CommandExecutorBase { #region Methods @@ -14,13 +18,13 @@ protected override string DoImpl() var elementId = Automator.GetValue(this.ExecutedCommand.Parameters, "element"); if (elementId == null) { - return null; + return this.JsonResponse(); } var tapPoint = this.Automator.RequestElementLocation(elementId).GetValueOrDefault(); this.Automator.EmulatorController.PerformGesture(new TapGesture(tapPoint)); - return null; + return this.JsonResponse(); } #endregion