Skip to content

Commit 70af0d6

Browse files
committed
Refactor .NET bindings class inheritance hierarchy
1 parent fb4d714 commit 70af0d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1556
-1941
lines changed

dotnet/src/support/Events/EventFiringWebDriver.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,12 +1469,41 @@ public string GetAttribute(string attributeName)
14691469
return attribute;
14701470
}
14711471

1472+
/// <summary>
1473+
/// Gets the value of a declared HTML attribute of this element.
1474+
/// </summary>
1475+
/// <param name="attributeName">The name of the HTML attribute to get the value of.</param>
1476+
/// <returns>The HTML attribute's current value. Returns a <see langword="null"/> if the
1477+
/// value is not set or the declared attribute does not exist.</returns>
1478+
/// <remarks>
1479+
/// As opposed to the <see cref="GetAttribute(string)"/> method, this method
1480+
/// only returns attributes declared in the element's HTML markup. To access the value
1481+
/// of an IDL property of the element, either use the <see cref="GetAttribute(string)"/>
1482+
/// method or the <see cref="GetDomProperty(string)"/> method.
1483+
/// </remarks>
1484+
public string GetDomAttribute(string attributeName)
1485+
{
1486+
string attribute = string.Empty;
1487+
try
1488+
{
1489+
attribute = this.underlyingElement.GetDomAttribute(attributeName);
1490+
}
1491+
catch (Exception ex)
1492+
{
1493+
this.parentDriver.OnException(new WebDriverExceptionEventArgs(this.parentDriver, ex));
1494+
throw;
1495+
}
1496+
1497+
return attribute;
1498+
}
1499+
14721500
/// <summary>
14731501
/// Gets the value of a JavaScript property of this element.
14741502
/// </summary>
14751503
/// <param name="propertyName">The name JavaScript the JavaScript property to get the value of.</param>
14761504
/// <returns>The JavaScript property's current value. Returns a <see langword="null"/> if the
14771505
/// value is not set or the property does not exist.</returns>
1506+
[Obsolete("Use the GetDomProperty method instead.")]
14781507
public string GetProperty(string propertyName)
14791508
{
14801509
string elementProperty = string.Empty;
@@ -1491,6 +1520,28 @@ public string GetProperty(string propertyName)
14911520
return elementProperty;
14921521
}
14931522

1523+
/// <summary>
1524+
/// Gets the value of a JavaScript property of this element.
1525+
/// </summary>
1526+
/// <param name="propertyName">The name JavaScript the JavaScript property to get the value of.</param>
1527+
/// <returns>The JavaScript property's current value. Returns a <see langword="null"/> if the
1528+
/// value is not set or the property does not exist.</returns>
1529+
public string GetDomProperty(string propertyName)
1530+
{
1531+
string elementProperty = string.Empty;
1532+
try
1533+
{
1534+
elementProperty = this.underlyingElement.GetDomProperty(propertyName);
1535+
}
1536+
catch (Exception ex)
1537+
{
1538+
this.parentDriver.OnException(new WebDriverExceptionEventArgs(this.parentDriver, ex));
1539+
throw;
1540+
}
1541+
1542+
return elementProperty;
1543+
}
1544+
14941545
/// <summary>
14951546
/// Method to return the value of a CSS Property
14961547
/// </summary>

dotnet/src/webdriver/Remote/RemoteAlert.cs renamed to dotnet/src/webdriver/Alert.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="RemoteAlert.cs" company="WebDriver Committers">
1+
// <copyright file="Alert.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -19,20 +19,20 @@
1919
using System;
2020
using System.Collections.Generic;
2121

