Skip to content

Commit 96c02b2

Browse files
authored
Update to Selenium 4.19.0 (#116)
* Update to Selenium 4.19.0 and use .NET 8.0 in Tests project * Migrate to NUnit 4, use new language constructions from suggestions * Fix consistency/maintainability coding issues
1 parent 0c5c863 commit 96c02b2

30 files changed

+222
-254
lines changed

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Aquality.Selenium.Core.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
<ItemGroup>
5050
<PackageReference Include="DotNetSeleniumExtras.PageObjects" Version="3.11.0" />
5151
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
52-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
52+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
5353
<PackageReference Include="NLog" Version="5.2.8" />
54-
<PackageReference Include="Selenium.Support" Version="4.17.0" />
55-
<PackageReference Include="Selenium.WebDriver" Version="4.17.0" />
56-
<PackageReference Include="SkiaSharp" Version="2.88.7" />
54+
<PackageReference Include="Selenium.Support" Version="4.19.0" />
55+
<PackageReference Include="Selenium.WebDriver" Version="4.19.0" />
56+
<PackageReference Include="SkiaSharp" Version="2.88.8" />
5757
</ItemGroup>
5858
</Project>

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/AqualityServicesTests.cs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@ public class AqualityServicesTests
1919
[Test]
2020
public void Should_BePossibleTo_RegisterCustomServices()
2121
{
22-
Assert.IsInstanceOf<TestTimeoutConfiguration>(TestAqualityServices.ServiceProvider.GetService<ITimeoutConfiguration>());
22+
Assert.That(TestAqualityServices.ServiceProvider.GetService<ITimeoutConfiguration>(), Is.InstanceOf<TestTimeoutConfiguration>());
2323
}
2424

2525
[Test]
2626
public void Should_BePossibleTo_GetCustomValues()
2727
{
2828
var timeoutConfiguration = TestAqualityServices.ServiceProvider.GetService<ITimeoutConfiguration>() as TestTimeoutConfiguration;
29-
Assert.AreEqual(SpecialTimeoutValue, timeoutConfiguration.CustomTimeout);
29+
Assert.That(timeoutConfiguration.CustomTimeout, Is.EqualTo(SpecialTimeoutValue));
3030
}
3131

3232
[Test]
3333
public void Should_BePossibleTo_GetCustomLoggerValues()
3434
{
3535
TestAqualityServices.SetStartup(new CustomStartup());
3636
var timeoutConfiguration = TestAqualityServices.ServiceProvider.GetService<ILoggerConfiguration>() as CustomLoggerConfiguration;
37-
Assert.AreEqual(SpecialLogger, timeoutConfiguration.CustomLogger);
37+
Assert.That(timeoutConfiguration.CustomLogger, Is.EqualTo(SpecialLogger));
3838
}
3939

4040
[Test]
4141
public void Should_BePossibleTo_RegisterCustomServices_WithCustomSettingsFile()
4242
{
43-
Assert.AreEqual(SpecialLanguageValue, TestAqualityServices.ServiceProvider.GetService<ILoggerConfiguration>().Language);
43+
Assert.That(TestAqualityServices.ServiceProvider.GetService<ILoggerConfiguration>().Language, Is.EqualTo(SpecialLanguageValue));
4444
}
4545

4646
private class TestAqualityServices : AqualityServices<IApplication>
4747
{
48-
private static ThreadLocal<TestStartup> startup = new ThreadLocal<TestStartup>();
48+
private static readonly ThreadLocal<TestStartup> startup = new();
4949

5050
private static IApplication Application => GetApplication(StartApplicationFunction, () => startup.Value.ConfigureServices(new ServiceCollection(), services => Application));
5151

@@ -85,24 +85,14 @@ public override IServiceCollection ConfigureServices(IServiceCollection services
8585
}
8686
}
8787

88-
private class TestTimeoutConfiguration : TimeoutConfiguration
88+
private class TestTimeoutConfiguration(ISettingsFile settingsFile) : TimeoutConfiguration(settingsFile)
8989
{
90-
public TestTimeoutConfiguration(ISettingsFile settingsFile) : base(settingsFile)
91-
{
92-
CustomTimeout = SpecialTimeoutValue;
93-
}
94-
95-
public TimeSpan CustomTimeout { get; }
90+
public TimeSpan CustomTimeout { get; } = SpecialTimeoutValue;
9691
}
9792

98-
private class CustomLoggerConfiguration : LoggerConfiguration
93+
private class CustomLoggerConfiguration(ISettingsFile settingsFile) : LoggerConfiguration(settingsFile)
9994
{
100-
public CustomLoggerConfiguration(ISettingsFile settingsFile) : base(settingsFile)
101-
{
102-
CustomLogger = SpecialLogger;
103-
}
104-
105-
public string CustomLogger { get; }
95+
public string CustomLogger { get; } = SpecialLogger;
10696
}
10797
}
10898
}

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/Browser/ApplicationNotStartedTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Aquality.Selenium.Core.Tests.Applications.Browser
1313
public class ApplicationNotStartedTests : TestWithBrowser
1414
{
1515
private static readonly Type[] TypesNotRequireApplication =
16-
{
16+
[
1717
typeof(IElementActionRetrier),
1818
typeof(IConditionalWait),
1919
typeof(Logger),
@@ -24,13 +24,13 @@ public class ApplicationNotStartedTests : TestWithBrowser
2424
typeof(ITimeoutConfiguration),
2525
typeof(ILoggerConfiguration),
2626
typeof(IRetryConfiguration)
27-
};
27+
];
2828

2929
[TestCaseSource(nameof(TypesNotRequireApplication))]
3030
public void Should_NotStartApplication_ForServiceResolving(Type type)
3131
{
32-
Assert.IsNotNull(ServiceProvider.GetRequiredService(type));
33-
Assert.IsFalse(AqualityServices.IsApplicationStarted);
32+
Assert.That(ServiceProvider.GetRequiredService(type), Is.Not.Null);
33+
Assert.That(AqualityServices.IsApplicationStarted, Is.False);
3434
}
3535
}
3636
}

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/Browser/CachedElementTests.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,38 @@ public class CachedElementTests : TestWithBrowser
1616
private static readonly By ContentLoc = By.Id("checkbox");
1717
private static readonly By StartLoc = By.XPath("//*[@id='start']//button");
1818
private static readonly By LoadingLoc = By.Id("loading");
19-
private static readonly Uri DynamicContentUrl = new Uri($"{TestSite}/dynamic_controls");
20-
private static readonly Uri DynamicLoadingUrl = new Uri($"{TestSite}/dynamic_loading/1");
19+
private static readonly Uri DynamicContentUrl = new($"{TestSite}/dynamic_controls");
20+
private static readonly Uri DynamicLoadingUrl = new($"{TestSite}/dynamic_loading/1");
2121

