Skip to content

Commit f57f391

Browse files
committed
Merge remote-tracking branch 'origin/master' into 43-mandatory-logging
2 parents 703afd3 + 6da6f32 commit f57f391

4 files changed

Lines changed: 14 additions & 23 deletions

File tree

.appveyor.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ init:
44
- cmd: git config --global core.autocrlf true
55
before_build:
66
- dotnet tool update -g docfx
7+
# I need to install ChromeDriver from Chcolatey because the preinstalled ChromeDriver is
8+
# not compatible with the Chrome browser version installed by the Visual Studio 2022 image
9+
# This originally caused tests to fail and also to hang, which caused issue #47.
10+
- choco install chromedriver
11+
- cmd: PATH=C:\ProgramData\chocolatey\lib\chromedriver\tools\chromedriver-win32;%PATH%
712
build_script:
813
- dotnet build
914
- docfx CSF.Extensions.WebDriver.Docs\docfx.json

CSF.Extensions.WebDriver.Tests/Factories/WebDriverFactoryIntegrationTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public void GetDefaultWebDriverShouldReturnADriverProxyWithIdentification()
2828
{
2929
var services = GetServiceProvider(o => o.SelectedConfiguration = "DefaultFake");
3030
var driverFactory = services.GetRequiredService<IGetsWebDriver>();
31-
Assert.That(() => driverFactory.GetDefaultWebDriver().WebDriver.GetBrowserId(), Is.Not.Null);
31+
using var driver = driverFactory.GetDefaultWebDriver();
32+
Assert.That(() => driver.WebDriver.GetBrowserId(), Is.Not.Null);
3233
}
3334

3435
IServiceProvider GetServiceProvider(Action<WebDriverCreationOptionsCollection>? configureOptions = null)
Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Reflection;
2-
using OpenQA.Selenium;
31
using OpenQA.Selenium.Chrome;
42

53
namespace CSF.Extensions.WebDriver.Factories;
@@ -17,16 +15,8 @@ public void GetWebDriverShouldCreateALocalChromeDriverFromAppropriateOptions([St
1715
OptionsFactory = () => new ChromeOptions(),
1816
};
1917

20-
try
21-
{
22-
using var driver = sut.GetWebDriver(options).WebDriver;
23-
Assert.That(driver, Is.Not.Null);
24-
}
25-
catch (Exception e) when (e is TargetInvocationException { InnerException: DriverServiceNotFoundException } or DriverServiceNotFoundException)
26-
{
27-
Assert.Pass("Despite the exception raised, this is only because the driver isn't installed on the environment running the test; this is more than enough to prove that the driver was being created.");
28-
}
29-
18+
using var driver = sut.GetWebDriver(options).WebDriver;
19+
Assert.That(driver, Is.Not.Null);
3020
}
3121

3222
[Test,AutoMoqData]
@@ -40,15 +30,7 @@ public void GetWebDriverShouldCustomiseDriverOptionsWithCallbackWhenItIsSpecifie
4030
OptionsFactory = () => driverOptions,
4131
};
4232

43-
try
44-
{
45-
using var driver = sut.GetWebDriver(options, o => o.AddAdditionalOption("Foo", "Bar")).WebDriver;
46-
}
47-
catch (Exception e) when (e is TargetInvocationException { InnerException: DriverServiceNotFoundException } or DriverServiceNotFoundException)
48-
{
49-
// Intentionally ignore this exception; we know it's going to fail but I care only about how the options were manipulated in this test.
50-
}
51-
33+
using var driver = sut.GetWebDriver(options, o => o.AddAdditionalOption("Foo", "Bar")).WebDriver;
5234
Assert.That(driverOptions.ToCapabilities()["Foo"], Is.EqualTo("Bar"));
5335
}
5436
}

CSF.Extensions.WebDriver/Factories/WebDriverAndOptions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
namespace CSF.Extensions.WebDriver.Factories
55
{
66
/// <summary>A model containing a WebDriver and the <see cref="DriverOptions"/> which were used to create it.</summary>
7-
public class WebDriverAndOptions
7+
public sealed class WebDriverAndOptions : IDisposable
88
{
99
/// <summary>Gets the WebDriver</summary>
1010
public IWebDriver WebDriver { get; }
1111

1212
/// <summary>Gets the <see cref="DriverOptions"/> which were used to create the <see cref="WebDriver"/></summary>
1313
public DriverOptions DriverOptions { get; }
1414

15+
/// <inheritdoc/>
16+
public void Dispose() => WebDriver.Dispose();
17+
1518
/// <summary>
1619
/// Initialises a new instance of <see cref="WebDriverAndOptions"/>.
1720
/// </summary>

0 commit comments

Comments
 (0)