22-
namespace OpenQA.Selenium.Remote
22+
namespace OpenQA.Selenium
2323
{
2424
/// <summary>
2525
/// Defines the interface through which the user can manipulate JavaScript alerts.
2626
/// </summary>
27-
internal class RemoteAlert : IAlert
27+
internal class Alert : IAlert
2828
{
29-
private RemoteWebDriver driver;
29+
private WebDriver driver;
3030

3131
/// <summary>
32-
/// Initializes a new instance of the <see cref="RemoteAlert"/> class.
32+
/// Initializes a new instance of the <see cref="Alert"/> class.
3333
/// </summary>
34-
/// <param name="driver">The <see cref="RemoteWebDriver"/> for which the alerts will be managed.</param>
35-
public RemoteAlert(RemoteWebDriver driver)
34+
/// <param name="driver">The <see cref="WebDriver"/> for which the alerts will be managed.</param>
35+
public Alert(WebDriver driver)
3636
{
3737
this.driver = driver;
3838
}

dotnet/src/webdriver/Remote/CapabilityType.cs renamed to dotnet/src/webdriver/CapabilityType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
using System.Collections.Generic;
2020

21-
namespace OpenQA.Selenium.Remote
21+
namespace OpenQA.Selenium
2222
{
2323
/// <summary>
2424
/// Provides types of capabilities for the DesiredCapabilities object.

dotnet/src/webdriver/Chrome/ChromeWebElement.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

dotnet/src/webdriver/Chromium/ChromiumDriver.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace OpenQA.Selenium.Chromium
3131
/// <summary>
3232
/// Provides an abstract way to access Chromium-based browsers to run tests.
3333
/// </summary>
34-
public abstract class ChromiumDriver : RemoteWebDriver, ISupportsLogs, IDevTools
34+
public abstract class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools
3535
{
3636
/// <summary>
3737
/// Accept untrusted SSL Certificates
@@ -70,11 +70,11 @@ public ChromiumDriver(ChromiumDriverService service, ChromiumOptions options, Ti
7070
this.optionsCapabilityName = options.CapabilityName;
7171

7272
// Add the custom commands unique to Chrome
73-
this.AddCustomChromeCommand(GetNetworkConditionsCommand, CommandInfo.GetCommand, "/session/{sessionId}/chromium/network_conditions");
74-
this.AddCustomChromeCommand(SetNetworkConditionsCommand, CommandInfo.PostCommand, "/session/{sessionId}/chromium/network_conditions");
75-
this.AddCustomChromeCommand(DeleteNetworkConditionsCommand, CommandInfo.DeleteCommand, "/session/{sessionId}/chromium/network_conditions");
76-
this.AddCustomChromeCommand(SendChromeCommand, CommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command");
77-
this.AddCustomChromeCommand(SendChromeCommandWithResult, CommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command_and_get_result");
73+
this.AddCustomChromeCommand(GetNetworkConditionsCommand, HttpCommandInfo.GetCommand, "/session/{sessionId}/chromium/network_conditions");
74+
this.AddCustomChromeCommand(SetNetworkConditionsCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/chromium/network_conditions");
75+
this.AddCustomChromeCommand(DeleteNetworkConditionsCommand, HttpCommandInfo.DeleteCommand, "/session/{sessionId}/chromium/network_conditions");
76+
this.AddCustomChromeCommand(SendChromeCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command");
77+
this.AddCustomChromeCommand(SendChromeCommandWithResult, HttpCommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command_and_get_result");
7878
}
7979

8080
/// <summary>
@@ -241,8 +241,8 @@ private static ICapabilities ConvertOptionsToCapabilities(ChromiumOptions option
241241

242242
private void AddCustomChromeCommand(string commandName, string method, string resourcePath)
243243
{
244-
CommandInfo commandInfoToAdd = new CommandInfo(method, resourcePath);
245-
this.CommandExecutor.CommandInfoRepository.TryAddCommand(commandName, commandInfoToAdd);
244+
HttpCommandInfo commandInfoToAdd = new HttpCommandInfo(method, resourcePath);
245+
this.CommandExecutor.TryAddCommand(commandName, commandInfoToAdd);
246246
}
247247
}
248248
}

dotnet/src/webdriver/Chromium/ChromiumWebElement.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

dotnet/src/webdriver/Remote/Command.cs renamed to dotnet/src/webdriver/Command.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="Command.cs" company="WebDriver Committers">
1+
// <copyright file="Command.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -17,9 +17,11 @@
1717
// </copyright>
1818

1919
using System.Collections.Generic;
20+
using System.Collections.ObjectModel;
2021
using Newtonsoft.Json;
22+
using OpenQA.Selenium.Internal;
2123

22-
namespace OpenQA.Selenium.Remote
24+
namespace OpenQA.Selenium
2325
{
2426
/// <summary>
2527
/// Provides a way to send commands to the remote server
@@ -112,7 +114,7 @@ public string ParametersAsJsonString
112114
/// <returns>A string representation of the Command Object</returns>
113115
public override string ToString()
114116
{
115-
return string.Concat("[", this.SessionId, "]: ", this.Name, " ", this.Parameters.ToString());
117+
return string.Concat("[", this.SessionId, "]: ", this.Name, " ", this.ParametersAsJsonString);
116118
}
117119

118120
/// <summary>
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="EdgeWebElement.cs" company="WebDriver Committers">
1+
// <copyright file="CommandInfo.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -16,23 +16,22 @@
1616
// limitations under the License.
1717
// </copyright>
1818

19-
using OpenQA.Selenium.Chromium;
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Linq;
22+
using System.Text;
23+
using System.Threading.Tasks;
2024

21-
namespace OpenQA.Selenium.Edge
25+
namespace OpenQA.Selenium
2226
{
2327
/// <summary>
24-
/// Provides a mechanism to get elements off the page for test
28+
/// Represents the information about a command.
2529
/// </summary>
26-
public class EdgeWebElement : ChromiumWebElement
30+
public abstract class CommandInfo
2731
{
2832
/// <summary>
29-
/// Initializes a new instance of the <see cref="EdgeWebElement"/> class
33+
/// Gets the unique identifier for this command within the scope of its protocol definition
3034
/// </summary>
31-
/// <param name="parent">Driver in use</param>
32-
/// <param name="elementId">Id of the element</param>
33-
public EdgeWebElement(EdgeDriver parent, string elementId)
34-
: base(parent, elementId)
35-
{
36-
}
35+
public abstract string CommandIdentifier { get; }
3736
}
3837
}

dotnet/src/webdriver/Remote/CommandInfoRepository.cs renamed to dotnet/src/webdriver/CommandInfoRepository.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="CommandInfoRepository.cs" company="WebDriver Committers">
1+
// <copyright file="CommandInfoRepository.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -18,8 +18,9 @@
1818

1919
using System;
2020
using System.Collections.Generic;
21+
using System.Globalization;
2122

22-
namespace OpenQA.Selenium.Remote
23+
namespace OpenQA.Selenium
2324
{
2425
/// <summary>
2526
/// Holds the information about all commands specified by the JSON wire protocol.
@@ -45,16 +46,21 @@ protected CommandInfoRepository()
4546
public abstract int SpecificationLevel { get; }
4647

4748
/// <summary>
48-
/// Gets the <see cref="CommandInfo"/> for a <see cref="DriverCommand"/>.
49+
/// Gets the <see cref="Type"/> that is valid for this <see cref="CommandInfoRepository"/>
50+
/// </summary>
51+
protected abstract Type RepositoryCommandInfoType { get; }
52+
53+
/// <summary>
54+
/// Gets the <see cref="HttpCommandInfo"/> for a <see cref="DriverCommand"/>.
4955
/// </summary>
5056
/// <param name="commandName">The <see cref="DriverCommand"/> for which to get the information.</param>
51-
/// <returns>The <see cref="CommandInfo"/> for the specified command.</returns>
52-
public CommandInfo GetCommandInfo(string commandName)
57+
/// <returns>The <see cref="HttpCommandInfo"/> for the specified command.</returns>
58+
public T GetCommandInfo<T>(string commandName) where T : CommandInfo
5359
{
54-
CommandInfo toReturn = null;
60+
T toReturn = default(T);
5561
if (this.commandDictionary.ContainsKey(commandName))
5662
{
57-
toReturn = this.commandDictionary[commandName];
63+
toReturn = this.commandDictionary[commandName] as T;
5864
}
5965

6066
return toReturn;
@@ -71,7 +77,7 @@ public CommandInfo GetCommandInfo(string commandName)
7177
/// This method will not overwrite existing commands for a specific name, and will return <see langword="false"/>
7278
/// in that case.
7379
/// </remarks>
74-
public bool TryAddCommand(string commandName, CommandInfo commandInfo)
80+
public bool TryAddCommand<T>(string commandName, T commandInfo) where T : CommandInfo
7581
{
7682
if (string.IsNullOrEmpty(commandName))
7783
{
@@ -83,6 +89,12 @@ public bool TryAddCommand(string commandName, CommandInfo commandInfo)
8389
throw new ArgumentNullException("commandInfo", "The command information object cannot be null.");
8490
}
8591

92+
if (!typeof(T).IsAssignableFrom(this.RepositoryCommandInfoType))
93+
{
94+
string message = string.Format(CultureInfo.InvariantCulture, "{0} is not a valid command type for this repository; command info must be of type {1}", typeof(T), this.RepositoryCommandInfoType);
95+
throw new ArgumentException(message, "commandInfo");
96+
}
97+
8698
if (this.commandDictionary.ContainsKey(commandName))
8799
{
88100
return false;

dotnet/src/webdriver/Remote/RemoteCookieJar.cs renamed to dotnet/src/webdriver/CookieJar.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="RemoteCookieJar.cs" company="WebDriver Committers">
1+
// <copyright file="CookieJar.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -20,20 +20,20 @@
2020
using System.Collections.Generic;
2121
using System.Collections.ObjectModel;
2222

23-
namespace OpenQA.Selenium.Remote
23+
namespace OpenQA.Selenium
2424
{
2525
/// <summary>
2626
/// Defines an interface allowing the user to manipulate cookies on the current page.
2727
/// </summary>
28-
internal class RemoteCookieJar : ICookieJar
28+
internal class CookieJar : ICookieJar
2929
{
30-
private RemoteWebDriver driver;
30+
private WebDriver driver;
3131

3232
/// <summary>
33-
/// Initializes a new instance of the <see cref="RemoteCookieJar"/> class.
33+
/// Initializes a new instance of the <see cref="CookieJar"/> class.
3434
/// </summary>
3535
/// <param name="driver">The driver that is currently in use</param>
36-
public RemoteCookieJar(RemoteWebDriver driver)
36+
public CookieJar(WebDriver driver)
3737
{
3838
this.driver = driver;
3939
}

0 commit comments

Comments
 (0)