Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #835 from Magenic/bug/CapWithColon
Browse files Browse the repository at this point in the history
Address Appium and Selenium remote cap mismatch
  • Loading branch information
TroyWalshProf authored Nov 5, 2021
2 parents 3d95acb + 2fed5a4 commit f684811
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Framework/BaseAppiumTest/AppiumDriverFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private static AppiumOptions SetMobileOptions(this AppiumOptions appiumOptions,
try
{
// Check if this is a Json string
var jsonDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(keyValue.Value as string);
var jsonDictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(keyValue.Value as string);
appiumOptions.AddAdditionalAppiumOption(keyValue.Key, jsonDictionary);
}
catch
Expand Down
55 changes: 37 additions & 18 deletions Framework/BaseSeleniumTest/WebDriverFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// </copyright>
// <summary>Web driver factory</summary>
//--------------------------------------------------
using Newtonsoft.Json;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
Expand Down Expand Up @@ -409,13 +410,13 @@ public static DriverOptions GetRemoteOptions(RemoteBrowserType remoteBrowser, st
// Add a platform setting if one was provided
if (!string.IsNullOrEmpty(remotePlatform) && !remoteCapabilities.ContainsKey("platform"))
{
remoteCapabilities.Add("platform", remotePlatform);
options.PlatformName = remotePlatform;
}

// Add a remote browser setting if one was provided
if (!string.IsNullOrEmpty(remoteBrowserVersion) && !remoteCapabilities.ContainsKey("version"))
{
remoteCapabilities.Add("version", remoteBrowserVersion);
options.BrowserVersion = remoteBrowserVersion;
}

// Add additional capabilities to the driver options
Expand All @@ -442,24 +443,42 @@ public static void SetDriverOptions(this DriverOptions driverOptions, Dictionary
// Make sure there is a value
if (keyValue.Value != null && (!(keyValue.Value is string) || !string.IsNullOrEmpty(keyValue.Value as string)))
{
switch (driverOptions)
// Handle W3C complient keys
if (keyValue.Key.Contains(":"))
{
case ChromeOptions chromeOptions:
chromeOptions.AddAdditionalChromeOption(keyValue.Key, keyValue.Value);
break;
case FirefoxOptions firefoxOptions:
firefoxOptions.AddAdditionalFirefoxOption(keyValue.Key, keyValue.Value);
break;
case InternetExplorerOptions ieOptions:
ieOptions.AddAdditionalInternetExplorerOption(keyValue.Key, keyValue.Value);
break;
case EdgeOptions ieOptions:
ieOptions.AddAdditionalEdgeOption(keyValue.Key, keyValue.Value);
break;
default:
// Not one of our 4 main types
try
{
// Check if this is a Json string
var jsonDictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(keyValue.Value as string);
driverOptions.AddAdditionalOption(keyValue.Key, jsonDictionary);
}
catch
{
// Not Json string so add as a normal string
driverOptions.AddAdditionalOption(keyValue.Key, keyValue.Value);
break;
}
}
else
{
switch (driverOptions)
{
case ChromeOptions chromeOptions:
chromeOptions.AddAdditionalChromeOption(keyValue.Key, keyValue.Value);
break;
case FirefoxOptions firefoxOptions:
firefoxOptions.AddAdditionalFirefoxOption(keyValue.Key, keyValue.Value);
break;
case InternetExplorerOptions ieOptions:
ieOptions.AddAdditionalInternetExplorerOption(keyValue.Key, keyValue.Value);
break;
case EdgeOptions ieOptions:
ieOptions.AddAdditionalEdgeOption(keyValue.Key, keyValue.Value);
break;
default:
// Not one of our 4 main types
driverOptions.AddAdditionalOption(keyValue.Key, keyValue.Value);
break;
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions Framework/SeleniumUnitTests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<!--Remote browser settings-->
<!--<add key="Browser" value="REMOTE"/>-->
<add key="RemoteBrowser" value="Chrome" />
<add key="RemotePlatform" value="Windows 10" />
<add key="HubUrl" value="https://ondemand.saucelabs.com/wd/hub" />
<add key="WebSiteBase" value="https://magenicautomation.azurewebsites.net/" />
<add key="BrowserWaitTime" value="1000" />
Expand All @@ -72,9 +73,9 @@
<add key="FirefoxVersion" value="0.30.0" />
</SeleniumMaqs>
<RemoteSeleniumCapsMaqs>
<!--<add key="sauce:options" value="{username: 'magenicMAQSService', accessKey: 'NEVER_ADD', appiumVersion: '1.20.2', orientation: 'portrait' }" />-->
<!--<add key="sauce:options" value="{username: 'USER', accessKey: 'KEY'}" />-->
<add key="username" value="magenicMAQSService" />
<add key="accessKey" value="NEVER_ENTER_THIS_VALUE" />
<add key="appiumVersion" value="1.20.2" />
<add key="test:test" value="test" />
</RemoteSeleniumCapsMaqs>
</configuration>
15 changes: 13 additions & 2 deletions Framework/SeleniumUnitTests/SeleniumConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void GetRemotePlatform()
{
string platform = SeleniumConfig.GetRemotePlatform();

Assert.AreEqual(platform, string.Empty);
Assert.AreEqual("Windows 10", platform);
}

/// <summary>
Expand All @@ -315,7 +315,7 @@ public void GetRemoteBrowserVersion()
{
string version = SeleniumConfig.GetRemoteBrowserVersion();

Assert.AreEqual(version, string.Empty);
Assert.AreEqual(string.Empty, version);
}

/// <summary>
Expand Down Expand Up @@ -579,5 +579,16 @@ public void CommandTimeoutNotANumberException()
"SeleniumMaqs");
}
}

/// <summary>
/// Capablities with colons are included in the top level capabilities
/// </summary>
[TestMethod]
[TestCategory(TestCategories.Selenium)]
public void CapablitiesWithColons()
{
var caps = WebDriverFactory.GetDefaultRemoteOptions().ToCapabilities();
Assert.AreEqual("test", caps.GetCapability("test:test"));
}
}
}

0 comments on commit f684811

Please sign in to comment.