diff --git a/dotnet/DotnetCore.Test/PackageIntegration.cs b/dotnet/DotnetCore.Test/PackageIntegration.cs index 9ac6c7ac..ff3d39ff 100644 --- a/dotnet/DotnetCore.Test/PackageIntegration.cs +++ b/dotnet/DotnetCore.Test/PackageIntegration.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Simple.Sauce; namespace DotnetCore.Test diff --git a/dotnet/Simple.Sauce/Browser.cs b/dotnet/Simple.Sauce/Browser.cs index a4d4e571..10720cd0 100644 --- a/dotnet/Simple.Sauce/Browser.cs +++ b/dotnet/Simple.Sauce/Browser.cs @@ -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; + } } } \ No newline at end of file diff --git a/dotnet/Simple.Sauce/DataCenter.cs b/dotnet/Simple.Sauce/DataCenter.cs index 12b5c168..c01af641 100644 --- a/dotnet/Simple.Sauce/DataCenter.cs +++ b/dotnet/Simple.Sauce/DataCenter.cs @@ -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"); } } \ No newline at end of file diff --git a/dotnet/Simple.Sauce/ISauceRemoteDriver.cs b/dotnet/Simple.Sauce/ISauceRemoteDriver.cs index 3e33105c..646f838c 100644 --- a/dotnet/Simple.Sauce/ISauceRemoteDriver.cs +++ b/dotnet/Simple.Sauce/ISauceRemoteDriver.cs @@ -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); } } \ No newline at end of file diff --git a/dotnet/Simple.Sauce/Platforms.cs b/dotnet/Simple.Sauce/Platforms.cs index 1bb1e346..3e0a8c6b 100644 --- a/dotnet/Simple.Sauce/Platforms.cs +++ b/dotnet/Simple.Sauce/Platforms.cs @@ -1,5 +1,3 @@ -using System; - namespace Simple.Sauce { public class Platforms diff --git a/dotnet/Simple.Sauce/SauceDriver.cs b/dotnet/Simple.Sauce/SauceDriver.cs index 08b0c580..92202f90 100644 --- a/dotnet/Simple.Sauce/SauceDriver.cs +++ b/dotnet/Simple.Sauce/SauceDriver.cs @@ -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) diff --git a/dotnet/Simple.Sauce/SauceOptions.cs b/dotnet/Simple.Sauce/SauceOptions.cs index b2b0ae50..8fb945e5 100644 --- a/dotnet/Simple.Sauce/SauceOptions.cs +++ b/dotnet/Simple.Sauce/SauceOptions.cs @@ -4,7 +4,9 @@ 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 @@ -12,20 +14,86 @@ 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 W3CAllowedOptionsList = new List(new[] + { + "BrowserName", + "BrowserVersion", + "PlatformName", + "PageLoadStrategy", + "AcceptInsecureCerts", + "Proxy", + "SetWindowRect", + "Timeouts", + "StrictFileInteractability", + "UnhandledPromptBehavior" + } + ); + + private static readonly List _sauceAllowedOptions = new List(new[] + { + "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 knownCITools = new Dictionary + { + {"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 CustomData { get; set; } + public Dictionary 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 + { + ["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); + //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() diff --git a/dotnet/Simple.Sauce/SauceSession.cs b/dotnet/Simple.Sauce/SauceSession.cs index 75b175ea..f79a51a3 100644 --- a/dotnet/Simple.Sauce/SauceSession.cs +++ b/dotnet/Simple.Sauce/SauceSession.cs @@ -1,7 +1,6 @@ -using System; +using OpenQA.Selenium; +using System; using System.Collections.Generic; -using OpenQA.Selenium; -using OpenQA.Selenium.Chrome; namespace Simple.Sauce { @@ -31,15 +30,31 @@ public SauceSession(SauceOptions options, ISauceRemoteDriver driver) Driver = driver; } - public ChromeOptions ChromeOptions { get; private set; } + readonly string sauceUserName = Environment.GetEnvironmentVariable("SAUCE_USERNAME"); + readonly string sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY"); + private Uri _sauceUrl; + public DataCenter DataCenter { get; set; } = DataCenter.UsWest; - public SauceOptions Options { get; } + public SauceOptions Options { get; private set; } public ISauceRemoteDriver Driver { get; set; } + public Uri SauceUrl + { + get + { + if (_sauceUrl != null) + return _sauceUrl; + else + { + string url = "https://" + sauceUserName + ":" + sauceAccessKey + "@" + DataCenter.Value + "/wd/hub"; + return new Uri(url); + } + } + } public IWebDriver Start() { - if (!string.IsNullOrEmpty(Options.ConfiguredEdgeOptions.BrowserVersion)) + if (Options.BrowserName == Browser.Edge) return CreateEdgeBrowser(); if (!string.IsNullOrEmpty(Options.ConfiguredSafariOptions.BrowserVersion)) return CreateSafariDriver(); @@ -92,16 +107,7 @@ private IWebDriver CreateChromeDriver() private IWebDriver CreateEdgeBrowser() { - var sauceUserName = Environment.GetEnvironmentVariable("SAUCE_USERNAME"); - var sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY"); - var sauceConfiguration = new Dictionary - { - ["username"] = sauceUserName, - ["accessKey"] = sauceAccessKey - }; - - Options.ConfiguredEdgeOptions.AddAdditionalOption("sauce:options", sauceConfiguration); - return Driver.CreateRemoteWebDriver(Options.ConfiguredEdgeOptions); + return Driver.CreateRemoteWebDriver(SauceUrl, Options.ToDriverOptions()); } public void Stop(bool isPassed) diff --git a/dotnet/Simple.Sauce/Simple.Sauce.csproj b/dotnet/Simple.Sauce/Simple.Sauce.csproj index c77e71b7..9f50686b 100644 --- a/dotnet/Simple.Sauce/Simple.Sauce.csproj +++ b/dotnet/Simple.Sauce/Simple.Sauce.csproj @@ -3,7 +3,7 @@ netstandard2.0 Simple.Sauce An API wrapper arounds the Sauce Labs API to make test automation extremely easy - Sauce Labs, Simple Sauce, Selenium + SauceLabs, Sauce, Selenium true 1.0.0 alpha diff --git a/dotnet/Simple.Sauce/TestVisibility.cs b/dotnet/Simple.Sauce/TestVisibility.cs index 0756f1c5..b4dd4706 100644 --- a/dotnet/Simple.Sauce/TestVisibility.cs +++ b/dotnet/Simple.Sauce/TestVisibility.cs @@ -2,6 +2,7 @@ { public enum TestVisibility { - Public + Public, + Team } } \ No newline at end of file diff --git a/dotnet/Simple.Sauce/Timeout.cs b/dotnet/Simple.Sauce/Timeout.cs index 1c50ac52..c3298b3a 100644 --- a/dotnet/Simple.Sauce/Timeout.cs +++ b/dotnet/Simple.Sauce/Timeout.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Serialization; +using System.Collections.Generic; namespace Simple.Sauce { diff --git a/dotnet/SimpleSauce.Test/BaselineSeleniumAcceptanceTests.cs b/dotnet/SimpleSauce.Test/BaselineSeleniumAcceptanceTests.cs index 5ffa9265..def2c53e 100644 --- a/dotnet/SimpleSauce.Test/BaselineSeleniumAcceptanceTests.cs +++ b/dotnet/SimpleSauce.Test/BaselineSeleniumAcceptanceTests.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Remote; -using Simple.Sauce; +using System; +using System.Collections.Generic; namespace SimpleSauce.Test { diff --git a/dotnet/SimpleSauce.Test/Browsers/EdgeTests.cs b/dotnet/SimpleSauce.Test/Browsers/EdgeTests.cs index d0be1114..a9c85fed 100644 --- a/dotnet/SimpleSauce.Test/Browsers/EdgeTests.cs +++ b/dotnet/SimpleSauce.Test/Browsers/EdgeTests.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Simple.Sauce; +using System; +using System.Collections.Generic; namespace SimpleSauce.Test.Browsers { @@ -15,23 +15,11 @@ public void Setup() SauceOptions = new SauceOptions(); } [TestMethod] - public void WithEdge_DefaultPlatform_Windows10() - { - SauceOptions.WithEdge(); - SauceOptions.ConfiguredEdgeOptions.PlatformName.Should().Be("Windows 10"); - } - [TestMethod] - public void WithEdge_DefaultBrowserVersion_latest() - { - SauceOptions.WithEdge(); - SauceOptions.ConfiguredEdgeOptions.BrowserVersion.Should().Be("latest"); - } - [TestMethod] [DynamicData(nameof(PossibleEdgeConfigurations), typeof(EdgeTests))] public void WithEdge_SetVersion_SetsCorrectVersion(string expectedVersion, EdgeVersion edgeVersion) { - SauceOptions.WithEdge(edgeVersion); - SauceOptions.ConfiguredEdgeOptions.BrowserVersion.Should().Be(expectedVersion); + SauceOptions.BrowserVersion = edgeVersion.Value; + SauceOptions.BrowserVersion.Should().Be(expectedVersion); } public static IEnumerable PossibleEdgeConfigurations => new[] { @@ -42,11 +30,5 @@ public void WithEdge_SetVersion_SetsCorrectVersion(string expectedVersion, EdgeV new object[] {"14.14393", EdgeVersion._14 }, new object[] { "13.10586", EdgeVersion._13 } }; - - [TestMethod] - public void WithEdge_NullBrowserVersion_ThrowsException() - { - Assert.ThrowsException(() => SauceOptions.WithEdge(null)); - } } } diff --git a/dotnet/SimpleSauce.Test/Browsers/FirefoxTests.cs b/dotnet/SimpleSauce.Test/Browsers/FirefoxTests.cs deleted file mode 100644 index 939c5a7f..00000000 --- a/dotnet/SimpleSauce.Test/Browsers/FirefoxTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium.Chrome; -using OpenQA.Selenium.Firefox; -using Simple.Sauce; - -namespace SimpleSauce.Test.Browsers -{ - [TestClass] - public class FirefoxTests : BaseTest - { - [TestInitialize] - public void Setup() - { - SauceOptions = new SauceOptions(); - } - [TestMethod] - public void WithFirefox_SetsFirefoxOptions() - { - SauceOptions.WithFirefox(); - SauceOptions.ConfiguredFirefoxOptions.Should().NotBeNull(); - SauceOptions.ConfiguredFirefoxOptions.Should().BeOfType(typeof(FirefoxOptions)); - } - [TestMethod] - public void WithFirefox_DefaultBrowserVersion_Latest() - { - SauceOptions.WithFirefox(); - SauceOptions.ConfiguredChromeOptions.BrowserVersion.Should().Be("latest"); - } - [TestMethod] - public void WithFirefox_DefaultPlatform_Win10() - { - SauceOptions.WithFirefox(); - SauceOptions.ConfiguredChromeOptions.PlatformName.Should().Be("Windows 10"); - } - [TestMethod] - public void WithFirefox_VersionChanged_SetsVersion() - { - SauceOptions.WithFirefox("72"); - SauceOptions.ConfiguredFirefoxOptions.BrowserVersion.Should().Be("72"); - } - } -} diff --git a/dotnet/SimpleSauce.Test/Browsers/SafariTests.cs b/dotnet/SimpleSauce.Test/Browsers/SafariTests.cs index 7a434295..219229b9 100644 --- a/dotnet/SimpleSauce.Test/Browsers/SafariTests.cs +++ b/dotnet/SimpleSauce.Test/Browsers/SafariTests.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Simple.Sauce; +using System.Collections.Generic; namespace SimpleSauce.Test.Browsers { diff --git a/dotnet/SimpleSauce.Test/SauceOptionsTests.cs b/dotnet/SimpleSauce.Test/SauceOptionsTests.cs index c68023b7..4ea123ad 100644 --- a/dotnet/SimpleSauce.Test/SauceOptionsTests.cs +++ b/dotnet/SimpleSauce.Test/SauceOptionsTests.cs @@ -1,12 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices.ComTypes; using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Edge; +using OpenQA.Selenium.Firefox; +using OpenQA.Selenium.IE; +using OpenQA.Selenium.Safari; using Simple.Sauce; +using System; +using System.Collections.Generic; namespace SimpleSauce.Test { @@ -22,18 +24,18 @@ public void Setup() [TestMethod] public void UsesLatestChromeWindowsVersionsByDefault() { - SauceOptions.BrowserName.Should().BeEquivalentTo(Browser.Chrome); + SauceOptions.BrowserName.Should().Be(Browser.Chrome); SauceOptions.BrowserVersion.Should().Be("latest"); SauceOptions.PlatformName.Should().BeEquivalentTo(Platforms.Windows10); } [TestMethod] - public void UpdatesBrowserBrowserVersionPlatformVersion() + public void UpdatesBrowserVersionPlatformVersion() { SauceOptions.BrowserVersion = "68"; SauceOptions.BrowserName = Browser.Firefox; SauceOptions.PlatformName = Platforms.MacOsHighSierra; - SauceOptions.BrowserName.Should().BeEquivalentTo(Browser.Firefox); + SauceOptions.BrowserName.Should().Be(Browser.Firefox); SauceOptions.BrowserVersion.Should().Be("68"); SauceOptions.PlatformName.Should().BeEquivalentTo(Platforms.MacOsHighSierra); } @@ -56,7 +58,6 @@ public void AcceptsAllW3CValues() var page = new KeyValuePair("pageload", 44); var script = new KeyValuePair("script", 33); - SauceOptions.AcceptInsecureCerts.Should().BeTrue(); SauceOptions.PageLoadStrategy.Should().Be(PageLoadStrategy.Eager); SauceOptions.Proxy.Should().Be(proxy); @@ -132,5 +133,197 @@ public void AcceptsAllSauceLabsValues() SauceOptions.TunnelIdentifier.Should().Be("My Tunnel ID"); SauceOptions.VideoUploadOnPass.Should().BeFalse(); } + + [TestMethod] + public void AcceptsChromeOptionsClass() + { + var options = new ChromeOptions(); + SauceOptions = new SauceOptions(options); + + SauceOptions.BrowserName.Should().BeEquivalentTo(Browser.Chrome); + SauceOptions.SeleniumOptions.Should().BeEquivalentTo(options); + } + [TestMethod] + public void AcceptsEdgeOptionsClass() + { + var options = new EdgeOptions(); + SauceOptions = new SauceOptions(options); + + SauceOptions.BrowserName.Should().Be(Browser.Edge); + SauceOptions.SeleniumOptions.Should().BeEquivalentTo(options); + } + + [TestMethod] + public void AcceptsFirefoxOptionsClass() + { + var options = new FirefoxOptions(); + SauceOptions = new SauceOptions(options); + + SauceOptions.BrowserName.Should().BeEquivalentTo(Browser.Firefox); + SauceOptions.SeleniumOptions.Should().BeEquivalentTo(options); + } + + [TestMethod] + public void AcceptsInternetExplorerOptionsClass() + { + var options = new InternetExplorerOptions(); + SauceOptions = new SauceOptions(options); + + SauceOptions.BrowserName.Should().BeEquivalentTo(Browser.IE); + SauceOptions.SeleniumOptions.Should().BeEquivalentTo(options); + } + + [TestMethod] + public void AcceptsSafariOptionsClass() + { + var options = new SafariOptions(); + SauceOptions = new SauceOptions(options); + + SauceOptions.BrowserName.Should().BeEquivalentTo(Browser.Safari); + SauceOptions.SeleniumOptions.Should().BeEquivalentTo(options); + } + + [TestMethod] + public void CreatesDefaultBuildName() + { + Environment.SetEnvironmentVariable("BUILD_TAG", "Not Empty"); + Environment.SetEnvironmentVariable("BUILD_NAME", "TEMP BUILD"); + Environment.SetEnvironmentVariable("BUILD_NUMBER", "11"); + + SauceOptions.BuildName.Should().BeEquivalentTo("TEMP BUILD: 11"); + } + + [TestMethod] + [Ignore("Waiting for fixes")] + + public void ParsesCapabilitiesFromW3CValues() + { + SauceOptions.BrowserName = Browser.Firefox; + SauceOptions.PlatformName = Platforms.MacOsHighSierra; + SauceOptions.BrowserVersion = "77"; + SauceOptions.PageLoadStrategy = PageLoadStrategy.Eager; + SauceOptions.AcceptInsecureCerts = true; + SauceOptions.SetWindowRect = true; + SauceOptions.Timeout.Implicit = 4; + SauceOptions.Timeout.PageLoad = 44; + SauceOptions.Timeout.Script = 33; + SauceOptions.BuildName = "Build Name"; + + var timeouts = new Dictionary + { + { "Implicit", 4 }, + { "PageLoad", 44 }, + { "Script", 33 } + }; + + var expectedCapabilities = new Dictionary + { + { "BrowserName", "firefox" }, + { "BrowserVersion", "77" }, + { "PlatformName", "macOS 10.13" }, + { "AcceptInsecureCerts", true }, + { "SetWindowRect", true }, + { "StrictFileInteractability", true }, + { "PageLoadStrategy", PageLoadStrategy.Eager }, + { "Timeouts", timeouts }, + { "UnhandledPromptBehavior", UnhandledPromptBehavior.Ignore } + }; + + SauceOptions.ToDriverOptions().Should().Be(expectedCapabilities); + } + + [TestMethod] + [Ignore("Waiting for fixes")] + public void ParsesCapabilitiesFromSauceLabsValues() + { + var customData = new Dictionary { { "foo", "foo" }, { "bar", "bar" } }; + + var args = new List { "--silent", "-a", "-q" }; + + var prerun = new Dictionary + { + {"executable", "http://url.to/your/executable.exe"}, + {"args", args}, + {"background", false}, + {"timeout", new TimeSpan(120)} + }; + + var tags = new List { "foo", "bar" }; + + SauceOptions.AvoidProxy = true; + SauceOptions.BuildName = "Sample Build Name"; + SauceOptions.CapturePerformance = true; + SauceOptions.ChromedriverVersion = "71"; + SauceOptions.Timeout.CommandTimeout = 2; + SauceOptions.CustomData = customData; + SauceOptions.ExtendedDebugging = true; + SauceOptions.Timeout.IdleTimeout = 3; + SauceOptions.IeDriverVersion = "3.141.0"; + SauceOptions.Timeout.MaxDuration = 300; + SauceOptions.TestName = "Sample Test Name"; + SauceOptions.ParentTunnel = "Mommy"; + SauceOptions.Prerun = prerun; + SauceOptions.Priority = 0; + SauceOptions.TestVisibility = TestVisibility.Team; + SauceOptions.RecordLogs = false; + SauceOptions.RecordScreenshots = false; + SauceOptions.RecordVideo = false; + SauceOptions.ScreenResolution = "10x10"; + SauceOptions.SeleniumVersion = "3.141.59"; + SauceOptions.Tags = tags; + SauceOptions.TimeZone = "San Francisco"; + SauceOptions.TunnelIdentifier = "MyTunnel"; + SauceOptions.VideoUploadOnPass = false; + + var expectedCapabilities = new Dictionary(); + + SauceOptions.ToDriverOptions().Should().BeEquivalentTo(expectedCapabilities, options => options.WithAutoConversion()); + } + [TestMethod] + [Ignore("Waiting for fixes")] + + public void ParsesCapabilitiesFromSeleniumValues() + { + var options = new ChromeOptions(); + SauceOptions = new SauceOptions(options); + + var expectedCapabilities = new Dictionary(); + + SauceOptions.ToDriverOptions().Should().BeEquivalentTo(expectedCapabilities); + } + + //TODO finish copying over this test from Java later + [TestMethod] + [Ignore("Waiting for fixes")] + + public void ParsesW3CAndSauceAndSeleniumValues() + { + var firefoxOptions = new FirefoxOptions(); + firefoxOptions.AddArguments("--foo"); + firefoxOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.Dismiss; + + SauceOptions = new SauceOptions(firefoxOptions) + { + PageLoadStrategy = PageLoadStrategy.Eager, + AcceptInsecureCerts = true, + AvoidProxy = true, + BuildName = "Sample Build Name", + CapturePerformance = true + }; + + + var impl = new KeyValuePair("implicit", 4); + var page = new KeyValuePair("pageload", 44); + var script = new KeyValuePair("script", 33); + + var expectedCapabilities = new Dictionary + { + { "platformName", Platforms.Windows10 }, + { "pageLoadStrategy", "eager" }, + {"acceptInsecureCerts", true } + }; + + SauceOptions.ToDriverOptions().Should().BeEquivalentTo(expectedCapabilities); + } } } diff --git a/dotnet/SimpleSauce.Test/SauceSessionTests.cs b/dotnet/SimpleSauce.Test/SauceSessionTests.cs index 9c607845..cd54af66 100644 --- a/dotnet/SimpleSauce.Test/SauceSessionTests.cs +++ b/dotnet/SimpleSauce.Test/SauceSessionTests.cs @@ -1,5 +1,3 @@ -using System; -using System.Reflection; using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -58,19 +56,6 @@ public void Start_Default_SetsSauceOptionsTag() AssertUsernameAndAccessKeyExist(browserOptionsSetInSauce); } [TestMethod] - public void Start_WithEdge_SetsUsernameAndAccessKey() - { - SauceOptions = new SauceOptions(); - SauceOptions.WithEdge(); - SauceSession = new SauceSession(SauceOptions, _dummyDriver.Object); - - SauceSession.Start(); - - var browserOptionsSetInSauceJson = SauceSession.Options.ConfiguredEdgeOptions.ToString(); - var browserOptionsSetInSauce = DeserializeToObject(browserOptionsSetInSauceJson); - AssertUsernameAndAccessKeyExist(browserOptionsSetInSauce); - } - [TestMethod] public void Start_WithChrome_SetsUsernameAndAccessKey() { SauceOptions = new SauceOptions(); diff --git a/dotnet/SimpleSauce.Test/SimpleSauce.Test.csproj b/dotnet/SimpleSauce.Test/SimpleSauce.Test.csproj index e31f8010..77d035c1 100644 --- a/dotnet/SimpleSauce.Test/SimpleSauce.Test.csproj +++ b/dotnet/SimpleSauce.Test/SimpleSauce.Test.csproj @@ -1,8 +1,7 @@  - netcoreapp2.1 - + netcoreapp3.0 false diff --git a/dotnet/SimpleSauce.Test/SimpleSauceAcceptanceTests.cs b/dotnet/SimpleSauce.Test/SimpleSauceAcceptanceTests.cs index 3ecabed4..46822ea7 100644 --- a/dotnet/SimpleSauce.Test/SimpleSauceAcceptanceTests.cs +++ b/dotnet/SimpleSauce.Test/SimpleSauceAcceptanceTests.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; @@ -29,30 +27,27 @@ public void Start_Default_IsChrome() { _session = new SauceSession(); _driver = _session.Start(); + ((IJavaScriptExecutor)_driver).ExecuteScript("sauce:job-name=" + TestContext.TestName); + var capabilities = ((RemoteWebDriver)_driver).Capabilities; capabilities.GetCapability("browserName").Should().Be("chrome"); } [TestMethod] public void RunTestWithEdge() { - _sauceOptions = new SauceOptions(); - _sauceOptions.WithEdge(); - _session = new SauceSession(_sauceOptions); - _driver = _session.Start(); - var capabilities = ((RemoteWebDriver)_driver).Capabilities; - capabilities.GetCapability("browserName").Should().Be("MicrosoftEdge"); - } - [TestMethod] - [Ignore("Getting an infrastructure error")] - public void RunTestWithEdge15() - { - _sauceOptions = new SauceOptions(); - _sauceOptions.WithEdge(EdgeVersion._15); + _sauceOptions = new SauceOptions + { + BrowserName = Browser.Edge + }; + _session = new SauceSession(_sauceOptions); _driver = _session.Start(); + ((IJavaScriptExecutor)_driver).ExecuteScript("sauce:job-name=" + TestContext.TestName); var capabilities = ((RemoteWebDriver)_driver).Capabilities; - capabilities.GetCapability("browserName").Should().Be("MicrosoftEdge"); + //Noticed that I started getting back msedge + capabilities.GetCapability("browserName").Should().Be("msedge"); } + [TestMethod] public void RunTestWithSafariDefault() { @@ -60,6 +55,8 @@ public void RunTestWithSafariDefault() _sauceOptions.WithSafari(); _session = new SauceSession(_sauceOptions); _driver = _session.Start(); + ((IJavaScriptExecutor)_driver).ExecuteScript("sauce:job-name=" + TestContext.TestName); + var capabilities = ((RemoteWebDriver)_driver).Capabilities; capabilities.GetCapability("browserName").Should().Be("Safari"); }