Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More options #131

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7b39a97
[dotnet] add new sauce options capabilities based on updated java spec
nadvolod Jan 14, 2020
5f9b88d
add test for setting properties in options
nadvolod Jan 14, 2020
c9c5db5
add all w3c caps
nadvolod Jan 14, 2020
8d75caa
add Sauce specific SauceOptions options
nadvolod Jan 14, 2020
9b91565
add test to convert Timeouts to dictionary
nadvolod Jan 15, 2020
247dc00
[dotnet] finishing adding the rest of SauceOptions based on Java spec
nadvolod Feb 4, 2020
fbafca9
merging
nadvolod Feb 4, 2020
ad39f61
change to netcore3.0
nadvolod Feb 4, 2020
eb40904
add BuildName logic
nadvolod Feb 4, 2020
a8c7899
udpated name of GetEnvVariable()
nadvolod Feb 4, 2020
9006376
fixed issue with mutable Chrome being returned from Browser
nadvolod Feb 5, 2020
a4e88ae
add a suite of working tests using java capabilities
nadvolod Feb 19, 2020
21ad8f1
trying to implement the ToCapabilites logic
nadvolod Feb 19, 2020
1d4d64e
got Edge toBrowserOptions() going with a hack
nadvolod Feb 19, 2020
def3e4f
removed dead tests
nadvolod Feb 19, 2020
19d8dd1
renaming methods and cleaning up dataCenter strings
nadvolod Feb 19, 2020
7f23da6
removed a bunch of old Edge functionality
nadvolod Feb 19, 2020
cc71d9f
clean up tests
nadvolod Feb 19, 2020
e51eb15
add the rest of Java tests
nadvolod Feb 19, 2020
cf360a0
fix compilation error
nadvolod Feb 19, 2020
ccba782
Cleaning up tests
nadvolod Mar 9, 2020
d2a2ba6
cleanup the structure of the code
nadvolod Mar 9, 2020
3a81fd3
Minor clean up with Resharper
nadvolod Mar 9, 2020
c9738a1
cleaning up tests
nadvolod Mar 16, 2020
dff7a3a
Merge branch 'master' into more_options
nadvolod Mar 16, 2020
d447b0d
ignore failing tests
nadvolod Mar 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dotnet/DotnetCore.Test/PackageIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Simple.Sauce;

namespace DotnetCore.Test
Expand Down
15 changes: 12 additions & 3 deletions dotnet/Simple.Sauce/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ private Browser(string browserName)
Value = browserName;
}

public string Value { get; set; }
private string Value { get; set; }

public static Browser Chrome => new Browser("chrome");
public static Browser Firefox => new Browser("firefox");
public static Browser Chrome { get; } = new Browser("chrome");
public static Browser Firefox { get; } = new Browser("firefox");
public static Browser Safari { get; } = new Browser("safari");
public static Browser Edge { get; } = new Browser("MicrosoftEdge");
public static Browser IE { get; } = new Browser("internet explorer");


public override string ToString()
{
return Value;
}
}
}
6 changes: 3 additions & 3 deletions dotnet/Simple.Sauce/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ private DataCenter(string value)

public string Value { get; set; }

public static DataCenter UsWest => new DataCenter("https://ondemand.saucelabs.com/wd/hub");
public static DataCenter UsWest => new DataCenter("ondemand.us-west-1.saucelabs.com");

public static DataCenter UsEast => new DataCenter("https://ondemand.us-east-1.saucelabs.com/wd/hub");
public static DataCenter UsEast => new DataCenter("ondemand.us-east-1.saucelabs.com");

public static object EuCental => new DataCenter("https://ondemand.eu-central-1.saucelabs.com/wd/hub");
public static object EuCental => new DataCenter("ondemand.eu-central-1.saucelabs.com");
}
}
2 changes: 2 additions & 0 deletions dotnet/Simple.Sauce/ISauceRemoteDriver.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using OpenQA.Selenium;
using System;

