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

Compatibility with Selenium 4 and Appium #368

Open
wants to merge 2 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
9 changes: 8 additions & 1 deletion src/Winium.Desktop.Driver/Automator/Automator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Winium.Desktop.Driver.Automator
{
using System;
#region using

using System.Collections.Generic;
Expand Down Expand Up @@ -63,7 +64,13 @@ public static Automator InstanceForSession(string sessionId)
{
if (sessionId == null)
{
sessionId = "AwesomeSession";
Random random = new Random();
string randomNumber = string.Empty;
for (int i = 0; i < 10; i++)
{
randomNumber += random.Next(0, 10).ToString();
}
sessionId = randomNumber;
}

// TODO: Add actual support for sessions. Temporary return single Automator for any season
Expand Down
12 changes: 6 additions & 6 deletions src/Winium.Desktop.Driver/Automator/Capabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ internal Capabilities()

#region Public Properties

[JsonProperty("app")]
[JsonProperty("winium:app")]
public string App { get; set; }

[JsonProperty("args")]
[JsonProperty("winium:args")]
public string Arguments { get; set; }

[JsonProperty("debugConnectToRunningApp")]
[JsonProperty("winium:debugConnectToRunningApp")]
public bool DebugConnectToRunningApp { get; set; }

[JsonProperty("innerPort")]
[JsonProperty("winium:innerPort")]
public int InnerPort { get; set; }

[JsonProperty("keyboardSimulator")]
[JsonProperty("winium:keyboardSimulator")]
public KeyboardSimulatorType KeyboardSimulator { get; set; }

[JsonProperty("launchDelay")]
[JsonProperty("winium:launchDelay")]
public int LaunchDelay { get; set; }

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Winium.Desktop.Driver.CommandExecutors
{
internal class DoubleClickElementExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
var registeredKey = this.ExecutedCommand.Parameters["ID"].ToString();
this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey).DoubleClick();

return this.JsonResponse();
}

#endregion
}
}
35 changes: 31 additions & 4 deletions src/Winium.Desktop.Driver/CommandExecutors/NewSessionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;

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

using Winium.Cruciatus;
using Winium.Cruciatus.Settings;
Expand All @@ -22,17 +23,22 @@ protected override string DoImpl()
{
// It is easier to reparse desired capabilities as JSON instead of re-mapping keys to attributes and calling type conversions,
// so we will take possible one time performance hit by serializing Dictionary and deserializing it as Capabilities object
var serializedCapability =
JsonConvert.SerializeObject(this.ExecutedCommand.Parameters["desiredCapabilities"]);
this.Automator.ActualCapabilities = Capabilities.CapabilitiesFromJsonString(serializedCapability);
JObject cap =
JObject.Parse(
JsonConvert.SerializeObject(
this.ExecutedCommand.Parameters["capabilities"]));
var alwaysMatch = cap.SelectToken("alwaysMatch");
this.Automator.ActualCapabilities =
Capabilities.CapabilitiesFromJsonString(alwaysMatch.ToString());

this.InitializeApplication(this.Automator.ActualCapabilities.DebugConnectToRunningApp);
this.InitializeKeyboardEmulator(this.Automator.ActualCapabilities.KeyboardSimulator);

// 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);
AutomatorResponse resp = new AutomatorResponse(this.Automator.Session, this.Automator.ActualCapabilities);
return this.JsonResponse(ResponseStatus.Success, resp);
}

private void InitializeApplication(bool debugDoNotDeploy = false)
Expand All @@ -56,4 +62,25 @@ private void InitializeKeyboardEmulator(KeyboardSimulatorType keyboardSimulatorT

#endregion
}

internal class AutomatorResponse
{
#region Constructors and Destructors

public AutomatorResponse(string sessionId, Capabilities capabilities)
{
this.SessionId = sessionId;
this.Capabilities = capabilities;
}
#endregion

#region Public Properties

[JsonProperty("sessionId")]
public string SessionId { get; set; }

[JsonProperty("capabilities")]
public Capabilities Capabilities { get; set; }
#endregion
}
}
3 changes: 3 additions & 0 deletions src/Winium.Desktop.Driver/UriDispatchTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ private void InitializeSeleniumCommandDictionary()
this.commandDictionary.Add(
DriverCommand.ClickElement,
new CommandInfo("POST", "/session/{sessionId}/element/{id}/click"));
this.commandDictionary.Add(
DriverCommand.DoubleClickElement,
new CommandInfo("POST", "/session/{sessionId}/element/{id}/doubleClickElement"));
this.commandDictionary.Add(
DriverCommand.GetElementText,
new CommandInfo("GET", "/session/{sessionId}/element/{id}/text"));
Expand Down
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 @@ -69,6 +69,7 @@
<ItemGroup>
<Compile Include="Automator\Automator.cs" />
<Compile Include="Automator\Capabilities.cs" />
<Compile Include="CommandExecutors\DoubleClickElementExecutor.cs" />
<Compile Include="CommandExecutors\CollapseComboBoxExecutor.cs" />
<Compile Include="CommandExecutors\FindComboBoxSelectedItemExecutor.cs" />
<Compile Include="CommandExecutors\GetOrientationExecutor.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/Winium.Desktop.Driver/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<package id="CommandLineParser" version="1.9.71" targetFramework="net451" userInstalled="true" />
<package id="ILMerge.Tools" version="2.14.1208" />
<package id="InputSimulator" version="1.0.4.0" targetFramework="net451" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" userInstalled="true" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net45" userInstalled="true" />
<package id="NLog" version="3.1.0.0" targetFramework="net451" />
<package id="Selenium.WebDriver" version="2.53.1" targetFramework="net451" />
<package id="Winium.Cruciatus" version="2.10.0" targetFramework="net451" />
Expand Down
6 changes: 6 additions & 0 deletions src/Winium.StoreApps.Common/DriverCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public static class DriverCommand
/// </summary>
public static readonly string ClickElement = "clickElement";

/// <summary>
/// Represents DoubleClickElement command
///
/// </summary>
public static readonly string DoubleClickElement = "doubleClickElement";

/// <summary>
/// Represents a Browser close command
///
Expand Down
2 changes: 1 addition & 1 deletion src/Winium.StoreApps.Common/JsonWireClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public JsonElementContent(string element)

#region Public Properties

[JsonProperty("ELEMENT")]
[JsonProperty("element-6066-11e4-a52e-4f735466cecf")]
public string Element { get; set; }

#endregion
Expand Down