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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<ItemGroup>
<Content Include="appsettings.*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,55 @@ public void DriverTypeNorOptionsTypeShouldBeMandatoryIfACustomFactoryTypeIsSpeci
Assert.That(() => driver.WebDriver.GetBrowserId(), Is.Not.Null);
}

IServiceProvider GetServiceProvider(Action<WebDriverCreationOptionsCollection>? configureOptions = null)
[Test]
public void GetWebDriverShouldReturnADriverWithTheCorrectQuirksForChrome()
{
var services = GetServiceProvider(extraRegistrations: services => services.AddWebDriverQuirks(GetCommonBrowserQuirks()));

var driverFactory = services.GetRequiredService<IGetsWebDriver>();
using var driver = driverFactory.GetWebDriver("Chrome");

Assert.Multiple(() =>
{
Assert.That(driver.WebDriver.HasQuirk("IAmChrome"), Is.True, "Chrome quirk");
Assert.That(driver.WebDriver.HasQuirk("IAmFirefox"), Is.False, "Firefox quirk");
});
}

[Test]
public void GetWebDriverShouldReturnADriverWithTheCorrectQuirksForFirefox()
{
var services = GetServiceProvider(extraRegistrations: services => services.AddWebDriverQuirks(GetCommonBrowserQuirks()));

var driverFactory = services.GetRequiredService<IGetsWebDriver>();
using var driver = driverFactory.GetWebDriver("Firefox");

Assert.Multiple(() =>
{
Assert.That(driver.WebDriver.HasQuirk("IAmChrome"), Is.False, "Chrome quirk");
Assert.That(driver.WebDriver.HasQuirk("IAmFirefox"), Is.True, "Firefox quirk");
});
}

Quirks.QuirksData GetCommonBrowserQuirks()
{
return new ()
{
Quirks = new Dictionary<string, Quirks.BrowserInfoCollection>
{
{ "IAmChrome", new () { AffectedBrowsers = new HashSet<Quirks.BrowserInfo>() { new () { Name = "chrome" } } } },
{ "IAmFirefox", new () { AffectedBrowsers = new HashSet<Quirks.BrowserInfo>() { new () { Name = "firefox" } } } },
}
};
}

IServiceProvider GetServiceProvider(Action<WebDriverCreationOptionsCollection>? configureOptions = null,
Action<IServiceCollection>? extraRegistrations = null)
{
var services = new ServiceCollection();
services.AddSingleton(GetConfiguration());
services.AddWebDriverFactory(configureOptions: configureOptions);
extraRegistrations?.Invoke(services);
services.AddLogging();
return services.BuildServiceProvider();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public void MatchesShouldReturnTrueWhenOnlyTheBrowserNameMatches(BrowserInfoMatc
Assert.That(() => sut.Matches(browserId, browserInfo), Is.True);
}

[Test,AutoMoqData]
public void MatchesShouldUseACaseInsensitiveMatchForBrowserName(BrowserInfoMatcher sut)
{
var browserId = new BrowserId("FOOBROWSER", "BarPlatform", MissingBrowserVersion.Instance);
var browserInfo = new BrowserInfo { Name = "foobrowser" };
Assert.That(() => sut.Matches(browserId, browserInfo), Is.True);
}

[Test,AutoMoqData]
public void MatchesShouldReturnFalseIfTheBrowserNameDoesNotMatch(BrowserInfoMatcher sut)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
},
"OmittedDriverAndOptionsType": {
"DriverFactoryType": "CSF.Extensions.WebDriver.Factories.WebDriverFactoryIntegrationTests+FakeWebDriverFactory, CSF.Extensions.WebDriver.Tests"
},
"Chrome": {
"DriverType": "ChromeDriver",
"AddBrowserQuirks": "True"
},
"Firefox": {
"DriverType": "FirefoxDriver",
"AddBrowserQuirks": "True"
}
},
"SelectedConfiguration": "DefaultInvalid"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public WebDriverCreationOptions GetDriverConfiguration(IConfigurationSection con
DriverFactoryType = configuration.GetValue<string>(nameof(WebDriverCreationOptions.DriverFactoryType)),
};

if(configuration.GetSection(nameof(WebDriverCreationOptions.AddBrowserIdentification)).Exists())
creationOptions.AddBrowserIdentification = configuration.GetValue<bool>(nameof(WebDriverCreationOptions.AddBrowserIdentification));

if(configuration.GetSection(nameof(WebDriverCreationOptions.AddBrowserQuirks)).Exists())
creationOptions.AddBrowserQuirks = configuration.GetValue<bool>(nameof(WebDriverCreationOptions.AddBrowserQuirks));

if(!TryGetDriverType(creationOptions, configuration, out var driverType))
return null;

Expand Down
Loading