2222
private const string ElementCacheVariableName = "elementCache.isEnabled";
2323

2424
private static readonly Func<IElementStateProvider, bool>[] StateFunctionsFalseWhenElementStale
25-
= new Func<IElementStateProvider, bool>[]
26-
{
25+
=
26+
[
2727
state => state.IsDisplayed,
2828
state => state.IsExist,
2929
state => !state.WaitForNotDisplayed(TimeSpan.Zero),
3030
state => !state.WaitForNotExist(TimeSpan.Zero),
31-
};
31+
];
3232

3333
private static readonly Func<IElementStateProvider, bool>[] StateFunctionsTrueWhenElementStaleWhichRetriveElement
34-
= new Func<IElementStateProvider, bool>[]
35-
{
34+
=
35+
[
3636
state => state.IsEnabled,
3737
state => state.IsClickable,
3838
state => state.WaitForDisplayed(TimeSpan.Zero),
3939
state => state.WaitForExist(TimeSpan.Zero),
4040
state => state.WaitForEnabled(TimeSpan.Zero),
4141
state => !state.WaitForNotEnabled(TimeSpan.Zero),
42-
};
42+
];
4343

4444
private static readonly Func<IElementStateProvider, bool>[] StateFunctionsThrowNoSuchElementException
45-
= new Func<IElementStateProvider, bool>[]
46-
{
45+
=
46+
[
4747
state => state.IsEnabled,
4848
state => state.WaitForEnabled(TimeSpan.Zero),
4949
state => !state.WaitForNotEnabled(TimeSpan.Zero),
50-
};
50+
];
5151

5252
private static IConditionalWait ConditionalWait => AqualityServices.ServiceProvider.GetRequiredService<IConditionalWait>();
5353

