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

Stop using OpenQA WebDriver nuget-package #12

Merged
merged 4 commits into from
Mar 4, 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
@@ -0,0 +1,80 @@
namespace WindowsUniversalAppDriver.Common
{
#region

using System.Collections.Generic;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

#endregion

public class Command
{
#region Fields

private IDictionary<string, JToken> commandParameters = new JObject();

#endregion

#region Constructors and Destructors

public Command(string name, IDictionary<string, JToken> parameters)
{
this.Name = name;
if (parameters != null)
{
this.Parameters = parameters;
}
}

public Command(string name, string jsonParameters)
: this(name, string.IsNullOrEmpty(jsonParameters) ? null : JObject.Parse(jsonParameters))
{
}

public Command(string name)
{
this.Name = name;
}

public Command()
{
}

#endregion

#region Public Properties

/// <summary>
/// Gets the command name
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// Gets the parameters of the command
/// </summary>
[JsonProperty("parameters")]
public IDictionary<string, JToken> Parameters
{
get
{
return this.commandParameters;
}

set
{
this.commandParameters = value;
}
}

/// <summary>
/// Gets the SessionID of the command
/// </summary>
[JsonProperty("sessionId")]
public string SessionId { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace WindowsUniversalAppDriver.Common
{
public class CommandInfo
{
#region Constants

public const string DeleteCommand = "DELETE";

public const string GetCommand = "GET";

public const string PostCommand = "POST";

#endregion

#region Constructors and Destructors

public CommandInfo(string method, string resourcePath)
{
this.ResourcePath = resourcePath;
this.Method = method;
}

#endregion

#region Public Properties

public string Method { get; set; }

public string ResourcePath { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace WindowsUniversalAppDriver.Common
{
#region

using System.Net;

#endregion

public class CommandResponse
{
public HttpStatusCode HttpStatusCode { get; set; }

public string Content { get; set; }

public static CommandResponse Create(HttpStatusCode code, string content)
{
return new CommandResponse { HttpStatusCode = code, Content = content };
}

public override string ToString()
{
return string.Format("{0}: {1}", this.HttpStatusCode, Content);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ public static class DriverCommand
/// </summary>
public static readonly string SwitchToFrame = "switchToFrame";

/// <summary>
/// Represents SwitchToParentFrame command
///
/// </summary>
public static readonly string SwitchToParentFrame = "switchToParentFrame";

/// <summary>
/// Represents SwitchToWindow command
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,4 @@ public JsonResponse(string sessionId, ResponseStatus responseCode, object value)

#endregion
}

public class JsonCommand
{
#region Public Properties

/// <summary>
/// Gets the command name
///
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// Gets the parameters of the command
///
/// </summary>
[JsonProperty("parameters")]
public Dictionary<string, object> Parameters { get; set; }

/// <summary>
/// Gets the SessionID of the command
///
/// </summary>
[JsonProperty("sessionId")]
public string SessionId { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Command.cs" />
<Compile Include="CommandInfo.cs" />
<Compile Include="CommandResponse.cs" />
<Compile Include="DriverCommand.cs" />
<Compile Include="Exceptions\AutomationException.cs" />
<Compile Include="Exceptions\InnerDriverRequestException.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Automator(UIElement visualRoot)

public string ProcessCommand(string content)
{
var requestData = JsonConvert.DeserializeObject<JsonCommand>(content);
var requestData = JsonConvert.DeserializeObject<Command>(content);
var command = requestData.Name;
var parameters = requestData.Parameters;

Expand All @@ -50,7 +50,7 @@ public string ProcessCommand(string content)
throw new NullReferenceException("Parameters can not be NULL");
}

object elementIdObject;
JToken elementIdObject;
if (parameters.TryGetValue("ID", out elementIdObject))
{
elementId = elementIdObject.ToString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
namespace WindowsUniversalAppDriver.InnerServer.Commands
{
#region

using System;
using System.Collections.Generic;
using System.Threading;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using Windows.UI.Core;
using Windows.UI.Xaml;

using Newtonsoft.Json;

using WindowsUniversalAppDriver.Common;
using WindowsUniversalAppDriver.Common.Exceptions;
using WindowsUniversalAppDriver.InnerServer;

#endregion

internal class CommandBase
{
#region Public Properties

public Automator Automator { get; set; }

public Dictionary<string, object> Parameters { get; set; }
public IDictionary<string, JToken> Parameters { get; set; }

public string Session { get; set; }

Expand All @@ -33,7 +37,7 @@ public static void BeginInvokeSync(UIElement root, Action action)
var waitEvent = new AutoResetEvent(false);

root.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
CoreDispatcherPriority.Normal,
() =>
{
try
Expand Down Expand Up @@ -65,7 +69,7 @@ public string Do()
var response = string.Empty;
try
{
BeginInvokeSync(Automator.VisualRoot, () => { response = this.DoImpl(); });
BeginInvokeSync(this.Automator.VisualRoot, () => { response = this.DoImpl(); });
}
catch (AutomationException exception)
{
Expand All @@ -87,6 +91,9 @@ public virtual string DoImpl()
/// <summary>
/// The JsonResponse with SUCCESS status and NULL value.
/// </summary>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
public string JsonResponse()
{
return JsonConvert.SerializeObject(new JsonResponse(this.Session, ResponseStatus.Success, null));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
namespace WindowsUniversalAppDriver.InnerServer.Commands
{
#region

using System;
using System.Reflection;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using WindowsUniversalAppDriver.Common;
using WindowsUniversalAppDriver.Common.Exceptions;
using WindowsUniversalAppDriver.InnerServer.Commands.Helpers;

#endregion

internal class GetElementAttributeCommand : CommandBase
{
#region Public Properties
Expand All @@ -23,7 +28,7 @@ public override string DoImpl()
{
var element = this.Automator.WebElements.GetRegisteredElement(this.ElementId);

object value;
JToken value;
string attributeName = null;
if (this.Parameters.TryGetValue("NAME", out value))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
namespace WindowsUniversalAppDriver.Automator
{
#region

using System;
using System.Collections.Generic;
using System.Drawing;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using OpenQA.Selenium.Remote;

using WindowsUniversalAppDriver.Common;
using WindowsUniversalAppDriver.EmulatorHelpers;

using DriverCommand = WindowsUniversalAppDriver.Common.DriverCommand;
#endregion

internal class Automator
{
Expand Down Expand Up @@ -66,12 +66,22 @@ public EmulatorController EmulatorController

#region Public Methods and Operators

public static T GetValue<T>(IReadOnlyDictionary<string, object> parameters, string key) where T : class
public static T GetValue<T>(IDictionary<string, JToken> parameters, string key) where T : class
{
object valueObject;
parameters.TryGetValue(key, out valueObject);
JToken valueObject;
if (!parameters.TryGetValue(key, out valueObject))
{
return null;
}

return valueObject as T;
try
{
return valueObject.ToObject<T>();
}
catch (Exception)
{
return null;
}
}

public static Automator InstanceForSession(string sessionId)
Expand All @@ -96,9 +106,11 @@ public static Automator InstanceForSession(string sessionId)
return instance;
}

public Point? RequestElementLocation(string element)
public Point? RequestElementLocation(JToken element)
{
var command = new Command(null, DriverCommand.GetElementLocationOnceScrolledIntoView, new Dictionary<string, object> { { "ID", element } });
var command = new Command(
DriverCommand.GetElementLocationOnceScrolledIntoView,
new Dictionary<string, JToken> { { "ID", element } });

var responseBody = this.CommandForwarder.ForwardCommand(command);

Expand Down Expand Up @@ -133,7 +145,7 @@ public static Automator InstanceForSession(string sessionId)
/// </summary>
public void UpdatedOrientationForEmulatorController()
{
var command = new Command(null, DriverCommand.GetOrientation, null);
var command = new Command(DriverCommand.GetOrientation);
var responseBody = this.CommandForwarder.ForwardCommand(command);
var deserializeObject = JsonConvert.DeserializeObject<JsonResponse>(responseBody);
if (deserializeObject.Status != ResponseStatus.Success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal class ClickElementExecutor : CommandExecutorBase

protected override string DoImpl()
{
var location = this.Automator.RequestElementLocation(this.ExecutedCommand.Parameters["ID"] as string);
var location = this.Automator.RequestElementLocation(this.ExecutedCommand.Parameters["ID"]);

if (!location.HasValue)
{
Expand Down
Loading