diff --git a/examples/dotnet/SeleniumDocs/Browsers/EdgeTest.cs b/examples/dotnet/SeleniumDocs/Browsers/EdgeTest.cs index a5782535a05c..6d6711dd9c8f 100644 --- a/examples/dotnet/SeleniumDocs/Browsers/EdgeTest.cs +++ b/examples/dotnet/SeleniumDocs/Browsers/EdgeTest.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; +using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; using OpenQA.Selenium.Chromium; @@ -18,11 +19,18 @@ public class EdgeTest [TestCleanup] public void Cleanup() { + driver?.Quit(); + if (_logLocation != null && File.Exists(_logLocation)) { - File.Delete(_logLocation); + try + { + File.Delete(_logLocation); + } + catch (IOException) + { + } } - driver.Quit(); } [TestMethod] @@ -94,8 +102,9 @@ public void LogsToFile() service.LogPath = GetLogLocation(); driver = new EdgeDriver(service, options); - driver.Quit(); // Close the Service log file before reading - var lines = File.ReadLines(GetLogLocation()); + driver.Quit(); + service.Dispose(); + var lines = ReadLogLines(GetLogLocation()); Assert.IsNotNull(lines.FirstOrDefault(line => line.Contains("Starting Microsoft Edge WebDriver"))); } @@ -111,8 +120,9 @@ public void LogsLevel() driver = new EdgeDriver(service, options); - driver.Quit(); // Close the Service log file before reading - var lines = File.ReadLines(GetLogLocation()); + driver.Quit(); + service.Dispose(); + var lines = ReadLogLines(GetLogLocation()); Assert.IsNotNull(lines.FirstOrDefault(line => line.Contains("[DEBUG]:"))); } @@ -130,8 +140,9 @@ public void ConfigureDriverLogs() driver = new EdgeDriver(service, options); - driver.Quit(); // Close the Service log file before reading - var lines = File.ReadLines(GetLogLocation()); + driver.Quit(); + service.Dispose(); + var lines = ReadLogLines(GetLogLocation()); var regex = new Regex(@"\[\d\d-\d\d-\d\d\d\d \d\d:\d\d:\d\d\.\d+\]"); Assert.IsNotNull(lines.FirstOrDefault(line => regex.Matches(line).Count > 0)); } @@ -148,12 +159,31 @@ public void DisableBuildCheck() service.DisableBuildCheck = true; driver = new EdgeDriver(service, options); - driver.Quit(); // Close the Service log file before reading + driver.Quit(); + service.Dispose(); var expected = "[WARNING]: You are using an unsupported command-line switch: --disable-build-check"; - var lines = File.ReadLines(GetLogLocation()); + var lines = ReadLogLines(GetLogLocation()); Assert.IsNotNull(lines.FirstOrDefault(line => line.Contains(expected))); } + private static string[] ReadLogLines(string path) + { + const int maxAttempts = 20; + for (var attempt = 1; attempt <= maxAttempts; attempt++) + { + try + { + return File.ReadAllLines(path); + } + catch (IOException) when (attempt < maxAttempts) + { + Thread.Sleep(500); + } + } + + return File.ReadAllLines(path); + } + private string GetLogLocation() { if (string.IsNullOrEmpty(_logLocation) && !File.Exists(_logLocation)) diff --git a/examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs b/examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs index 618e5361ecce..4d07da3a3b33 100644 --- a/examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs +++ b/examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs @@ -53,5 +53,20 @@ public void SetPageLoadStrategyNone() driver.Quit(); } } + [TestMethod] + public void SetUnhandledPromptBehavior() + { + var chromeOptions = new ChromeOptions(); + chromeOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.DismissAndNotify; + IWebDriver driver = new ChromeDriver(chromeOptions); + try + { + driver.Navigate().GoToUrl("https://selenium.dev"); + } + finally + { + driver.Quit(); + } + } } -} \ No newline at end of file +} diff --git a/website_and_docs/content/documentation/webdriver/drivers/options.en.md b/website_and_docs/content/documentation/webdriver/drivers/options.en.md index 48f82e72d06e..6e7355d60471 100644 --- a/website_and_docs/content/documentation/webdriver/drivers/options.en.md +++ b/website_and_docs/content/documentation/webdriver/drivers/options.en.md @@ -412,7 +412,7 @@ user prompt encounters at the remote-end. This is defined by {{< gh-codeblock path="/examples/python/tests/drivers/test_options.py#L51-53">}} {{% /tab %}} {{< tab header="CSharp" >}} -{{< badge-code >}} +{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs#L59-L60">}} {{< /tab >}} {{< tab header="Ruby" >}} {{< gh-codeblock path="/examples/ruby/spec/drivers/options_spec.rb#L60-L61" >}}