Skip to content

Commit 6232ff8

Browse files
authored
Update to Selenium 4.19.0 (#251)
* Update to Selenium 4.19.0 - Add OpenCvSharp4 runtime for osx_arm64 (Apple Silicon M1 or later) to support ByImage locator on that platform - use .NET 8 in tests project - migrate to NUnit 4 , update assertions - use simplified initialization in tests project * Update azure-pipelines.yml for Azure Pipelines * Make assertion more clear * Fix geolocation test locator and codesmell * Update dismissal of cookie for geolocation test
1 parent 45c2f40 commit 6232ff8

34 files changed

+237
-254
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@
8282
</ItemGroup>
8383

8484
<ItemGroup>
85-
<PackageReference Include="Aquality.Selenium.Core" Version="3.0.6" />
86-
<PackageReference Include="WebDriverManager" Version="2.17.1" />
85+
<PackageReference Include="Aquality.Selenium.Core" Version="3.0.7" />
86+
<PackageReference Include="OpenCvSharp4.runtime.osx_arm64" Version="4.8.1-rc" />
87+
<PackageReference Include="WebDriverManager" Version="2.17.2" />
8788
<PackageReference Include="OpenCvSharp4" Version="4.9.0.20240103" />
8889
<PackageReference Include="OpenCvSharp4.runtime.linux-arm" Version="4.9.0.20240103" />
8990
<PackageReference Include="OpenCvSharp4.runtime.osx.10.15-x64" Version="4.6.0.20230105" />

Aquality.Selenium/tests/Aquality.Selenium.Tests/Aquality.Selenium.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
@@ -29,7 +29,7 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="nunit" Version="3.13.3" />
32+
<PackageReference Include="nunit" Version="4.1.0" />
3333
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
3434
<PrivateAssets>all</PrivateAssets>
3535
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Actions/JsActionsTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void Should_BePossibleTo_Click()
1919
var welcomeForm = new WelcomeForm();
2020
welcomeForm.Open();
2121
welcomeForm.GetExampleLink(AvailableExample.Dropdown).JsActions.Click();
22-
Assert.IsTrue(new DropdownForm().State.WaitForDisplayed(), "Dropdown form should be displayed");
22+
Assert.That(new DropdownForm().State.WaitForDisplayed(), "Dropdown form should be displayed");
2323
}
2424

2525
[Test]
@@ -28,7 +28,7 @@ public void Should_BePossibleTo_ClickAndWait()
2828
var welcomeForm = new WelcomeForm();
2929
welcomeForm.Open();
3030
welcomeForm.GetExampleLink(AvailableExample.Dropdown).JsActions.ClickAndWait();
31-
Assert.IsTrue(new DropdownForm().State.WaitForDisplayed(), "Dropdown form should be displayed");
31+
Assert.That(new DropdownForm().State.WaitForDisplayed(), "Dropdown form should be displayed");
3232
}
3333

3434
[Test]
@@ -39,7 +39,7 @@ public void Should_BePossibleTo_HighlightElement()
3939
var dropdownExample = welcomeForm.GetExampleLink(AvailableExample.Dropdown);
4040
dropdownExample.JsActions.HighlightElement(HighlightState.Highlight);
4141
var border = dropdownExample.GetCssValue("border");
42-
Assert.AreEqual("3px solid rgb(255, 0, 0)", border, "Element should be highlighted");
42+
Assert.That(border, Is.EqualTo("3px solid rgb(255, 0, 0)"), "Element should be highlighted");
4343
}
4444

4545
[Test]
@@ -48,7 +48,7 @@ public void Should_BePossibleTo_HoverMouse()
4848
var menuForm = new JQueryMenuForm();
4949
menuForm.Open();
5050
JQueryMenuForm.EnabledButton.JsActions.HoverMouse();
51-
Assert.IsTrue(JQueryMenuForm.IsEnabledButtonFocused, "Element should be focused after hover");
51+
Assert.That(JQueryMenuForm.IsEnabledButtonFocused, "Element should be focused after hover");
5252
}
5353

