Skip to content

Commit 6da6f32

Browse files
authored
Merge pull request #48 from csf-dev/47-hanging-build
WIP #47 - Attempt to fix hanging build
2 parents b1b7dcd + 5f1bc72 commit 6da6f32

4 files changed

Lines changed: 13 additions & 44 deletions

File tree

.appveyor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +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.
710
- choco install chromedriver
11+
- cmd: PATH=C:\ProgramData\chocolatey\lib\chromedriver\tools\chromedriver-win32;%PATH%
812
build_script:
913
- dotnet build
1014
- 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 & 42 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,29 +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-
catch(TargetInvocationException e) when (e is { InnerException: InvalidOperationException })
30-
{
31-
if(e.InnerException.Message.StartsWith("session not created:"))
32-
Assert.Pass("Despite the exception raised, this is only because the wrong version of the driver is installed on the environment running the test; this is more than enough to prove that the driver was being created.");
33-
else
34-
throw;
35-
}
36-
catch(InvalidOperationException invOpEx)
37-
{
38-
if(invOpEx.Message.StartsWith("session not created:"))
39-
Assert.Pass("Despite the exception raised, this is only because the wrong version of the driver is installed on the environment running the test; this is more than enough to prove that the driver was being created.");
40-
else
41-
throw;
42-
}
18+
using var driver = sut.GetWebDriver(options).WebDriver;
19+
Assert.That(driver, Is.Not.Null);
4320
}
4421

4522
[Test,AutoMoqData]
@@ -53,23 +30,7 @@ public void GetWebDriverShouldCustomiseDriverOptionsWithCallbackWhenItIsSpecifie
5330
OptionsFactory = () => driverOptions,
5431
};
5532

56-
try
57-
{
58-
using var driver = sut.GetWebDriver(options, o => o.AddAdditionalOption("Foo", "Bar")).WebDriver;
59-
}
60-
catch (Exception e) when (e is TargetInvocationException { InnerException: DriverServiceNotFoundException } or DriverServiceNotFoundException)
61-
{
62-
// Intentionally ignore this exception; we know it's going to fail but I care only about how the options were manipulated in this test.
63-
}
64-
catch(TargetInvocationException e) when (e is { InnerException: InvalidOperationException })
65-
{
66-
// Intentionally ignore this exception; we know it's going to fail but I care only about how the options were manipulated in this test.
67-
}
68-
catch(InvalidOperationException)
69-
{
70-
// Intentionally ignore this exception; we know it's going to fail but I care only about how the options were manipulated in this test.
71-
}
72-
33+
using var driver = sut.GetWebDriver(options, o => o.AddAdditionalOption("Foo", "Bar")).WebDriver;
7334
Assert.That(driverOptions.ToCapabilities()["Foo"], Is.EqualTo("Bar"));
7435
}
7536
}

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)