Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 40 additions & 10 deletions examples/dotnet/SeleniumDocs/Browsers/EdgeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
}
Comment thread
diemol marked this conversation as resolved.
}
driver.Quit();
}

[TestMethod]
Expand Down Expand Up @@ -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")));
}

Expand All @@ -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]:")));
}

Expand All @@ -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));
}
Expand All @@ -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))
Expand Down
17 changes: 16 additions & 1 deletion examples/dotnet/SeleniumDocs/Drivers/OptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,20 @@ public void SetPageLoadStrategyNone()
driver.Quit();
}
}
[TestMethod]
public void SetUnhandledPromptBehavior()
{
var chromeOptions = new ChromeOptions();
chromeOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.DismissAndNotify;
Comment thread
diemol marked this conversation as resolved.
IWebDriver driver = new ChromeDriver(chromeOptions);
try
{
driver.Navigate().GoToUrl("https://selenium.dev");
}
Comment thread
diemol marked this conversation as resolved.
finally
{
driver.Quit();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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" >}}
Expand Down
Loading