5454
[Test]
@@ -64,7 +64,7 @@ public void Should_BePossibleTo_SetFocus()
6464
ForgotPasswordForm.EmailTextBox.JsActions.SetFocus();
6565
ForgotPasswordForm.EmailTextBox.SendKeys(Keys.Delete);
6666
ForgotPasswordForm.EmailTextBox.SendKeys(Keys.Backspace);
67-
Assert.AreEqual(expectedText, ForgotPasswordForm.EmailTextBox.Value, $"One character should be removed from '{currentText}'");
67+
Assert.That(ForgotPasswordForm.EmailTextBox.Value, Is.EqualTo(expectedText), $"One character should be removed from '{currentText}'");
6868
}
6969

7070
[Test]
@@ -74,9 +74,9 @@ public void Should_BePossibleTo_CheckIsElementOnScreen()
7474
hoversForm.Open();
7575
Assert.Multiple(() =>
7676
{
77-
Assert.IsFalse(HoversForm.GetHiddenElement(HoverExample.First, ElementState.ExistsInAnyState).JsActions.IsElementOnScreen(),
77+
Assert.That(HoversForm.GetHiddenElement(HoverExample.First, ElementState.ExistsInAnyState).JsActions.IsElementOnScreen(), Is.False,
7878
$"Hidden element for {HoverExample.First} should be invisible.");
79-
Assert.IsTrue(HoversForm.GetExample(HoverExample.First).JsActions.IsElementOnScreen(),
79+
Assert.That(HoversForm.GetExample(HoverExample.First).JsActions.IsElementOnScreen(),
8080
$"Element for {HoverExample.First} should be visible.");
8181
});
8282
}
@@ -89,15 +89,15 @@ public void Should_BePossibleTo_SetValue()
8989
const string text = "text";
9090
keyPressesForm.InputTextBox.JsActions.SetValue(text);
9191
var actualText = keyPressesForm.InputTextBox.Value;
92-
Assert.AreEqual(text, actualText, $"Text should be '{text}' after setting value via JS");
92+
Assert.That(actualText, Is.EqualTo(text), $"Text should be '{text}' after setting value via JS");
9393
}
9494

9595
[Test]
9696
public void Should_BePossibleTo_GetElementText()
9797
{
9898
var welcomeForm = new WelcomeForm();
9999
welcomeForm.Open();
100-
Assert.AreEqual(WelcomeForm.SubTitle, welcomeForm.SubTitleLabel.JsActions.GetElementText(),
100+
Assert.That(welcomeForm.SubTitleLabel.JsActions.GetElementText(), Is.EqualTo(WelcomeForm.SubTitle),
101101
$"Sub title should be {WelcomeForm.SubTitle}");
102102
}
103103

@@ -108,7 +108,7 @@ public void Should_BePossibleTo_GetXPathLocator()
108108
welcomeForm.Open();
109109
var actualLocator = welcomeForm.SubTitleLabel.JsActions.GetXPath();
110110
const string expectedLocator = "/html/body/DIV[2]/DIV[1]/H2[1]";
111-
Assert.AreEqual(expectedLocator, actualLocator, $"Locator of sub title should be {expectedLocator}");
111+
Assert.That(actualLocator, Is.EqualTo(expectedLocator), $"Locator of sub title should be {expectedLocator}");
112112
}
113113

114114
[Test]
@@ -117,7 +117,7 @@ public void Should_BePossibleTo_GetViewPortCoordinates()
117117
var welcomeForm = new WelcomeForm();
118118
welcomeForm.Open();
119119
var actualPoint = welcomeForm.SubTitleLabel.JsActions.GetViewPortCoordinates();
120-
Assert.IsFalse(actualPoint.IsEmpty, "Coordinates of Sub title should not be empty");
120+
Assert.That(actualPoint.IsEmpty, Is.False, "Coordinates of Sub title should not be empty");
121121
}
122122

123123
[Test]
@@ -148,7 +148,7 @@ public void Should_BePossibleTo_ScrollBy()
148148
Select(item => (int)Math.Round(double.Parse(item.ToString())))
149149
.ToList();
150150
var actualPoint = new Point(currentCoordinates[0], currentCoordinates[1]);
151-
Assert.AreEqual(point, actualPoint, $"Current coordinates should be '{point}'");
151+
Assert.That(actualPoint, Is.EqualTo(point), $"Current coordinates should be '{point}'");
152152
}
153153

