diff --git a/src/Core/Riganti.Selenium.Core/Drivers/Implementation/ChromeHelpers.cs b/src/Core/Riganti.Selenium.Core/Drivers/Implementation/ChromeHelpers.cs index b714d724..684becef 100644 --- a/src/Core/Riganti.Selenium.Core/Drivers/Implementation/ChromeHelpers.cs +++ b/src/Core/Riganti.Selenium.Core/Drivers/Implementation/ChromeHelpers.cs @@ -16,7 +16,7 @@ public static ChromeDriver CreateChromeDriver(LocalWebBrowserFactory factory) options.AddArgument("disable-popup-blocking"); options.AddArguments(factory.Capabilities); - options.BrowserVersion = factory.Options.TryGetOrDefault(nameof(options.BrowserVersion), "stable"); + options.BrowserVersion = factory.Options.TryGet(nameof(options.BrowserVersion)); if (factory.GetBooleanOption("disableExtensions")) { diff --git a/src/Core/Riganti.Selenium.Core/Drivers/Implementation/DictionaryExtensions.cs b/src/Core/Riganti.Selenium.Core/Drivers/Implementation/DictionaryExtensions.cs index aa301249..fc81069a 100644 --- a/src/Core/Riganti.Selenium.Core/Drivers/Implementation/DictionaryExtensions.cs +++ b/src/Core/Riganti.Selenium.Core/Drivers/Implementation/DictionaryExtensions.cs @@ -5,13 +5,13 @@ namespace Riganti.Selenium.Core.Drivers.Implementation public static class DictionaryExtensions { - public static T2 TryGetOrDefault(this IDictionary dic, T1 key, T2 defaultValue) + public static T2 TryGet(this IDictionary dic, T1 key) { if (dic is not null && dic.TryGetValue(key, out T2 value) && value is T2) { return value; } - return defaultValue; + return default; } } } \ No newline at end of file diff --git a/src/Core/Riganti.Selenium.Core/Drivers/Implementation/EdgeHelpers.cs b/src/Core/Riganti.Selenium.Core/Drivers/Implementation/EdgeHelpers.cs index 933dcdc2..e53a1fc1 100644 --- a/src/Core/Riganti.Selenium.Core/Drivers/Implementation/EdgeHelpers.cs +++ b/src/Core/Riganti.Selenium.Core/Drivers/Implementation/EdgeHelpers.cs @@ -11,7 +11,7 @@ public static EdgeDriver CreateEdgeDriver(LocalWebBrowserFactory factory) { }; - options.BrowserVersion = factory.Options.TryGetOrDefault(nameof(options.BrowserVersion), "stable"); + options.BrowserVersion = factory.Options.TryGet(nameof(options.BrowserVersion)); return new EdgeDriver(options); } } diff --git a/src/Core/Riganti.Selenium.Core/Drivers/Implementation/FirefoxHelpers.cs b/src/Core/Riganti.Selenium.Core/Drivers/Implementation/FirefoxHelpers.cs index 7b70f238..288e9706 100644 --- a/src/Core/Riganti.Selenium.Core/Drivers/Implementation/FirefoxHelpers.cs +++ b/src/Core/Riganti.Selenium.Core/Drivers/Implementation/FirefoxHelpers.cs @@ -1,5 +1,7 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.IO; +using Newtonsoft.Json; using OpenQA.Selenium.Firefox; using Riganti.Selenium.Core.Factories; @@ -16,7 +18,11 @@ static FirefoxHelpers() public static FirefoxDriver CreateFirefoxDriver(LocalWebBrowserFactory factory) { - return new FirefoxDriver(service, GetFirefoxOptions(factory.Options)); + Console.WriteLine("Firefox applies capabilities: " + JsonConvert.SerializeObject(factory.Capabilities)); + var ffOptions = GetFirefoxOptions(factory.Options); + Console.WriteLine("Firefox applies options: " + JsonConvert.SerializeObject(ffOptions)); + var driver = new FirefoxDriver(service, ffOptions); + return driver; } public static FirefoxProfile GetFirefoxProfile() @@ -30,8 +36,12 @@ public static FirefoxProfile GetFirefoxProfile() public static FirefoxOptions GetFirefoxOptions(System.Collections.Generic.IDictionary _options) { - var options = new FirefoxOptions { Profile = GetFirefoxProfile() }; - options.BrowserVersion = _options.TryGetOrDefault(nameof(options.BrowserVersion), "stable"); + var options = new FirefoxOptions + { + // Profile = GetFirefoxProfile() + }; + options.BrowserVersion = _options.TryGet(nameof(options.BrowserVersion)); + Console.WriteLine($"Requesting {options.BrowserVersion} version of browser"); return options; } } diff --git a/src/Core/Riganti.Selenium.Core/Drivers/Implementation/InternetExplorerHelpers.cs b/src/Core/Riganti.Selenium.Core/Drivers/Implementation/InternetExplorerHelpers.cs index 274b7d13..d9a0fc21 100644 --- a/src/Core/Riganti.Selenium.Core/Drivers/Implementation/InternetExplorerHelpers.cs +++ b/src/Core/Riganti.Selenium.Core/Drivers/Implementation/InternetExplorerHelpers.cs @@ -12,7 +12,7 @@ public static InternetExplorerDriver CreateInternetExplorerDriver(LocalWebBrowse { BrowserCommandLineArguments = "-private" }; - options.BrowserVersion = factory.Options.TryGetOrDefault(nameof(options.BrowserVersion), "stable"); + options.BrowserVersion = factory.Options.TryGet(nameof(options.BrowserVersion)); return new InternetExplorerDriver(options); } } diff --git a/src/Integrations/Riganti.Selenium.xUnit/XunitTestSuiteRunner.cs b/src/Integrations/Riganti.Selenium.xUnit/XunitTestSuiteRunner.cs index f997524a..6f6a3fb8 100644 --- a/src/Integrations/Riganti.Selenium.xUnit/XunitTestSuiteRunner.cs +++ b/src/Integrations/Riganti.Selenium.xUnit/XunitTestSuiteRunner.cs @@ -23,30 +23,4 @@ public override void RunInAllBrowsers(ISeleniumTest testClass, Action "This reporter is a bit hack to close all resources when test execution ends."; - - // public bool IsEnvironmentallyEnabled => true; - - // public string RunnerSwitch => "riganti-selenium"; - - // public IMessageSink CreateMessageHandler(IRunnerLogger logger) - // { - // return new SeleniumMessageSink(); - // } - //} - //public class SeleniumMessageSink : IMessageSink - //{ - // public bool OnMessage(IMessageSinkMessage message) - // { - // if (message is TestAssemblyExecutionFinished) - // { - // if (Debugger.IsAttached) - // Debugger.Break(); - // } - // return true; - // } - //} } \ No newline at end of file diff --git a/src/Tests/Riganti.Selenium.Core.Samples.Assert.Tests/seleniumconfig.json b/src/Tests/Riganti.Selenium.Core.Samples.Assert.Tests/seleniumconfig.json index 1c93c9af..272c0ed3 100644 --- a/src/Tests/Riganti.Selenium.Core.Samples.Assert.Tests/seleniumconfig.json +++ b/src/Tests/Riganti.Selenium.Core.Samples.Assert.Tests/seleniumconfig.json @@ -1,8 +1,10 @@ { "factories": { "chrome:fast": { - "capabilities": [ "--window-size=1920,1080" , "--headless", "--disable-gpu" ], - "BrowserVersion": "124" + "capabilities": [ "--window-size=1920,1080", "--headless", "--disable-gpu" ], + "Options": { + "BrowserVersion": "124" + } } //"firefox:dev": { //} diff --git a/src/Tests/Riganti.Selenium.Core.Samples.Tests/Profiles/seleniumconfig.chrome.json b/src/Tests/Riganti.Selenium.Core.Samples.Tests/Profiles/seleniumconfig.chrome.json index 3d5c2f1c..bd6d19b5 100644 --- a/src/Tests/Riganti.Selenium.Core.Samples.Tests/Profiles/seleniumconfig.chrome.json +++ b/src/Tests/Riganti.Selenium.Core.Samples.Tests/Profiles/seleniumconfig.chrome.json @@ -1,7 +1,10 @@ { "factories": { "chrome:fast": { - "capabilities": [ "--no-sandbox" ] + "capabilities": [ "--no-sandbox" ], + "Options": { + "BrowserVersion": "124" + } } }, "baseUrls": [ diff --git a/src/Tests/Riganti.Selenium.Core.Samples.Tests/SeleniumManagerTests.cs b/src/Tests/Riganti.Selenium.Core.Samples.Tests/SeleniumManagerTests.cs new file mode 100644 index 00000000..3c329f9d --- /dev/null +++ b/src/Tests/Riganti.Selenium.Core.Samples.Tests/SeleniumManagerTests.cs @@ -0,0 +1,36 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json; +using OpenQA.Selenium; + +[TestClass] +public class SeleniumManagerTests +{ + [TestMethod] + public void GetBinariesVersion113() + { + var data1 = SeleniumManager.BinaryPaths("--browser firefox --driver geckodriver --browser-version 113"); + Console.WriteLine("Firefox binaries: " + JsonConvert.SerializeObject(data1)); + Assert.IsNotNull(data1["browser_path"]); + Assert.IsNotNull(data1["driver_path"]); + + var data2 = SeleniumManager.BinaryPaths("--browser chrome --driver chromedriver --browser-version 113"); + Console.WriteLine("Chrome binaries: " + JsonConvert.SerializeObject(data2)); + Assert.IsNotNull(data2["browser_path"]); + Assert.IsNotNull(data2["driver_path"]); + } + + [TestMethod] + public void GetBinariesVersionStable() + { + var data1 = SeleniumManager.BinaryPaths("--browser firefox --driver geckodriver --browser-version stable"); + Console.WriteLine("Firefox binaries: " + JsonConvert.SerializeObject(data1)); + Assert.IsNotNull(data1["browser_path"]); + Assert.IsNotNull(data1["driver_path"]); + + var data2 = SeleniumManager.BinaryPaths("--browser chrome --driver chromedriver --browser-version stable"); + Console.WriteLine("Chrome binaries: " + JsonConvert.SerializeObject(data2)); + Assert.IsNotNull(data2["browser_path"]); + Assert.IsNotNull(data2["driver_path"]); + } +} \ No newline at end of file diff --git a/src/Tests/Riganti.Selenium.Core.Samples.Tests/seleniumconfig.json b/src/Tests/Riganti.Selenium.Core.Samples.Tests/seleniumconfig.json index 57398adc..ed146148 100644 --- a/src/Tests/Riganti.Selenium.Core.Samples.Tests/seleniumconfig.json +++ b/src/Tests/Riganti.Selenium.Core.Samples.Tests/seleniumconfig.json @@ -2,11 +2,14 @@ "factories": { "chrome:fast": { "capabilities": [ "--window-size=1920,1080", "--headless", "--disable-gpu" ], - "BrowserVersion": "124" + "Options": { + "BrowserVersion": "124" + } }, //"firefox:fast": { - // "capabilities": [ "--window-size=1920,1080", "--headless", "--disable-gpu" ], - // "BrowserVersion": "stable" + // "Options": { + // "BrowserVersion": "104" + // } //} //"chrome:coordinator": { // "options": { diff --git a/src/Tests/Riganti.Selenium.Core.UnitTests/SeleniumManagerTests.cs b/src/Tests/Riganti.Selenium.Core.UnitTests/SeleniumManagerTests.cs new file mode 100644 index 00000000..decc18c6 --- /dev/null +++ b/src/Tests/Riganti.Selenium.Core.UnitTests/SeleniumManagerTests.cs @@ -0,0 +1,22 @@ +using System; +using System.Text.Json; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium; + +[TestClass] +public class SeleniumManagerTests +{ + [TestMethod] + public void GetBinaries() + { + var data1 = SeleniumManager.BinaryPaths("--browser firefox --driver geckodriver --browser-version 104"); + Console.WriteLine("Firefox binaries: " + JsonSerializer.Serialize(data1)); + Assert.IsNotNull(data1["browser_path"]); + Assert.IsNotNull(data1["driver_path"]); + + var data2 = SeleniumManager.BinaryPaths("--browser chrome --driver chromedriver --browser-version 104"); + Console.WriteLine("Chrome binaries: " + JsonSerializer.Serialize(data2)); + Assert.IsNotNull(data2["browser_path"]); + Assert.IsNotNull(data2["driver_path"]); + } +} \ No newline at end of file diff --git a/src/Tests/Riganti.Selenium.Sandbox/seleniumconfig.json b/src/Tests/Riganti.Selenium.Sandbox/seleniumconfig.json index f44678e6..04e0096a 100644 --- a/src/Tests/Riganti.Selenium.Sandbox/seleniumconfig.json +++ b/src/Tests/Riganti.Selenium.Sandbox/seleniumconfig.json @@ -1,7 +1,9 @@ { "factories": { "firefox:fast": { - "BrowserVersion": "stable" + "Options": { + "BrowserVersion": "stable" + } } }, "baseUrls": [