Skip to content

Commit

Permalink
Exposing new Interactions framework for .NET
Browse files Browse the repository at this point in the history
This commit exposes the new Interactions framework for creating advanced
user interaction sequences in the .NET bindings. This framework is only
designed to be used with remote ends that understand the W3C WebDriver
Specification actions end point. Most users will continue to use the
`Actions` class for now, which works with both protocol dialects. Once
most remote ends use the W3C dialect of the wire protocol, these classes
will become more useful.
  • Loading branch information
jimevans committed Apr 14, 2017
1 parent d807353 commit b074f20
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Interactions/ActionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace OpenQA.Selenium.Interactions
/// Provides methods that allow the creation of action sequences to enable
/// advanced user interactions.
/// </summary>
internal class ActionBuilder
public class ActionBuilder
{
private Dictionary<InputDevice, ActionSequence> sequences = new Dictionary<InputDevice, ActionSequence>();

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Interactions/ActionSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace OpenQA.Selenium.Interactions
/// <summary>
/// Represents a sequence of actions to be performed in the target browser.
/// </summary>
internal class ActionSequence
public class ActionSequence
{
private List<Interaction> interactions = new List<Interaction>();
private InputDevice device;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Interactions/InputDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace OpenQA.Selenium.Interactions
/// <summary>
/// Base class for all input devices for actions.
/// </summary>
internal abstract class InputDevice
public abstract class InputDevice
{
private string deviceName;

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Interactions/InputDeviceKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OpenQA.Selenium.Interactions
/// <summary>
/// Enumerated values for the kinds of devices available.
/// </summary>
internal enum InputDeviceKind
public enum InputDeviceKind
{
/// <summary>
/// Represents the null device.
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Interactions/Interaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace OpenQA.Selenium.Interactions
/// <summary>
/// Represents a single interaction for a given input device.
/// </summary>
internal abstract class Interaction
public abstract class Interaction
{
private InputDevice sourceDevice;

Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/Internal/IActionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace OpenQA.Selenium.Internal
/// <summary>
/// Interface allowing execution of W3C Specification-compliant actions.
/// </summary>
internal interface IActionExecutor
public interface IActionExecutor
{
/// <summary>
/// Gets a value indicating whether this object is a valid action executor.
Expand All @@ -38,7 +38,7 @@ internal interface IActionExecutor
/// Performs the specified list of actions with this action executor.
/// </summary>
/// <param name="actionSequenceList">The list of action sequences to perform.</param>
void PerformActions(List<ActionSequence> actionSequenceList);
void PerformActions(IList<ActionSequence> actionSequenceList);

/// <summary>
/// Resets the input state of the action executor.
Expand Down
39 changes: 27 additions & 12 deletions dotnet/src/webdriver/Remote/RemoteWebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class RemoteWebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor,
/// </summary>
protected static readonly TimeSpan DefaultCommandTimeout = TimeSpan.FromSeconds(60);

private static readonly string DefaultRemoteServerUrl = "http://127.0.0.1:4444/wd/hub";
private const string DefaultRemoteServerUrl = "http://127.0.0.1:4444/wd/hub";

private ICommandExecutor executor;
private ICapabilities capabilities;
Expand All @@ -85,7 +85,7 @@ public class RemoteWebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor,
/// </summary>
/// <param name="options">An <see cref="DriverOptions"/> object containing the desired capabilities of the browser.</param>
public RemoteWebDriver(DriverOptions options)
: this(options.ToCapabilities())
: this(ConvertOptionsToCapabilities(options))
{
}

Expand All @@ -104,7 +104,7 @@ public RemoteWebDriver(ICapabilities desiredCapabilities)
/// <param name="remoteAddress">URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).</param>
/// <param name="options">An <see cref="DriverOptions"/> object containing the desired capabilities of the browser.</param>
public RemoteWebDriver(Uri remoteAddress, DriverOptions options)
: this(remoteAddress, options.ToCapabilities())
: this(remoteAddress, ConvertOptionsToCapabilities(options))
{
}

Expand Down Expand Up @@ -415,7 +415,7 @@ public SessionId SessionId
/// <summary>
/// Gets a value indicating whether this object is a valid action executor.
/// </summary>
bool IActionExecutor.IsActionExecutor
public bool IsActionExecutor
{
get { return this.IsSpecificationCompliant; }
}
Expand Down Expand Up @@ -940,8 +940,13 @@ public void Dispose()
/// Performs the specified list of actions with this action executor.
/// </summary>
/// <param name="actionSequenceList">The list of action sequences to perform.</param>
void IActionExecutor.PerformActions(List<ActionSequence> actionSequenceList)
public void PerformActions(IList<ActionSequence> actionSequenceList)
{
if (actionSequenceList == null)
{
throw new ArgumentNullException("actionSequenceList", "List of action sequences must not be null");
}

if (this.IsSpecificationCompliant)
{
List<object> objectList = new List<object>();
Expand All @@ -959,7 +964,7 @@ void IActionExecutor.PerformActions(List<ActionSequence> actionSequenceList)
/// <summary>
/// Resets the input state of the action executor.
/// </summary>
void IActionExecutor.ResetInputState()
public void ResetInputState()
{
if (this.IsSpecificationCompliant)
{
Expand Down Expand Up @@ -1117,14 +1122,14 @@ protected void StartSession(ICapabilities desiredCapabilities)
/// <summary>
/// Gets the capabilities as a dictionary supporting legacy drivers.
/// </summary>
/// <param name="capabilities">The dictionary to return.</param>
/// <param name="legacyCapabilities">The dictionary to return.</param>
/// <returns>A Dictionary consisting of the capabilities requested.</returns>
/// <remarks>This method is only transitional. Do not rely on it. It will be removed
/// once browser driver capability formats stabilize.</remarks>
protected virtual Dictionary<string, object> GetLegacyCapabilitiesDictionary(ICapabilities capabilities)
protected virtual Dictionary<string, object> GetLegacyCapabilitiesDictionary(ICapabilities legacyCapabilities)
{
Dictionary<string, object> capabilitiesDictionary = new Dictionary<string, object>();
DesiredCapabilities capabilitiesObject = capabilities as DesiredCapabilities;
DesiredCapabilities capabilitiesObject = legacyCapabilities as DesiredCapabilities;
foreach (KeyValuePair<string, object> entry in capabilitiesObject.CapabilitiesDictionary)
{
capabilitiesDictionary.Add(entry.Key, entry.Value);
Expand All @@ -1136,14 +1141,14 @@ protected virtual Dictionary<string, object> GetLegacyCapabilitiesDictionary(ICa
/// <summary>
/// Gets the capabilities as a dictionary.
/// </summary>
/// <param name="capabilities">The dictionary to return.</param>
/// <param name="capabilitiesToConvert">The dictionary to return.</param>
/// <returns>A Dictionary consisting of the capabilities requested.</returns>
/// <remarks>This method is only transitional. Do not rely on it. It will be removed
/// once browser driver capability formats stabilize.</remarks>
protected virtual Dictionary<string, object> GetCapabilitiesDictionary(ICapabilities capabilities)
protected virtual Dictionary<string, object> GetCapabilitiesDictionary(ICapabilities capabilitiesToConvert)
{
Dictionary<string, object> capabilitiesDictionary = new Dictionary<string, object>();
DesiredCapabilities capabilitiesObject = capabilities as DesiredCapabilities;
DesiredCapabilities capabilitiesObject = capabilitiesToConvert as DesiredCapabilities;
foreach (KeyValuePair<string, object> entry in capabilitiesObject.CapabilitiesDictionary)
{
if (entry.Key != CapabilityType.Version && entry.Key != CapabilityType.Platform)
Expand Down Expand Up @@ -1438,6 +1443,16 @@ private static void UnpackAndThrowOnError(Response errorResponse)
}
}

private static ICapabilities ConvertOptionsToCapabilities(DriverOptions options)
{
if (options == null)
{
throw new ArgumentNullException("options", "Driver options must not be null");
}

return options.ToCapabilities();
}

private object ParseJavaScriptReturnValue(object responseValue)
{
object returnValue = null;
Expand Down

0 comments on commit b074f20

Please sign in to comment.