154154
[Test]
@@ -163,7 +163,7 @@ public void Should_BePossibleTo_ScrollToTheCenter()
163163
var currentY = AqualityServices.Browser.ExecuteScriptFromFile<object>("Resources.GetElementYCoordinate.js",
164164
welcomeForm.GetExampleLink(AvailableExample.Hovers).GetElement()).ToString();
165165
var coordinateRelatingWindowCenter = double.Parse(windowSize) / 2 - double.Parse(currentY);
166-
Assert.LessOrEqual(Math.Abs(coordinateRelatingWindowCenter), accuracy, "Upper bound of element should be in the center of the page");
166+
Assert.That(Math.Abs(coordinateRelatingWindowCenter), Is.LessThanOrEqualTo(accuracy), "Upper bound of element should be in the center of the page");
167167
}
168168

169169
[Test]

Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Actions/MouseActionsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void Should_BePossibleTo_Click()
1212
var welcomeForm = new WelcomeForm();
1313
welcomeForm.Open();
1414
welcomeForm.GetExampleLink(AvailableExample.Dropdown).MouseActions.Click();
15-
Assert.IsTrue(new DropdownForm().State.WaitForDisplayed(), "Dropdown form should be displayed");
15+
Assert.That(new DropdownForm().State.WaitForDisplayed(), "Dropdown form should be displayed");
1616
}
1717

1818
[Test]
@@ -22,7 +22,7 @@ public void Should_BePossibleTo_DoubleClick()
2222
addRemoveElementsForm.Open();
2323
addRemoveElementsForm.AddButton.MouseActions.DoubleClick();
2424
var addedButtonsCount = addRemoveElementsForm.ListOfDeleteButtons.Count;
25-
Assert.AreEqual(2, addedButtonsCount, "2 elements should be added after double click");
25+
Assert.That(addedButtonsCount, Is.EqualTo(2), "2 elements should be added after double click");
2626
}
2727

2828
[Test]
@@ -40,7 +40,7 @@ public void Should_BePossibleTo_MoveToElement()
4040
var menuForm = new JQueryMenuForm();
4141
menuForm.Open();
4242
JQueryMenuForm.EnabledButton.MouseActions.MoveToElement();
43-
Assert.IsTrue(JQueryMenuForm.IsEnabledButtonFocused, "Element should be focused after move mouse");
43+
Assert.That(JQueryMenuForm.IsEnabledButtonFocused, "Element should be focused after move mouse");
4444
}
4545
}
4646
}

Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/AlertTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Aquality.Selenium.Tests.Integration
77
{
88
internal class AlertTests : UITest
99
{
10-
private readonly JavaScriptAlertsForm alertsForm = new JavaScriptAlertsForm();
10+
private readonly JavaScriptAlertsForm alertsForm = new();
1111

1212
[SetUp]
1313
public void BeforeTest()
@@ -20,15 +20,15 @@ public void Should_BePossibleTo_AcceptAlert()
2020
{
2121
alertsForm.JsAlertButton.Click();
2222
AqualityServices.Browser.HandleAlert(AlertAction.Accept);
23-
Assert.AreEqual("You successfully clicked an alert", alertsForm.ResultLabel.GetText());
23+
Assert.That(alertsForm.ResultLabel.GetText(), Is.EqualTo("You successfully clicked an alert"));
2424
}
2525

2626
[Test]
2727
public void Should_BePossibleTo_AcceptConfirmationAlert()
2828
{
2929
alertsForm.JsConfirmButton.Click();
3030
AqualityServices.Browser.HandleAlert(AlertAction.Accept);
31-
Assert.AreEqual("You clicked: Ok", alertsForm.ResultLabel.GetText());
31+
Assert.That(alertsForm.ResultLabel.GetText(), Is.EqualTo("You clicked: Ok"));
3232
}
3333

3434
[Test]
@@ -50,15 +50,15 @@ public void Should_BePossibleTo_AcceptConfirmationAlert_InWaitFor()
5050
}
5151

5252
});
53-
Assert.AreEqual("You clicked: Ok", alertsForm.ResultLabel.GetText());
53+
Assert.That(alertsForm.ResultLabel.GetText(), Is.EqualTo("You clicked: Ok"));
5454
}
5555

