Skip to content

Commit

Permalink
Update to Selenium 4.19.0 (#251)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mialeska authored Apr 18, 2024
1 parent 45c2f40 commit 6232ff8
Show file tree
Hide file tree
Showing 34 changed files with 237 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aquality.Selenium.Core" Version="3.0.6" />
<PackageReference Include="WebDriverManager" Version="2.17.1" />
<PackageReference Include="Aquality.Selenium.Core" Version="3.0.7" />
<PackageReference Include="OpenCvSharp4.runtime.osx_arm64" Version="4.8.1-rc" />
<PackageReference Include="WebDriverManager" Version="2.17.2" />
<PackageReference Include="OpenCvSharp4" Version="4.9.0.20240103" />
<PackageReference Include="OpenCvSharp4.runtime.linux-arm" Version="4.9.0.20240103" />
<PackageReference Include="OpenCvSharp4.runtime.osx.10.15-x64" Version="4.6.0.20230105" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="nunit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Should_BePossibleTo_Click()
var welcomeForm = new WelcomeForm();
welcomeForm.Open();
welcomeForm.GetExampleLink(AvailableExample.Dropdown).JsActions.Click();
Assert.IsTrue(new DropdownForm().State.WaitForDisplayed(), "Dropdown form should be displayed");
Assert.That(new DropdownForm().State.WaitForDisplayed(), "Dropdown form should be displayed");
}

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

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

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

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

[Test]
Expand All @@ -74,9 +74,9 @@ public void Should_BePossibleTo_CheckIsElementOnScreen()
hoversForm.Open();
Assert.Multiple(() =>
{
Assert.IsFalse(HoversForm.GetHiddenElement(HoverExample.First, ElementState.ExistsInAnyState).JsActions.IsElementOnScreen(),
Assert.That(HoversForm.GetHiddenElement(HoverExample.First, ElementState.ExistsInAnyState).JsActions.IsElementOnScreen(), Is.False,
$"Hidden element for {HoverExample.First} should be invisible.");
Assert.IsTrue(HoversForm.GetExample(HoverExample.First).JsActions.IsElementOnScreen(),
Assert.That(HoversForm.GetExample(HoverExample.First).JsActions.IsElementOnScreen(),
$"Element for {HoverExample.First} should be visible.");
});
}
Expand All @@ -89,15 +89,15 @@ public void Should_BePossibleTo_SetValue()
const string text = "text";
keyPressesForm.InputTextBox.JsActions.SetValue(text);
var actualText = keyPressesForm.InputTextBox.Value;
Assert.AreEqual(text, actualText, $"Text should be '{text}' after setting value via JS");
Assert.That(actualText, Is.EqualTo(text), $"Text should be '{text}' after setting value via JS");
}

[Test]
public void Should_BePossibleTo_GetElementText()
{
var welcomeForm = new WelcomeForm();
welcomeForm.Open();
Assert.AreEqual(WelcomeForm.SubTitle, welcomeForm.SubTitleLabel.JsActions.GetElementText(),
Assert.That(welcomeForm.SubTitleLabel.JsActions.GetElementText(), Is.EqualTo(WelcomeForm.SubTitle),
$"Sub title should be {WelcomeForm.SubTitle}");
}

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

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

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

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

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void Should_BePossibleTo_Click()
var welcomeForm = new WelcomeForm();
welcomeForm.Open();
welcomeForm.GetExampleLink(AvailableExample.Dropdown).MouseActions.Click();
Assert.IsTrue(new DropdownForm().State.WaitForDisplayed(), "Dropdown form should be displayed");
Assert.That(new DropdownForm().State.WaitForDisplayed(), "Dropdown form should be displayed");
}

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

[Test]
Expand All @@ -40,7 +40,7 @@ public void Should_BePossibleTo_MoveToElement()
var menuForm = new JQueryMenuForm();
menuForm.Open();
JQueryMenuForm.EnabledButton.MouseActions.MoveToElement();
Assert.IsTrue(JQueryMenuForm.IsEnabledButtonFocused, "Element should be focused after move mouse");
Assert.That(JQueryMenuForm.IsEnabledButtonFocused, "Element should be focused after move mouse");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Aquality.Selenium.Tests.Integration
{
internal class AlertTests : UITest
{
private readonly JavaScriptAlertsForm alertsForm = new JavaScriptAlertsForm();
private readonly JavaScriptAlertsForm alertsForm = new();

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

[Test]
public void Should_BePossibleTo_AcceptConfirmationAlert()
{
alertsForm.JsConfirmButton.Click();
AqualityServices.Browser.HandleAlert(AlertAction.Accept);
Assert.AreEqual("You clicked: Ok", alertsForm.ResultLabel.GetText());
Assert.That(alertsForm.ResultLabel.GetText(), Is.EqualTo("You clicked: Ok"));
}

[Test]
Expand All @@ -50,15 +50,15 @@ public void Should_BePossibleTo_AcceptConfirmationAlert_InWaitFor()
}

});
Assert.AreEqual("You clicked: Ok", alertsForm.ResultLabel.GetText());
Assert.That(alertsForm.ResultLabel.GetText(), Is.EqualTo("You clicked: Ok"));
}