namespace Simple.Sauce
{
public interface ISauceRemoteDriver : IJavaScriptExecutor, IWebDriver
{
IWebDriver CreateRemoteWebDriver(DriverOptions options);
IWebDriver CreateRemoteWebDriver(Uri sauceUri, DriverOptions browserOptions);
}
}
2 changes: 0 additions & 2 deletions dotnet/Simple.Sauce/Platforms.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace Simple.Sauce
{
public class Platforms
Expand Down
19 changes: 13 additions & 6 deletions dotnet/Simple.Sauce/SauceDriver.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
using System;
using System.Collections.ObjectModel;
using OpenQA.Selenium;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System;
using System.Collections.ObjectModel;

namespace Simple.Sauce
{
public class SauceDriver : ISauceRemoteDriver
{
private IWebDriver _driver;
private IWebDriver _driver;
public IWebDriver CreateRemoteWebDriver(DriverOptions browserOptions)
{
_driver = new RemoteWebDriver(new Uri("https://ondemand.saucelabs.com/wd/hub"),
browserOptions.ToCapabilities(), TimeSpan.FromSeconds(600));
browserOptions.ToCapabilities(), TimeSpan.FromSeconds(30));
return _driver;
}

public IWebDriver CreateRemoteWebDriver(Uri sauceUri, DriverOptions browserOptions)
{
_driver = new RemoteWebDriver(sauceUri,
browserOptions.ToCapabilities(), TimeSpan.FromSeconds(30));
return _driver;
}

public object ExecuteScript(string script, params object[] args)
{
return ((IJavaScriptExecutor) _driver).ExecuteScript(script, args);
return ((IJavaScriptExecutor)_driver).ExecuteScript(script, args);
}

public object ExecuteAsyncScript(string script, params object[] args)
Expand Down
202 changes: 187 additions & 15 deletions dotnet/Simple.Sauce/SauceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,96 @@
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Safari;

// ReSharper disable InconsistentNaming

namespace Simple.Sauce
{
public class SauceOptions
{
private const string DEFAULT_BROWSER_VERSION = "latest";

private const string DEFAULT_PLATFORM = "Windows 10";

//TODO not fond of this name
public static List<string> W3CAllowedOptionsList = new List<string>(new[]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
"BrowserName",
"BrowserVersion",
"PlatformName",
"PageLoadStrategy",
"AcceptInsecureCerts",
"Proxy",
"SetWindowRect",
"Timeouts",
"StrictFileInteractability",
"UnhandledPromptBehavior"
}
);

private static readonly List<string> _sauceAllowedOptions = new List<string>(new[]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
"AvoidProxy",
"Build",
"CapturePerformance",
"ChromedriverVersion",
"CommandTimeout",
"CustomData",
"ExtendedDebugging",
"IdleTimeout",
"IedriverVersion",
"MaxDuration",
"Name",
"ParentTunnel",
"Prerun",
"Priority",
// public, do not use, reserved keyword, using jobVisibility
"RecordLogs",
"RecordScreenshots",
"RecordVideo",
"ScreenResolution",
"SeleniumVersion",
"Tags",
"TimeZone",
"TunnelIdentifier",
"VideoUploadOnPass"
}
);

//TODO could probably store this into an enum
private readonly Dictionary<string, string> knownCITools = new Dictionary<string, string>
{
{"Jenkins", "BUILD_TAG"},
{"Bamboo", "bamboo_agentId"},
{"Travis", "TRAVIS_JOB_ID"},
{"Circle", "CIRCLE_JOB"},
{"GitLab", "CI"},
{"TeamCity", "TEAMCITY_PROJECT_NAME"},
{"ADO", "NEEDS_DEFINITION"}
};

private string _buildName;

public SauceOptions()
{
WithChrome();
Timeout = new Timeout();
}

public EdgeOptions ConfiguredEdgeOptions { get; set; } = new EdgeOptions();
public ChromeOptions ConfiguredChromeOptions { get; private set; } = new ChromeOptions();
public SauceOptions(DriverOptions options)
{
SeleniumOptions = options;
Timeout = new Timeout();
if (options.BrowserName != null) BrowserName = ToBrowserEnum(options.BrowserName);
}

public ChromeOptions ConfiguredChromeOptions { get; } = new ChromeOptions();
public SafariOptions ConfiguredSafariOptions { get; set; } = new SafariOptions();

public FirefoxOptions ConfiguredFirefoxOptions { get; set; } = new FirefoxOptions();
public Browser BrowserName { get; set; } = Browser.Chrome;
public String BrowserVersion { get; set; } = DEFAULT_BROWSER_VERSION;

public string BrowserVersion { get; set; } = DEFAULT_BROWSER_VERSION;
public Platforms PlatformName { get; set; } = Platforms.Windows10;
public PageLoadStrategy PageLoadStrategy { get; set; }
public bool AcceptInsecureCerts { get; set; }
Expand All @@ -36,10 +104,36 @@ public SauceOptions()
public bool StrictFileInteractability { get; set; }
public UnhandledPromptBehavior UnhandledPromptBehavior { get; set; }
public bool AvoidProxy { get; set; }
public string BuildName { get; set; }

public string BuildName
{
get
{
if (_buildName != null)
return _buildName;
if (GetEnvironmentVariable(knownCITools["Jenkins"]) != null)
return GetEnvironmentVariable("BUILD_NAME") + ": " + GetEnvironmentVariable("BUILD_NUMBER");
if (GetEnvironmentVariable(knownCITools["Bamboo"]) != null)
return GetEnvironmentVariable("bamboo_shortJobName") + ": " +
GetEnvironmentVariable("bamboo_buildNumber");
if (GetEnvironmentVariable(knownCITools["Travis"]) != null)
return GetEnvironmentVariable("TRAVIS_JOB_NAME") + ": " +
GetEnvironmentVariable("TRAVIS_JOB_NUMBER");
if (GetEnvironmentVariable(knownCITools["Circle"]) != null)
return GetEnvironmentVariable("CIRCLE_JOB") + ": " + GetEnvironmentVariable("CIRCLE_BUILD_NUM");
if (GetEnvironmentVariable(knownCITools["GitLab"]) != null)
return GetEnvironmentVariable("CI_JOB_NAME") + ": " + GetEnvironmentVariable("CI_JOB_ID");
if (GetEnvironmentVariable(knownCITools["TeamCity"]) != null)
return GetEnvironmentVariable("TEAMCITY_PROJECT_NAME") + ": " +
GetEnvironmentVariable("BUILD_NUMBER");
return "Build Time: " + DateTime.Now;
}
set => _buildName = value;
}

public bool CapturePerformance { get; set; }
public string ChromedriverVersion { get; set; }
public Dictionary<string,string> CustomData { get; set; }
public Dictionary<string, string> CustomData { get; set; }
public bool ExtendedDebugging { get; set; }
public string IeDriverVersion { get; set; }
public string TestName { get; set; }
Expand All @@ -56,19 +150,97 @@ public SauceOptions()
public string TimeZone { get; set; }
public string TunnelIdentifier { get; set; }
public bool VideoUploadOnPass { get; set; }
public DriverOptions SeleniumOptions { get; set; }
public Browser BrowserName { get; set; } = Browser.Chrome;

public DriverOptions ToDriverOptions()
{
//TODO temporary solution to get the code working
var sauceConfiguration = new Dictionary<string, object>
{
["username"] = Environment.GetEnvironmentVariable("SAUCE_USERNAME"),
["accessKey"] = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY")
};
//TODO add if logic from the toCapabilities() in Java

SetDriverOptions();
W3CAllowedOptionsList.ForEach(AppendCapabilityToSeleniumOptions);

SeleniumOptions.AddAdditionalOption("sauce:options", sauceConfiguration);
return SeleniumOptions;
}

private void SetDriverOptions()
{
if (BrowserName == Browser.Edge)
SeleniumOptions = new EdgeOptions();
else if (BrowserName == Browser.Firefox)
SeleniumOptions = new FirefoxOptions();
else if(BrowserName == Browser.Chrome)
SeleniumOptions = new ChromeOptions();
else if(BrowserName == Browser.IE)
SeleniumOptions = new InternetExplorerOptions();
else if(BrowserName == Browser.Safari)
SeleniumOptions = new SafariOptions();
else
throw new ArgumentOutOfRangeException("The desired browser configuration is not yet set.");
}

private void AppendCapabilityToSeleniumOptions(string capability)
{
var capabilityValue = TryToGetCapabilityValue(capability);
if (capabilityValue != null)
{
SeleniumOptions.AddAdditionalOption(capability, capabilityValue);
}
}

public void WithEdge()
private object TryToGetCapabilityValue(string capability)
{
WithEdge(EdgeVersion.Latest);
try
{
return GetType().GetProperty(capability)?.GetValue(this);
}
catch (NullReferenceException)
{
return null;
}

//PropertyInfo pinfo = typeof(SauceOptions).GetProperty(capability);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//return pinfo.GetValue(YourInstantiatedObject, null);
}

public void WithEdge(EdgeVersion edgeVersion)

protected string GetEnvironmentVariable(string key)
{
if (edgeVersion == null)
throw new ArgumentNullException("Please supply a valid EdgeVersion. You suplied an invalid value=>" +
edgeVersion);
ConfiguredEdgeOptions.BrowserVersion = edgeVersion.Value;
ConfiguredEdgeOptions.PlatformName = DEFAULT_PLATFORM;
return Environment.GetEnvironmentVariable(key);
}

private Browser ToBrowserEnum(string browserName)
{
Browser browser;
switch (browserName)
{
case "chrome":
browser = Browser.Chrome;
break;
case "MicrosoftEdge":
browser = Browser.Edge;
break;
case "firefox":
browser = Browser.Firefox;
break;
case "safari":
browser = Browser.Safari;
break;
case "internet explorer":
browser = Browser.IE;
break;
default:
throw new ArgumentException("No such browser exists.");
}

return browser;
}

public void WithChrome()
Expand Down
Loading