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 driver responses #10

Merged
merged 4 commits into from
Mar 2, 2015
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static Dictionary<HttpStatusCode, string> 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);
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override string DoImpl()
}

invokeProv.Invoke();
return null;
return this.JsonResponse();
}

throw new AutomationException("No alert is displayed", ResponseStatus.NoAlertOpenError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public virtual string DoImpl()
throw new NotImplementedException();
}

/// <summary>
/// The JsonResponse with SUCCESS status and NULL value.
/// </summary>
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -47,7 +47,7 @@ public override string DoImpl()
}
catch (AutomationException)
{
return this.JsonResponse(ResponseStatus.Success, null);
return this.JsonResponse();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace WindowsUniversalAppDriver.InnerServer.Commands
namespace WindowsUniversalAppDriver.InnerServer.Commands.Helpers
{
using System;
using System.Reflection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override string DoImpl()
}

TrySetText(textbox, this.KeyString);
return this.JsonResponse(ResponseStatus.Success, null);
return this.JsonResponse();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<Compile Include="Commands\LocationInViewCommand.cs" />
<Compile Include="Commands\OrientationCommand.cs" />
<Compile Include="Commands\PageSourceCommand.cs" />
<Compile Include="Commands\ScreenCoordinatesHelper.cs" />
<Compile Include="Commands\Helpers\ScreenCoordinatesHelper.cs" />
<Compile Include="Commands\GetElementTagNameCommand.cs" />
<Compile Include="Commands\TextCommand.cs" />
<Compile Include="Commands\ValueCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override string DoImpl()

this.Automator.EmulatorController.LeftButtonClick(location.Value);

return null;
return this.JsonResponse();
Copy link
Contributor

Choose a reason for hiding this comment

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

А почему тут ответ без параметров, а выше всегда с параметрами Success и null?

}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ protected override string DoImpl()
{
this.Automator.Deployer.Uninstall();

return null;
return this.JsonResponse();
Copy link
Contributor

Choose a reason for hiding this comment

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

Аналогично

}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public string Do()
}
catch (NotImplementedException exception)
{
return HttpResponseHelper.ResponseString(HttpStatusCode.NotImplemented, exception.Message);
return HttpResponseHelper.ResponseString(
Copy link
Contributor

Choose a reason for hiding this comment

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

Надо посмотреть как это будет в тестах выглядеть, например, на питоне, т.к. до этого unimplemented там работал

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Traceback одинаков, сообщение пробрасывается одинаково

HttpStatusCode.NotImplemented,
this.JsonResponse(ResponseStatus.UnknownCommand, exception.Message));
}
catch (Exception exception)
{
Expand All @@ -70,6 +72,14 @@ protected virtual string DoImpl()
throw new InvalidOperationException("DoImpl should never be called in CommandExecutorBase");
}

/// <summary>
/// The JsonResponse with SUCCESS status and NULL value.
/// </summary>
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override string DoImpl()
break;
}

return null;
return this.JsonResponse();
}

internal void ExecuteMobileScript(string command)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
namespace WindowsUniversalAppDriver.CommandExecutors
{
#region

using WindowsUniversalAppDriver.Common;

#endregion

internal class GetCurrentWindowHandleExecutor : CommandExecutorBase
{
#region Methods

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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace WindowsUniversalAppDriver.CommandExecutors
{
#region

using System.Windows.Forms;

#endregion

internal class GoBackExecutor : CommandExecutorBase
{
#region Methods
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ protected override string DoImpl()
{
this.Automator.EmulatorController.LeftButtonClick();

return null;
return this.JsonResponse();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ protected override string DoImpl()
{
this.Automator.EmulatorController.LeftButtonDown();

return null;
return this.JsonResponse();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -30,7 +34,7 @@ protected override string DoImpl()
this.Automator.UpdatedOrientationForEmulatorController();
this.Automator.EmulatorController.MoveCursorTo(coordinates);

return null;
return this.JsonResponse();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ protected override string DoImpl()
{
this.Automator.EmulatorController.LeftButtonUp();

return null;
return this.JsonResponse();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Протестировать, что в питоне ничего не сломалось, до этого ведь там как-то все работало

Copy link
Contributor Author

Choose a reason for hiding this comment

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

все ок. питон биндинги работают видимо именно так, как ты и предполагал

}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,7 +46,7 @@ protected override string DoImpl()
this.Automator.EmulatorController.TypeKey(magicKey);
}

return null;
return this.JsonResponse();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
namespace WindowsUniversalAppDriver.CommandExecutors
{
#region

using System;
using System.Drawing;
using System.Globalization;

using WindowsUniversalAppDriver.Automator;
using WindowsUniversalAppDriver.EmulatorHelpers;

#endregion

internal class TouchFlickExecutor : CommandExecutorBase
{
#region Methods
Expand Down Expand Up @@ -38,7 +42,7 @@ protected override string DoImpl()
this.Automator.EmulatorController.PerformGesture(new FlickGesture(startPoint, xSpeed, ySpeed));
}

return null;
return this.JsonResponse();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
namespace WindowsUniversalAppDriver.CommandExecutors
{
#region

using System;
using System.Drawing;
using System.Globalization;

using WindowsUniversalAppDriver.Automator;
using WindowsUniversalAppDriver.EmulatorHelpers;

#endregion

internal class TouchScrollExecutor : CommandExecutorBase
{
#region Methods
Expand All @@ -30,7 +34,7 @@ protected override string DoImpl()

this.Automator.EmulatorController.PerformGesture(new ScrollGesture(startPoint, xOffset, yOffset));

return null;
return this.JsonResponse();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
namespace WindowsUniversalAppDriver.CommandExecutors
{
#region

using WindowsUniversalAppDriver.Automator;
using WindowsUniversalAppDriver.EmulatorHelpers;

#endregion

internal class TouchSingleTapExecutor : CommandExecutorBase
{
#region Methods
Expand All @@ -14,13 +18,13 @@ protected override string DoImpl()
var elementId = Automator.GetValue<string>(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
Expand Down