Skip to content

Commit b1c4b87

Browse files
committed
Updating .NET bindings to allow use with older versions of the IE driver
The bindings will now flatten out the capabilities sent over the wire for non-spec-compliant versions of the IE driver. This will allow users to continue to use legacy versions of the driver until enough are upgraded to a version of the executable that understands the `se:ieOptions` capability.
1 parent 89d6a13 commit b1c4b87

File tree

3 files changed

+77
-15
lines changed

3 files changed

+77
-15
lines changed

dotnet/src/webdriver/IE/InternetExplorerDriver.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// </copyright>
1818

1919
using System;
20+
using System.Collections.Generic;
2021
using OpenQA.Selenium.Remote;
2122

2223
namespace OpenQA.Selenium.IE
@@ -160,6 +161,37 @@ public override IFileDetector FileDetector
160161
set { }
161162
}
162163

164+
/// <summary>
165+
/// Gets the capabilities as a dictionary supporting legacy drivers.
166+
/// </summary>
167+
/// <param name="capabilities">The dictionary to return.</param>
168+
/// <returns>A Dictionary consisting of the capabilities requested.</returns>
169+
/// <remarks>This method is only transitional. Do not rely on it. It will be removed
170+
/// once browser driver capability formats stabilize.</remarks>
171+
protected override Dictionary<string, object> GetLegacyCapabilitiesDictionary(ICapabilities capabilities)
172+
{
173+
// Flatten the dictionary, if required to support old versions of the IE driver.
174+
Dictionary<string, object> capabilitiesDictionary = new Dictionary<string, object>();
175+
DesiredCapabilities capabilitiesObject = capabilities as DesiredCapabilities;
176+
foreach (KeyValuePair<string, object> entry in capabilitiesObject.CapabilitiesDictionary)
177+
{
178+
if (entry.Key == InternetExplorerOptions.Capability)
179+
{
180+
Dictionary<string, object> internetExplorerOptions = entry.Value as Dictionary<string, object>;
181+
foreach (KeyValuePair<string, object> option in internetExplorerOptions)
182+
{
183+
capabilitiesDictionary.Add(option.Key, option.Value);
184+
}
185+
}
186+
else
187+
{
188+
capabilitiesDictionary.Add(entry.Key, entry.Value);
189+
}
190+
}
191+
192+
return capabilitiesDictionary;
193+
}
194+
163195
private static ICapabilities ConvertOptionsToCapabilities(InternetExplorerOptions options)
164196
{
165197
if (options == null)

dotnet/src/webdriver/Remote/DesiredCapabilities.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// limitations under the License.
1717
// </copyright>
1818

19+
using System;
1920
using System.Collections.Generic;
2021
using System.Globalization;
2122

@@ -141,6 +142,7 @@ public string Version
141142
/// <summary>
142143
/// Gets or sets a value indicating whether the browser is JavaScript enabled
143144
/// </summary>
145+
[Obsolete("Capability is not allowed by the W3C specification, and will be removed in a future version of the bindings.")]
144146
public bool IsJavaScriptEnabled
145147
{
146148
get

dotnet/src/webdriver/Remote/RemoteWebDriver.cs

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,23 +1094,10 @@ protected virtual void Dispose(bool disposing)
10941094
/// <param name="desiredCapabilities">Capabilities of the browser</param>
10951095
protected void StartSession(ICapabilities desiredCapabilities)
10961096
{
1097-
DesiredCapabilities capabilitiesObject = desiredCapabilities as DesiredCapabilities;
10981097
Dictionary<string, object> parameters = new Dictionary<string, object>();
1099-
parameters.Add("desiredCapabilities", capabilitiesObject.CapabilitiesDictionary);
1098+
parameters.Add("desiredCapabilities", this.GetLegacyCapabilitiesDictionary(desiredCapabilities));
11001099

1101-
// Must remove "platform" and "version" capabilities, which are not
1102-
// supported by W3C compliant remote ends. Note that this block is
1103-
// temporary and will change soon.
1104-
Dictionary<string, object> firstMatchCapabilities = capabilitiesObject.CapabilitiesDictionary;
1105-
if (firstMatchCapabilities.ContainsKey(CapabilityType.Version))
1106-
{
1107-
firstMatchCapabilities.Remove(CapabilityType.Version);
1108-
}
1109-
1110-
if (firstMatchCapabilities.ContainsKey(CapabilityType.Platform))
1111-
{
1112-
firstMatchCapabilities.Remove(CapabilityType.Platform);
1113-
}
1100+
Dictionary<string, object> firstMatchCapabilities = this.GetCapabilitiesDictionary(desiredCapabilities);
11141101

11151102
List<object> firstMatchCapabilitiesList = new List<object>();
11161103
firstMatchCapabilitiesList.Add(firstMatchCapabilities);
@@ -1127,6 +1114,47 @@ protected void StartSession(ICapabilities desiredCapabilities)
11271114
this.sessionId = new SessionId(response.SessionId);
11281115
}
11291116

1117+
/// <summary>
1118+
/// Gets the capabilities as a dictionary supporting legacy drivers.
1119+
/// </summary>
1120+
/// <param name="capabilities">The dictionary to return.</param>
1121+
/// <returns>A Dictionary consisting of the capabilities requested.</returns>
1122+
/// <remarks>This method is only transitional. Do not rely on it. It will be removed
1123+
/// once browser driver capability formats stabilize.</remarks>
1124+
protected virtual Dictionary<string, object> GetLegacyCapabilitiesDictionary(ICapabilities capabilities)
1125+
{
1126+
Dictionary<string, object> capabilitiesDictionary = new Dictionary<string, object>();
1127+
DesiredCapabilities capabilitiesObject = capabilities as DesiredCapabilities;
1128+
foreach (KeyValuePair<string, object> entry in capabilitiesObject.CapabilitiesDictionary)
1129+
{
1130+
capabilitiesDictionary.Add(entry.Key, entry.Value);
1131+
}
1132+
1133+
return capabilitiesDictionary;
1134+
}
1135+
1136+
/// <summary>
1137+
/// Gets the capabilities as a dictionary.
1138+
/// </summary>
1139+
/// <param name="capabilities">The dictionary to return.</param>
1140+
/// <returns>A Dictionary consisting of the capabilities requested.</returns>
1141+
/// <remarks>This method is only transitional. Do not rely on it. It will be removed
1142+
/// once browser driver capability formats stabilize.</remarks>
1143+
protected virtual Dictionary<string, object> GetCapabilitiesDictionary(ICapabilities capabilities)
1144+
{
1145+
Dictionary<string, object> capabilitiesDictionary = new Dictionary<string, object>();
1146+
DesiredCapabilities capabilitiesObject = capabilities as DesiredCapabilities;
1147+
foreach (KeyValuePair<string, object> entry in capabilitiesObject.CapabilitiesDictionary)
1148+
{
1149+
if (entry.Key != CapabilityType.Version && entry.Key != CapabilityType.Platform)
1150+
{
1151+
capabilitiesDictionary.Add(entry.Key, entry.Value);
1152+
}
1153+
}
1154+
1155+
return capabilitiesDictionary;
1156+
}
1157+
11301158
/// <summary>
11311159
/// Executes a command with this driver .
11321160
/// </summary>

0 commit comments

Comments
 (0)