-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebDriverFactoryIntegrationTests.cs
More file actions
67 lines (59 loc) · 2.71 KB
/
WebDriverFactoryIntegrationTests.cs
File metadata and controls
67 lines (59 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using OpenQA.Selenium;
namespace CSF.Extensions.WebDriver.Factories;
[TestFixture,Parallelizable]
public class WebDriverFactoryIntegrationTests
{
[Test]
public void GetDefaultWebDriverShouldThrowAnExceptionBecauseOfAnInvalidUrlScheme()
{
var services = GetServiceProvider();
var driverFactory = services.GetRequiredService<IGetsWebDriver>();
Assert.That(() => driverFactory.GetDefaultWebDriver(), Throws.InstanceOf<NotSupportedException>().And.Message.Contains("'invalid'"));
}
[Test]
public void GetDefaultWebDriverAfterConfigurationCallbackShouldThrowAnExceptionBecauseOfANonsenseUrlScheme()
{
var services = GetServiceProvider(o => o.SelectedConfiguration = "DefaultNonsense");
var driverFactory = services.GetRequiredService<IGetsWebDriver>();
Assert.That(() => driverFactory.GetDefaultWebDriver(), Throws.InstanceOf<NotSupportedException>().And.Message.Contains("'nonsense'"));
}
[Test]
public void GetDefaultWebDriverShouldReturnADriverProxyWithIdentification()
{
var services = GetServiceProvider(o => o.SelectedConfiguration = "DefaultFake");
var driverFactory = services.GetRequiredService<IGetsWebDriver>();
using var driver = driverFactory.GetDefaultWebDriver();
Assert.That(() => driver.WebDriver.GetBrowserId(), Is.Not.Null);
}
[Test]
public void DriverTypeNorOptionsTypeShouldBeMandatoryIfACustomFactoryTypeIsSpecified()
{
var services = GetServiceProvider(o => o.SelectedConfiguration = "OmittedDriverAndOptionsType");
var driverFactory = services.GetRequiredService<IGetsWebDriver>();
using var driver = driverFactory.GetDefaultWebDriver();
Assert.That(() => driver.WebDriver.GetBrowserId(), Is.Not.Null);
}
IServiceProvider GetServiceProvider(Action<WebDriverCreationOptionsCollection>? configureOptions = null)
{
var services = new ServiceCollection();
services.AddSingleton(GetConfiguration());
services.AddWebDriverFactory(configureOptions: configureOptions);
services.AddLogging();
return services.BuildServiceProvider();
}
IConfiguration GetConfiguration()
{
return new ConfigurationBuilder()
.AddJsonFile("appsettings.WebDriverFactoryIntegrationTests.json")
.Build();
}
public class FakeWebDriverFactory : ICreatesWebDriverFromOptions
{
public WebDriverAndOptions GetWebDriver(WebDriverCreationOptions options, Action<DriverOptions>? supplementaryConfiguration = null)
{
return new(Mock.Of<IWebDriver>(), Mock.Of<DriverOptions>());
}
}
}