Skip to content

Commit

Permalink
Revert .NET bindings to send spec-compliant new session for all browsers
Browse files Browse the repository at this point in the history
Now that the Java remote server will correctly handle spec-compliant new
session payload, even for browsers that are not yet spec-compliant, we can
revert to the original behavior of sending both "capabilities" and
"desiredCapabilities" properties with new session requests.

Reverts commit 4ce57f6.
  • Loading branch information
jimevans committed Apr 2, 2018
1 parent 6f0ea54 commit 03d8714
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 72 deletions.
6 changes: 0 additions & 6 deletions dotnet/src/webdriver/DriverOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,6 @@ protected Dictionary<string, object> GenerateLoggingPreferencesDictionary()
protected DesiredCapabilities GenerateDesiredCapabilities(bool isSpecificationCompliant)
{
DesiredCapabilities capabilities = new DesiredCapabilities();
ISpecificationCompliant specificationCompliantCapabilities = capabilities as ISpecificationCompliant;
if (specificationCompliantCapabilities != null)
{
specificationCompliantCapabilities.IsSpecificationCompliant = isSpecificationCompliant;
}

if (!string.IsNullOrEmpty(this.browserName))
{
capabilities.SetCapability(CapabilityType.BrowserName, this.browserName);
Expand Down
12 changes: 12 additions & 0 deletions dotnet/src/webdriver/Remote/CapabilityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,25 @@ public static class CapabilityType
/// </summary>
public static readonly string SupportsWebStorage = "webStorageEnabled";

/// <summary>
/// Capability name used to indicate whether the driver supports setting the browser window's size and position.
/// </summary>
public static readonly string SetWindowRect = "setWindowRect";

/// <summary>
/// Capability name used to get or set timeout values when creating a session.
/// </summary>
public static readonly string Timeouts = "timeouts";

private static readonly List<string> KnownSpecCompliantCapabilityNames = new List<string>() {
BrowserName,
BrowserVersion,
PlatformName,
AcceptInsecureCertificates,
PageLoadStrategy,
Proxy,
SetWindowRect,
Timeouts,
UnhandledPromptBehavior
};

Expand Down
20 changes: 1 addition & 19 deletions dotnet/src/webdriver/Remote/DesiredCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ namespace OpenQA.Selenium.Remote
/// Class to Create the capabilities of the browser you require for <see cref="IWebDriver"/>.
/// If you wish to use default values use the static methods
/// </summary>
public class DesiredCapabilities : ICapabilities, ISpecificationCompliant
public class DesiredCapabilities : ICapabilities
{
private readonly Dictionary<string, object> capabilities = new Dictionary<string, object>();
private bool isSpecCompliant;

/// <summary>
/// Initializes a new instance of the <see cref="DesiredCapabilities"/> class
Expand Down Expand Up @@ -101,7 +100,6 @@ internal DesiredCapabilities(string browser, string version, Platform platform,
this.SetCapability(CapabilityType.BrowserName, browser);
this.SetCapability(CapabilityType.Version, version);
this.SetCapability(CapabilityType.Platform, platform);
this.isSpecCompliant = isSpecCompliant;
}

/// <summary>
Expand Down Expand Up @@ -179,15 +177,6 @@ public bool AcceptInsecureCerts
}
}

/// <summary>
/// Gets or sets a value indicating whether this set of capabilities is compliant with the W3C WebDriver specification.
/// </summary>
bool ISpecificationCompliant.IsSpecificationCompliant
{
get { return this.isSpecCompliant; }
set { this.isSpecCompliant = value; }
}

/// <summary>
/// Gets the internal capabilities dictionary.
/// </summary>
Expand Down Expand Up @@ -215,7 +204,6 @@ public static DesiredCapabilities Firefox()
public static DesiredCapabilities PhantomJS()
{
DesiredCapabilities dc = new DesiredCapabilities("phantomjs", string.Empty, new Platform(PlatformType.Any));
dc.isSpecCompliant = false;
return dc;
}

Expand All @@ -237,7 +225,6 @@ public static DesiredCapabilities InternetExplorer()
public static DesiredCapabilities Edge()
{
DesiredCapabilities dc = new DesiredCapabilities("MicrosoftEdge", string.Empty, new Platform(PlatformType.Windows));
dc.isSpecCompliant = false;
return dc;
}

Expand All @@ -248,7 +235,6 @@ public static DesiredCapabilities Edge()
public static DesiredCapabilities HtmlUnit()
{
DesiredCapabilities dc = new DesiredCapabilities("htmlunit", string.Empty, new Platform(PlatformType.Any));
dc.isSpecCompliant = false;
return dc;
}

Expand All @@ -260,7 +246,6 @@ public static DesiredCapabilities HtmlUnitWithJavaScript()
{
DesiredCapabilities dc = new DesiredCapabilities("htmlunit", string.Empty, new Platform(PlatformType.Any));
dc.SetCapability(CapabilityType.IsJavaScriptEnabled, true);
dc.isSpecCompliant = false;
return dc;
}

Expand Down Expand Up @@ -293,7 +278,6 @@ public static DesiredCapabilities Chrome()
{
// This is strangely inconsistent.
DesiredCapabilities dc = new DesiredCapabilities("chrome", string.Empty, new Platform(PlatformType.Any));
dc.isSpecCompliant = false;
return dc;
}

Expand All @@ -315,7 +299,6 @@ public static DesiredCapabilities Android()
public static DesiredCapabilities Opera()
{
DesiredCapabilities dc = new DesiredCapabilities("opera", string.Empty, new Platform(PlatformType.Any));
dc.isSpecCompliant = false;
return dc;
}

Expand All @@ -327,7 +310,6 @@ public static DesiredCapabilities Opera()
public static DesiredCapabilities Safari()
{
DesiredCapabilities dc = new DesiredCapabilities("safari", string.Empty, new Platform(PlatformType.Mac));
dc.isSpecCompliant = false;
return dc;
}

Expand Down
36 changes: 0 additions & 36 deletions dotnet/src/webdriver/Remote/ISpecificationCompliant.cs

This file was deleted.

18 changes: 7 additions & 11 deletions dotnet/src/webdriver/Remote/RemoteWebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public RemoteWebDriver(ICommandExecutor commandExecutor, ICapabilities desiredCa
object locationContextCapability = this.capabilities.GetCapability(CapabilityType.SupportsLocationContext);
if (locationContextCapability is bool && (bool)locationContextCapability)
{
this.locationContext = new RemoteLocationContext(this);
this.locationContext = new RemoteLocationContext(this);
}
}

Expand Down Expand Up @@ -1105,18 +1105,14 @@ protected void StartSession(ICapabilities desiredCapabilities)
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("desiredCapabilities", this.GetLegacyCapabilitiesDictionary(desiredCapabilities));

ISpecificationCompliant specCompliantCapabilities = desiredCapabilities as ISpecificationCompliant;
if (specCompliantCapabilities != null && specCompliantCapabilities.IsSpecificationCompliant)
{
Dictionary<string, object> firstMatchCapabilities = this.GetCapabilitiesDictionary(desiredCapabilities);
Dictionary<string, object> firstMatchCapabilities = this.GetCapabilitiesDictionary(desiredCapabilities);

List<object> firstMatchCapabilitiesList = new List<object>();
firstMatchCapabilitiesList.Add(firstMatchCapabilities);
List<object> firstMatchCapabilitiesList = new List<object>();
firstMatchCapabilitiesList.Add(firstMatchCapabilities);

Dictionary<string, object> specCompliantCapabilitiesDictionary = new Dictionary<string, object>();
specCompliantCapabilitiesDictionary["firstMatch"] = firstMatchCapabilitiesList;
parameters.Add("capabilities", specCompliantCapabilitiesDictionary);
}
Dictionary<string, object> specCompliantCapabilitiesDictionary = new Dictionary<string, object>();
specCompliantCapabilitiesDictionary["firstMatch"] = firstMatchCapabilitiesList;
parameters.Add("capabilities", specCompliantCapabilitiesDictionary);

Response response = this.Execute(DriverCommand.NewSession, parameters);

Expand Down

0 comments on commit 03d8714

Please sign in to comment.