@@ -80,7 +80,7 @@ public void Should_ReturnFalse_AtWaitForDisplayed_WhenElementIsNotDisplayed()
8080
var loader = new Label(LoadingLoc, "loader", ElementState.Displayed);
8181
StartLoading();
8282
WaitForLoading(loader);
83-
Assert.IsFalse(loader.State.WaitForDisplayed(TimeSpan.Zero), nameof(Should_ReturnFalse_AtWaitForDisplayed_WhenElementIsNotDisplayed));
83+
Assert.That(loader.State.WaitForDisplayed(TimeSpan.Zero), Is.False, nameof(Should_ReturnFalse_AtWaitForDisplayed_WhenElementIsNotDisplayed));
8484
}
8585

8686
[Test]
@@ -89,7 +89,7 @@ public void Should_ReturnTrue_AtWaitForExist_WhenElementIsNotDisplayed()
8989
var loader = new Label(LoadingLoc, "loader", ElementState.Displayed);
9090
StartLoading();
9191
WaitForLoading(loader);
92-
Assert.IsTrue(loader.State.WaitForExist(TimeSpan.Zero), nameof(Should_ReturnTrue_AtWaitForExist_WhenElementIsNotDisplayed));
92+
Assert.That(loader.State.WaitForExist(TimeSpan.Zero), nameof(Should_ReturnTrue_AtWaitForExist_WhenElementIsNotDisplayed));
9393
}
9494

9595
[Test]
@@ -98,10 +98,10 @@ public void Should_BeStale_WhenBecameInvisible()
9898
StartLoading();
9999
var loader = new Label(LoadingLoc, "loader", ElementState.Displayed);
100100
Assume.That(loader.State.WaitForDisplayed(), "Loader should be displayed in the beginning");
101-
Assert.IsTrue(ConditionalWait.WaitFor(() => loader.Cache.IsStale), "Loader should become invisible and be treated as stale");
102-
Assert.IsFalse(loader.State.IsDisplayed, "Invisible loader should be not displayed");
103-
Assert.IsFalse(loader.State.IsExist, "Loader that was displayed previously and become invisible should be treated as disappeared");
104-
Assert.IsTrue(loader.State.WaitForExist(TimeSpan.Zero), "When waiting for existance, we should get an actual element's state");
101+
Assert.That(ConditionalWait.WaitFor(() => loader.Cache.IsStale), "Loader should become invisible and be treated as stale");
102+
Assert.That(loader.State.IsDisplayed, Is.False, "Invisible loader should be not displayed");
103+
Assert.That(loader.State.IsExist, Is.False, "Loader that was displayed previously and become invisible should be treated as disappeared");
104+
Assert.That(loader.State.WaitForExist(TimeSpan.Zero), "When waiting for existance, we should get an actual element's state");
105105
}
106106

107107
[Test]
@@ -113,7 +113,7 @@ public void Should_RefreshElement_WhenItIsStale()
113113
var exToString = example.GetElement().ToString();
114114
AqualityServices.Application.Driver.Navigate().Refresh();
115115
var newToString = example.GetElement().ToString();
116-
Assert.AreNotEqual(exToString, newToString);
116+
Assert.That(newToString, Is.Not.EqualTo(exToString));
117117
}
118118