5656
[Test]
5757
public void Should_BePossibleTo_DeclineConfirmationAlert()
5858
{
5959
alertsForm.JsConfirmButton.Click();
6060
AqualityServices.Browser.HandleAlert(AlertAction.Decline);
61-
Assert.AreEqual("You clicked: Cancel", alertsForm.ResultLabel.GetText());
61+
Assert.That(alertsForm.ResultLabel.GetText(), Is.EqualTo("You clicked: Cancel"));
6262
}
6363

6464
[Test]
@@ -67,15 +67,15 @@ public void Should_BePossibleTo_AcceptPromptAlertWithText()
6767
alertsForm.JsPromptButton.Click();
6868
var text = "accept alert text";
6969
AqualityServices.Browser.HandleAlert(AlertAction.Accept, text);
70-
Assert.AreEqual($"You entered: {text}", alertsForm.ResultLabel.GetText());
70+
Assert.That(alertsForm.ResultLabel.GetText(), Is.EqualTo($"You entered: {text}"));
7171
}
7272

7373
[Test]
7474
public void Should_BePossibleTo_DeclinePromptAlertWithText()
7575
{
7676
alertsForm.JsPromptButton.Click();
7777
AqualityServices.Browser.HandleAlert(AlertAction.Decline, "decline alert text");
78-
Assert.AreEqual("You entered: null", alertsForm.ResultLabel.GetText());
78+
Assert.That(alertsForm.ResultLabel.GetText(), Is.EqualTo("You entered: null"));
7979
}
8080

8181
[Test]

Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/BrowserTabsTests.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Aquality.Selenium.Tests.Integration
88
{
99
internal class BrowserTabsTests : UITest
1010
{
11-
private readonly WelcomeForm WelcomeForm = new WelcomeForm();
11+
private readonly WelcomeForm WelcomeForm = new();
1212

1313
[SetUp]
1414
public void Before()
@@ -22,8 +22,8 @@ public void Should_BePossibleTo_OpenUrlInNewTab()
2222
var url = new WelcomeForm().Url;
2323
var browser = AqualityServices.Browser;
2424
browser.Tabs().OpenInNewTab(url);
25-
Assert.AreEqual(2, browser.Tabs().TabHandles.Count);
26-
Assert.AreEqual(browser.Driver.Url, url);
25+
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(2));
26+
Assert.That(url, Is.EqualTo(browser.Driver.Url));
2727
}
2828

2929
[Test]
@@ -32,8 +32,8 @@ public void Should_BePossibleTo_OpenUrlInNewTab_ViaJs()
3232
var url = new WelcomeForm().Url;
3333
var browser = AqualityServices.Browser;
3434
browser.Tabs().OpenInNewTabViaJs(url);
35-
Assert.AreEqual(2, browser.Tabs().TabHandles.Count);
36-
Assert.AreEqual(browser.Driver.Url, url);
35+
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(2));
36+
Assert.That(url, Is.EqualTo(browser.Driver.Url));
3737
}
3838

3939
[Test]
@@ -42,25 +42,25 @@ public void Should_BePossibleTo_OpenUriInNewTab()
4242
var url = new Uri(new WelcomeForm().Url);
4343
var browser = AqualityServices.Browser;
4444
browser.Tabs().OpenInNewTab(url);
45-
Assert.AreEqual(2, browser.Tabs().TabHandles.Count);
46-
Assert.AreEqual(new Uri(browser.Driver.Url), url);
45+
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(2));
46+
Assert.That(url, Is.EqualTo(new Uri(browser.Driver.Url)));
4747
}
4848

4949
[Test]
5050
public void Should_BePossibleTo_HandleTab()
5151
{
5252
var browser = AqualityServices.Browser;
5353
var tabHandle = browser.Tabs().CurrentTabHandle;
54-
Assert.IsNotEmpty(tabHandle, "Tab name should not be empty");
54+
Assert.That(tabHandle, Is.Not.Empty, "Tab name should not be empty");
5555
}
5656