[Test]
public void Should_BePossibleTo_DeclineConfirmationAlert()
{
alertsForm.JsConfirmButton.Click();
AqualityServices.Browser.HandleAlert(AlertAction.Decline);
Assert.AreEqual("You clicked: Cancel", alertsForm.ResultLabel.GetText());
Assert.That(alertsForm.ResultLabel.GetText(), Is.EqualTo("You clicked: Cancel"));
}

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

[Test]
public void Should_BePossibleTo_DeclinePromptAlertWithText()
{
alertsForm.JsPromptButton.Click();
AqualityServices.Browser.HandleAlert(AlertAction.Decline, "decline alert text");
Assert.AreEqual("You entered: null", alertsForm.ResultLabel.GetText());
Assert.That(alertsForm.ResultLabel.GetText(), Is.EqualTo("You entered: null"));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Aquality.Selenium.Tests.Integration
{
internal class BrowserTabsTests : UITest
{
private readonly WelcomeForm WelcomeForm = new WelcomeForm();
private readonly WelcomeForm WelcomeForm = new();

[SetUp]
public void Before()
Expand All @@ -22,8 +22,8 @@ public void Should_BePossibleTo_OpenUrlInNewTab()
var url = new WelcomeForm().Url;
var browser = AqualityServices.Browser;
browser.Tabs().OpenInNewTab(url);
Assert.AreEqual(2, browser.Tabs().TabHandles.Count);
Assert.AreEqual(browser.Driver.Url, url);
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(2));
Assert.That(url, Is.EqualTo(browser.Driver.Url));
}

[Test]
Expand All @@ -32,8 +32,8 @@ public void Should_BePossibleTo_OpenUrlInNewTab_ViaJs()
var url = new WelcomeForm().Url;
var browser = AqualityServices.Browser;
browser.Tabs().OpenInNewTabViaJs(url);
Assert.AreEqual(2, browser.Tabs().TabHandles.Count);
Assert.AreEqual(browser.Driver.Url, url);
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(2));
Assert.That(url, Is.EqualTo(browser.Driver.Url));
}

[Test]
Expand All @@ -42,25 +42,25 @@ public void Should_BePossibleTo_OpenUriInNewTab()
var url = new Uri(new WelcomeForm().Url);
var browser = AqualityServices.Browser;
browser.Tabs().OpenInNewTab(url);
Assert.AreEqual(2, browser.Tabs().TabHandles.Count);
Assert.AreEqual(new Uri(browser.Driver.Url), url);
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(2));
Assert.That(url, Is.EqualTo(new Uri(browser.Driver.Url)));
}

[Test]
public void Should_BePossibleTo_HandleTab()
{
var browser = AqualityServices.Browser;
var tabHandle = browser.Tabs().CurrentTabHandle;
Assert.IsNotEmpty(tabHandle, "Tab name should not be empty");
Assert.That(tabHandle, Is.Not.Empty, "Tab name should not be empty");
}

[Test]
public void Should_BePossibleTo_GetTabHandles()
{
var browser = AqualityServices.Browser;
var tabHandles = browser.Tabs().TabHandles;
Assert.AreEqual(1, tabHandles.Count, "Tab number should be correct");
Assert.IsNotEmpty(tabHandles.First(), "Tab handle should not be empty");
Assert.That(tabHandles.Count, Is.EqualTo(1), "Tab number should be correct");
Assert.That(tabHandles.First(), Is.Not.Empty, "Tab handle should not be empty");
}

[Test]
Expand All @@ -71,12 +71,12 @@ public void Should_BePossibleTo_OpenNewTab()

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

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

[Test]
Expand All @@ -87,22 +87,22 @@ public void Should_BePossibleTo_OpenNewTab_ViaJs()

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

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

[Test]
public void Should_BePossibleTo_CloseTab()
{
var browser = AqualityServices.Browser;
WelcomeForm.ClickElementalSelenium();
Assert.AreEqual(2, browser.Tabs().TabHandles.Count, "New tab should be opened");
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(2), "New tab should be opened");
browser.Tabs().CloseTab();
Assert.AreEqual(1, browser.Tabs().TabHandles.Count, "New tab should be closed");
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(1), "New tab should be closed");
}

[Test]
Expand Down Expand Up @@ -177,11 +177,12 @@ private void CheckSwitchingBy(int expectedTabCount, Action switchMethod)
{
var browser = AqualityServices.Browser;
var tabHandle = browser.Tabs().CurrentTabHandle;
Assert.That(tabHandle, Is.Not.Empty);
WelcomeForm.ClickElementalSelenium();
var newTabHandle = browser.Tabs().TabHandles.Last();
switchMethod.Invoke();
Assert.AreEqual(newTabHandle, browser.Tabs().CurrentTabHandle, "Browser should be switched to correct tab");
Assert.AreEqual(expectedTabCount, browser.Tabs().TabHandles.Count, "Number of tabs should be correct");
Assert.That(browser.Tabs().CurrentTabHandle, Is.EqualTo(newTabHandle), "Browser should be switched to correct tab");
Assert.That(browser.Tabs().TabHandles.Count, Is.EqualTo(expectedTabCount), "Number of tabs should be correct");
}
}
}
Loading

0 comments on commit 6232ff8

Please sign in to comment.