119119
[Test]
@@ -159,7 +159,7 @@ private static void AssertStateConditionAfterReopen(Func<IElementStateProvider,
159159

160160
Assume.That(testElement, Is.Not.Null);
161161
OpenDynamicContent();
162-
Assert.AreEqual(expectedValue, stateCondition(testElement.State),
162+
Assert.That(stateCondition(testElement.State), Is.EqualTo(expectedValue),
163163
"Element state condition is not expected after reopening the window");
164164
}
165165

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/Browser/ConditionalWaitTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ namespace Aquality.Selenium.Core.Tests.Applications.Browser
1313
{
1414
public class ConditionalWaitTests : TestWithBrowser
1515
{
16-
private static readonly Uri WikiURL = new Uri("https://wikipedia.org");
16+
private static readonly Uri WikiURL = new("https://wikipedia.org");
1717
private static readonly TimeSpan LittleTimeout = TimeSpan.FromSeconds(1);
1818
private static readonly TimeSpan PollingInterval = AqualityServices.ServiceProvider.GetRequiredService<ITimeoutConfiguration>().PollingInterval;
1919

2020
private static readonly Action<Func<bool>, IList<Type>>[] WaitWithHandledException
21-
= new Action<Func<bool>, IList<Type>>[]
22-
{
21+
=
22+
[
2323
(condition, handledExceptions) => ConditionalWait.WaitFor(condition, timeout: LittleTimeout, exceptionsToIgnore: handledExceptions),
2424
(condition, handledExceptions) => ConditionalWait.WaitFor(driver => condition(), timeout: LittleTimeout, exceptionsToIgnore: handledExceptions),
2525
(condition, handledExceptions) => ConditionalWait.WaitForTrue(condition, timeout: LittleTimeout, exceptionsToIgnore: handledExceptions)
26-
};
26+
];
2727

2828
private static readonly Func<Func<bool>, IList<Type>, Task>[] WaitWithHandledExceptionAsync
29-
= new Func<Func<bool>, IList<Type>, Task>[]
30-
{
29+
=
30+
[
3131
(condition, handledExceptions) => ConditionalWait.WaitForAsync(condition, timeout: LittleTimeout, exceptionsToIgnore: handledExceptions),
3232
(condition, handledExceptions) => ConditionalWait.WaitForTrueAsync(condition, timeout: LittleTimeout, exceptionsToIgnore: handledExceptions)
33-
};
33+
];
3434

3535
private static IConditionalWait ConditionalWait => AqualityServices.ServiceProvider.GetRequiredService<IConditionalWait>();
3636

@@ -97,7 +97,7 @@ public void Should_BePossibleTo_UseConditionalWait_WithElementFinder()
9797
{
9898
bool elementFinderCondition() => ServiceProvider.GetRequiredService<IElementFinder>()
9999
.FindElements(By.XPath("//*[contains(., 'wikipedia')]"), timeout: LittleTimeout).Count > 0;
100-
Assert.IsFalse(elementFinderCondition());
100+
Assert.That(elementFinderCondition(), Is.False);
101101
Assert.DoesNotThrow(() => ConditionalWait.WaitFor(driver =>
102102
{
103103
GoToUrl(WikiURL, driver);
@@ -113,9 +113,9 @@ public void Should_BePossibleTo_UseConditionalWait_ForAsyncWaiting()
113113
stopWatch.Start();
114114
Assert.DoesNotThrow(() => returnedResult = ConditionalWait.WaitForAsync(() => result = false, LittleTimeout).Result);
115115
stopWatch.Stop();
116-
Assert.IsFalse(result, $"{nameof(ConditionalWait.WaitForAsync)} should work at least once");
117-
Assert.IsFalse(returnedResult, $"{nameof(ConditionalWait.WaitForAsync)} should return valid result");
118-
Assert.AreEqual(LittleTimeout.TotalSeconds, stopWatch.Elapsed.TotalSeconds, PollingInterval.TotalSeconds * 2,
116+
Assert.That(result, Is.False, $"{nameof(ConditionalWait.WaitForAsync)} should work at least once");
117+
Assert.That(returnedResult, Is.False, $"{nameof(ConditionalWait.WaitForAsync)} should return valid result");
118+
Assert.That(stopWatch.Elapsed.TotalSeconds, Is.EqualTo(LittleTimeout.TotalSeconds).Within(PollingInterval.TotalSeconds * 2),
119119
$"{nameof(ConditionalWait.WaitForAsync)} should wait correct time");
120120
}
121121

@@ -131,9 +131,9 @@ public void Should_BePossibleTo_UseConditionalWait_ForAsyncWaitingForTrue()
131131
$"{nameof(ConditionalWait.WaitForTrueAsync)} should not fail after the calling");
132132
Assume.That(awaitableResult, Is.Not.Null);
133133
Assert.ThrowsAsync<TimeoutException>(async () => await awaitableResult, $"{nameof(ConditionalWait.WaitForTrueAsync)} should throw when awaited");
134-
Assert.IsFalse(result, $"{nameof(ConditionalWait.WaitForTrueAsync)} should work");
134+
Assert.That(result, Is.False, $"{nameof(ConditionalWait.WaitForTrueAsync)} should work");
135135
stopWatch.Stop();
136-
Assert.AreEqual(LittleTimeout.TotalSeconds, stopWatch.Elapsed.TotalSeconds, PollingInterval.TotalSeconds * 2,
136+
Assert.That(stopWatch.Elapsed.TotalSeconds, Is.EqualTo(LittleTimeout.TotalSeconds).Within(PollingInterval.TotalSeconds * 2),
137137
$"{nameof(ConditionalWait.WaitForTrueAsync)} should wait correct time");
138138
}
139139
}

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/Browser/Elements/Label.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44

55
namespace Aquality.Selenium.Core.Tests.Applications.Browser.Elements
66
{
7-
public class Label : WebElement
7+
public class Label(By locator, string name, ElementState state) : WebElement(locator, name, state)
88
{
9-
public Label(By locator, string name, ElementState state) : base(locator, name, state)
10-
{
11-
}
12-
139
protected override string ElementType { get; } = "Label";
1410

1511
public new IElementCacheHandler Cache => base.Cache;

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/Browser/Elements/WebElementFactory.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88

99
namespace Aquality.Selenium.Core.Tests.Applications.Browser.Elements
1010
{
11-
internal class WebElementFactory : ElementFactory
11+
internal class WebElementFactory(IConditionalWait conditionalWait, IElementFinder elementFinder, ILocalizationManager localizationManager) : ElementFactory(conditionalWait, elementFinder, localizationManager)
1212
{
13-
public WebElementFactory(IConditionalWait conditionalWait, IElementFinder elementFinder, ILocalizationManager localizationManager) : base(conditionalWait, elementFinder, localizationManager)
14-
{
15-
}
16-
1713
protected override By GenerateXpathLocator(By baseLocator, IWebElement webElement, int elementIndex)
1814
{
1915
return baseLocator.ToString().StartsWith("By.XPath")

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/Browser/FindChildElementsTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ namespace Aquality.Selenium.Core.Tests.Applications.Browser
99
{
1010
public class FindChildElementsTests : FindElementsTests
1111
{
12-
private readonly Label customParent = new Label(By.XPath("//div[contains(@class,'figure')]"),
12+
private readonly Label customParent = new(By.XPath("//div[contains(@class,'figure')]"),
1313
"custom parent", ElementState.ExistsInAnyState);
1414
protected override By HiddenElementsLoc => By.XPath(".//h5");
1515
protected override By DisplayedElementsLoc => By.XPath(".//img[@alt='User Avatar']");
1616
protected override By NotExistElementLoc => By.XPath(".//div[@class='testtest']");
1717

18-
private static readonly By[] SupportedLocators = new By[]
19-
{
18+
private static readonly By[] SupportedLocators =
19+
[
2020
By.XPath("//img"),
2121
By.XPath(".//img"),
2222
By.TagName("img")
23-
};
23+
];
2424

2525
protected override IList<T> FindElements<T>(By locator, string name = null, ElementSupplier<T> supplier = null,
2626
ElementsCount expectedCount = ElementsCount.Any, ElementState state = ElementState.Displayed)
@@ -34,7 +34,7 @@ public void Should_GetCorrectNumberOfChilds_ForRelativeChildLocator(
3434
{
3535
var expectedCount = 3;
3636
var elementsCount = ElementFactory.FindChildElements<Label>(customParent, childRelativeLocator).Count;
37-
Assert.AreEqual(expectedCount, elementsCount,
37+
Assert.That(elementsCount, Is.EqualTo(expectedCount),
3838
$"Elements count for relative locator [{childRelativeLocator}] should be {expectedCount}");
3939
}
4040

@@ -68,9 +68,9 @@ public void Should_SetXPathLocator_InFindChildElements_IfBothParentAndChildHaveS
6868

6969
private void CheckChildLocatorIsXpathAndStartsFromParent(string childLocatorString)
7070
{
71-
StringAssert.StartsWith("By.XPath", childLocatorString);
71+
Assert.That(childLocatorString, Does.StartWith("By.XPath"));
7272
var parentLocatorString = customParent.Locator.ToString();
73-
StringAssert.Contains(parentLocatorString.Substring(parentLocatorString.IndexOf(':') + 1).Trim(), childLocatorString);
73+
Assert.That(childLocatorString, Contains.Substring(parentLocatorString[(parentLocatorString.IndexOf(':') + 1)..].Trim()));
7474
}
7575
}
7676
}

0 commit comments

Comments
 (0)