5757
[Test]
5858
public void Should_BePossibleTo_GetTabHandles()
5959
{
6060
var browser = AqualityServices.Browser;
6161
var tabHandles = browser.Tabs().TabHandles;
62-
Assert.AreEqual(1, tabHandles.Count, "Tab number should be correct");
63-
Assert.IsNotEmpty(tabHandles.First(), "Tab handle should not be empty");
62+
Assert.That(tabHandles.Count, Is.EqualTo(1), "Tab number should be correct");
63+
Assert.That(tabHandles.First(), Is.Not.Empty, "Tab handle should not be empty");
6464
}
6565

6666
[Test]
@@ -71,12 +71,12 @@ public void Should_BePossibleTo_OpenNewTab()
7171

7272
browser.Tabs().OpenNewTab();
7373
var newTabHandle = browser.Tabs().CurrentTabHandle;
74-
Assert.AreEqual(2, browser.Tabs().TabHandles.Count, "New tab should be opened");
75-
Assert.AreNotEqual(tabHandle, newTabHandle, "Browser should be switched to new tab");
74+
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(2), "New tab should be opened");
75+
Assert.That(newTabHandle, Is.Not.EqualTo(tabHandle), "Browser should be switched to new tab");
7676

7777
browser.Tabs().OpenNewTab(false);
78-
Assert.AreEqual(3, browser.Tabs().TabHandles.Count, "New tab should be opened");
79-
Assert.AreEqual(newTabHandle, browser.Tabs().CurrentTabHandle, "Browser should not be switched to new tab");
78+
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(3), "New tab should be opened");
79+
Assert.That(browser.Tabs().CurrentTabHandle, Is.EqualTo(newTabHandle), "Browser should not be switched to new tab");
8080
}
8181

8282
[Test]
@@ -87,22 +87,22 @@ public void Should_BePossibleTo_OpenNewTab_ViaJs()
8787

8888
browser.Tabs().OpenNewTabViaJs();
8989
var newTabHandle = browser.Tabs().CurrentTabHandle;
90-
Assert.AreEqual(2, browser.Tabs().TabHandles.Count, "New tab should be opened");
91-
Assert.AreNotEqual(tabHandle, newTabHandle, "Browser should be switched to new tab");
90+
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(2), "New tab should be opened");
91+
Assert.That(newTabHandle, Is.Not.EqualTo(tabHandle), "Browser should be switched to new tab");
9292

9393
browser.Tabs().OpenNewTabViaJs(false);
94-
Assert.AreEqual(3, browser.Tabs().TabHandles.Count, "New tab should be opened");
95-
Assert.AreEqual(newTabHandle, browser.Tabs().CurrentTabHandle, "Browser should not be switched to new tab");
94+
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(3), "New tab should be opened");
95+
Assert.That(browser.Tabs().CurrentTabHandle, Is.EqualTo(newTabHandle), "Browser should not be switched to new tab");
9696
}
9797

9898
[Test]
9999
public void Should_BePossibleTo_CloseTab()
100100
{
101101
var browser = AqualityServices.Browser;
102102
WelcomeForm.ClickElementalSelenium();
103-
Assert.AreEqual(2, browser.Tabs().TabHandles.Count, "New tab should be opened");
103+
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(2), "New tab should be opened");
104104
browser.Tabs().CloseTab();
105-
Assert.AreEqual(1, browser.Tabs().TabHandles.Count, "New tab should be closed");
105+
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(1), "New tab should be closed");
106106
}
107107

108108
[Test]
@@ -177,11 +177,12 @@ private void CheckSwitchingBy(int expectedTabCount, Action switchMethod)
177177
{
178178
var browser = AqualityServices.Browser;
179179
var tabHandle = browser.Tabs().CurrentTabHandle;
180+
Assert.That(tabHandle, Is.Not.Empty);
180181
WelcomeForm.ClickElementalSelenium();
181182
var newTabHandle = browser.Tabs().TabHandles.Last();
182183
switchMethod.Invoke();
183-
Assert.AreEqual(newTabHandle, browser.Tabs().CurrentTabHandle, "Browser should be switched to correct tab");
184-
Assert.AreEqual(expectedTabCount, browser.Tabs().TabHandles.Count, "Number of tabs should be correct");
184+
Assert.That(browser.Tabs().CurrentTabHandle, Is.EqualTo(newTabHandle), "Browser should be switched to correct tab");
185+
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(expectedTabCount), "Number of tabs should be correct");
185186
}
186187
}
187188
}

0 commit comments

Comments
 (0)