-
Notifications
You must be signed in to change notification settings - Fork 16
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
base: main
Are you sure you want to change the base?
More options #131
Changes from all commits
7b39a97
5f9b88d
c9c5db5
8d75caa
9b91565
247dc00
fbafca9
ad39f61
eb40904
a8c7899
9006376
a4e88ae
21ad8f1
1d4d64e
def3e4f
19d8dd1
7f23da6
cc71d9f
e51eb15
cf360a0
ccba782
d2a2ba6
3a81fd3
c9738a1
dff7a3a
d447b0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
using System; | ||
|
||
namespace Simple.Sauce | ||
{ | ||
public class Platforms | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; } | ||
|
@@ -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; } | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue found: Remove this commented out code. |
||
//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() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Make this field 'private' and encapsulate it in a 'public' property.