Skip to content

Commit 813b040

Browse files
authored
Update tests to NUnit 4 assertions style (#39)
* Update tests to NUnit 4 assertions style + Implement assertion that keyboard is shown in test * add wait to stabilize TextBoxInteraction test
1 parent 1b69013 commit 813b040

File tree

9 files changed

+66
-66
lines changed

9 files changed

+66
-66
lines changed

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Aquality.Appium.Mobile.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="nunit" Version="3.14.0" />
12-
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2">
11+
<PackageReference Include="nunit" Version="4.1.0" />
12+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
1313
<PrivateAssets>all</PrivateAssets>
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
</PackageReference>

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Integration/DeviceSettingsTests.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Aquality.Appium.Mobile.Configurations;
33
using NUnit.Framework;
44
using System;
5-
using System.Linq;
65

76
namespace Aquality.Appium.Mobile.Tests.Integration
87
{
@@ -17,17 +16,15 @@ public void Should_BePossible_ToGetDeviceCapabilities()
1716
{
1817
var deviceSettings = new DeviceSettings("iPhone_11");
1918
var options = deviceSettings.Capabilities;
20-
Assert.IsNotNull(options);
21-
Assert.IsTrue(options.Any());
19+
Assert.That(options, Is.Not.Null.And.Not.Empty);
2220
}
2321

2422
[Test]
2523
public void Should_BePossible_ToGetEmptyCapabilitiesWhenDeviceKeyIsNull()
2624
{
2725
var deviceSettings = new DeviceSettings(null);
2826
var options = deviceSettings.Capabilities;
29-
Assert.IsNotNull(options);
30-
Assert.IsFalse(options.Any());
27+
Assert.That(options, Is.Not.Null.And.Empty);
3128
}
3229

3330
[Test]
@@ -36,12 +33,12 @@ public void Should_BePossible_ToUseDifferentDevicesProfiles()
3633
Environment.SetEnvironmentVariable(DevicesProfilePropertyKey, "test");
3734
var deviceSettings = new DeviceSettings("iPhone_11");
3835
var options = deviceSettings.Capabilities;
39-
Assert.AreEqual("iPhone 11 test", options["deviceName"]);
36+
Assert.That(options["deviceName"], Is.EqualTo("iPhone 11 test"));
4037

4138
Environment.SetEnvironmentVariable(DevicesProfilePropertyKey, null);
4239
deviceSettings = new DeviceSettings("iPhone_11");
4340
options = deviceSettings.Capabilities;
44-
Assert.AreEqual("iPhone 11", options["deviceName"]);
41+
Assert.That(options["deviceName"], Is.EqualTo("iPhone 11"));
4542
}
4643

4744
[Test]
@@ -50,7 +47,7 @@ public void Should_BePossible_ToGetDefaultDeviceSettingsForIosPlatform()
5047
Environment.SetEnvironmentVariable(PlatformNamePropertyKey, "ios");
5148
Environment.SetEnvironmentVariable(DevicesKeyPropertyKey, "iPhone_11");
5249
var options = AqualityServices.Get<IApplicationProfile>().DriverSettings.AppiumOptions;
53-
Assert.AreEqual("iPhone 11", options.DeviceName);
50+
Assert.That(options.DeviceName, Is.EqualTo("iPhone 11"));
5451
}
5552

5653
[Test]
@@ -59,7 +56,7 @@ public void Should_BePossible_ToGetDefaultDeviceSettingsForAndroidPlatform()
5956
Environment.SetEnvironmentVariable(PlatformNamePropertyKey, "android");
6057
Environment.SetEnvironmentVariable(DevicesKeyPropertyKey, "Nexus");
6158
var options = AqualityServices.Get<IApplicationProfile>().DriverSettings.AppiumOptions;
62-
Assert.AreEqual("Nexus", options.DeviceName);
59+
Assert.That(options.DeviceName, Is.EqualTo("Nexus"));
6360
}
6461

6562
[Test]
@@ -68,7 +65,7 @@ public void Should_BePossible_ToOverrideDefaultDevice()
6865
Environment.SetEnvironmentVariable(PlatformNamePropertyKey, "android");
6966
Environment.SetEnvironmentVariable(DevicesKeyPropertyKey, "Samsung_Galaxy");
7067
var options = AqualityServices.Get<IApplicationProfile>().DriverSettings.AppiumOptions;
71-
Assert.AreEqual("Samsung Galaxy", options.DeviceName);
68+
Assert.That(options.DeviceName, Is.EqualTo("Samsung Galaxy"));
7269
}
7370

7471
[TearDown]

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Samples/Android/ICheckBoxTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ public static void InvokeCheckBoxTest(this ICheckBoxTest checkBoxTest)
1616
{
1717
checkBoxTest.OpenCheckBoxesScreen();
1818
var checkBox1 = checkBoxTest.GetCheckBox(1);
19-
Assert.IsFalse(checkBox1.IsChecked, "Checkbox should not be checked initially");
19+
Assert.That(checkBox1.IsChecked, Is.False, "Checkbox should not be checked initially");
2020
checkBox1.Click();
21-
Assert.IsTrue(checkBox1.IsChecked, "Checkbox should be checked after first click on it");
21+
Assert.That(checkBox1.IsChecked, Is.True, "Checkbox should be checked after first click on it");
2222
checkBox1.Uncheck();
23-
Assert.IsFalse(checkBox1.IsChecked, "Checkbox should not be checked after uncheck");
23+
Assert.That(checkBox1.IsChecked, Is.False, "Checkbox should not be checked after uncheck");
2424
checkBox1.Toggle();
25-
Assert.IsTrue(checkBox1.IsChecked, "Checkbox should be checked after toggle from unchecked state");
25+
Assert.That(checkBox1.IsChecked, Is.True, "Checkbox should be checked after toggle from unchecked state");
2626
checkBox1.Toggle();
27-
Assert.IsFalse(checkBox1.IsChecked, "Checkbox should not be checked after toggle from checked state");
27+
Assert.That(checkBox1.IsChecked, Is.False, "Checkbox should not be checked after toggle from checked state");
2828
checkBoxTest.GetCheckBox(2).Check();
29-
Assert.IsFalse(checkBox1.IsChecked, "Checkbox should not be checked after checking other checkbox");
29+
Assert.That(checkBox1.IsChecked, Is.False, "Checkbox should not be checked after checking other checkbox");
3030
}
3131
}
3232
}

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Samples/Android/IRadioButtonTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public static void InvokeRadioButtonTest(this IRadioButtonTest radioButtonTest)
1616
{
1717
radioButtonTest.OpenRadioButtonsScreen();
1818
IRadioButton button1 = radioButtonTest.GetRadioButton(1);
19-
Assert.IsFalse(button1.IsChecked, "RadioButton should not be checked initially");
19+
Assert.That(button1.IsChecked, Is.False, "RadioButton should not be checked initially");
2020
button1.Click();
21-
Assert.IsTrue(button1.IsChecked, "RadioButton should be checked after click on it");
21+
Assert.That(button1.IsChecked, Is.True, "RadioButton should be checked after click on it");
2222
radioButtonTest.GetRadioButton(2).Click();
23-
Assert.IsFalse(button1.IsChecked,
23+
Assert.That(button1.IsChecked, Is.False,
2424
$"RadioButton {button1.Name} should not be checked after click on another option");
2525
}
2626
}

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Samples/Android/NativeApp/AndroidBasicInteractionsTest.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void SendKeys()
2121
Assume.That(searchScreen.State.IsDisplayed, $"{searchScreen.Name} should be opened from the menu");
2222
const string query = "Hello world!";
2323
searchScreen.SubmitSearch(query);
24-
Assert.AreEqual(query, searchScreen.SearchResult, "Search result don't match to entered query");
24+
Assert.That(searchScreen.SearchResult, Is.EqualTo(query), "Search result don't match to entered query");
2525
}
2626

2727
[Test]
@@ -51,8 +51,9 @@ public void AlertInteraction()
5151
LogStep("Check that the dialog is there");
5252
var alertDialog = new TwoButtonsAlert();
5353
const string expectedText = "Lorem ipsum dolor sit aie consectetur adipiscingPlloaso mako nuto siwuf cakso dodtos anr koop.";
54-
Assert.AreEqual(expectedText,
55-
alertDialog.AlertText.Replace("\r", string.Empty).Replace("\n", string.Empty), "Alert text should match to expected");
54+
Assert.That(alertDialog.AlertText.Replace("\r", string.Empty).Replace("\n", string.Empty),
55+
Is.EqualTo(expectedText),
56+
"Alert text should match to expected");
5657

5758
LogStep("Close the dialog");
5859
alertDialog.Close();
@@ -64,12 +65,12 @@ public void TestVerticalSwipeToElement()
6465
var viewControlsScreen = new ViewControlsScreen();
6566
OpenRadioButtonsScreen();
6667
viewControlsScreen.ScrollToAllInsideScrollViewLabel();
67-
Assert.AreEqual(
68-
"(And all inside of a ScrollView!)",
68+
Assert.That(
6969
viewControlsScreen.AllInsideScrollViewLabelText,
70+
Is.EqualTo("(And all inside of a ScrollView!)"),
7071
"Label text does not match expected");
7172
viewControlsScreen.ScrollToDisabledButton();
72-
Assert.IsFalse(viewControlsScreen.IsDisabledButtonClickable);
73+
Assert.That(viewControlsScreen.IsDisabledButtonClickable, Is.False);
7374
}
7475

7576
[Test]
@@ -81,18 +82,18 @@ public void TestHorizontalSwipeToElement()
8182
var tabFourTag = 4;
8283
var viewTabsScrollableScreen = new ViewTabsScrollableScreen();
8384
OpenViewTabsScrollableScreen();
84-
Assert.IsTrue(viewTabsScrollableScreen.State.IsDisplayed);
85+
Assert.That(viewTabsScrollableScreen.State.IsDisplayed, Is.True);
8586
viewTabsScrollableScreen.SwipeTab(tabFourTag, 1);
8687
viewTabsScrollableScreen.SelectTab(tabSevenTag);
87-
Assert.AreEqual(
88+
Assert.That(
8889
viewTabsScrollableScreen.GetTabContentText(tabSevenTag),
89-
$"{tabContentFriendlyMessage} {tabSevenTag}",
90+
Is.EqualTo($"{tabContentFriendlyMessage} {tabSevenTag}"),
9091
tabTextDoesNotMatchFriendlyMessage);
9192
viewTabsScrollableScreen.SwipeTab(5, tabSevenTag);
9293
viewTabsScrollableScreen.SelectTab(tabFourTag);
93-
Assert.AreEqual(
94+
Assert.That(
9495
viewTabsScrollableScreen.GetTabContentText(tabFourTag),
95-
$"{tabContentFriendlyMessage} {tabFourTag}",
96+
Is.EqualTo($"{tabContentFriendlyMessage} {tabFourTag}"),
9697
tabTextDoesNotMatchFriendlyMessage);
9798
}
9899

@@ -102,7 +103,7 @@ public void TestHorizontalSwipeToElement()
102103
[Test]
103104
public void TestRadioButton() => this.InvokeRadioButtonTest();
104105

105-
private void LogStep(string step)
106+
private static void LogStep(string step)
106107
{
107108
AqualityServices.Logger.Info(step);
108109
}
@@ -115,6 +116,6 @@ private void LogStep(string step)
115116

116117
public ICheckBox GetCheckBox(int number) => new ViewControlsScreen().GetCheckBox(number);
117118

118-
public void OpenViewTabsScrollableScreen() => new ViewTabsScrollableScreen().Open();
119+
public static void OpenViewTabsScrollableScreen() => new ViewTabsScrollableScreen().Open();
119120
}
120121
}

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Samples/Android/Web/AndroidWebSessionTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ namespace Aquality.Appium.Mobile.Tests.Samples.Android.Web
66
{
77
public class AndroidWebSessionTest : UITest
88
{
9-
private IWebDriver Driver => AqualityServices.Application.Driver;
9+
private static IWebDriver Driver => AqualityServices.Application.Driver;
1010

1111
[Test]
1212
public void CreateWebSession()
1313
{
1414
Driver.Url = "http://www.google.com";
15-
var title = Driver.Title;
16-
Assert.AreEqual("Google", title);
15+
Assert.That(Driver.Title, Is.EqualTo("Google"));
1716
}
1817
}
1918
}

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Samples/Android/Web/WebComboboxTest.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace Aquality.Appium.Mobile.Tests.Samples.Android.Web
1212
public class WebComboboxTest : UITest
1313
{
1414
private readonly IComboBox comboBox = AqualityServices.ElementFactory.GetComboBox(By.Id("dropdown"), "dropdown");
15-
private IEnumerable<DropdownOption> DropdownOptions => Enum.GetValues(typeof(DropdownOption)).Cast<DropdownOption>();
15+
private static IEnumerable<DropdownOption> DropdownOptions => Enum.GetValues(typeof(DropdownOption)).Cast<DropdownOption>();
1616

17-
private By GetChildLocator(string textPart) => By.XPath($".//*[contains(., '{textPart}')]");
17+
private static By GetChildLocator(string textPart) => By.XPath($".//*[contains(., '{textPart}')]");
1818

1919
[SetUp]
2020
public void OpenDropdownPage()
@@ -25,53 +25,54 @@ public void OpenDropdownPage()
2525

2626
[Test]
2727
public void TestComboBoxGetsTexts() =>
28-
CollectionAssert.AreEquivalent(
29-
DropdownOptions.Select(option => option.GetText()),
28+
Assert.That(
3029
comboBox.Texts,
30+
Is.EquivalentTo(DropdownOptions.Select(option => option.GetText())),
3131
"Texts should match to expected");
3232

3333
[Test]
3434
public void TestComboBoxGetsValues() =>
35-
CollectionAssert.AreEquivalent(
36-
DropdownOptions.Select(option => option.GetValue()),
35+
Assert.That(
3736
comboBox.Values,
37+
Is.EquivalentTo(DropdownOptions.Select(option => option.GetValue())),
3838
"Texts should match to expected");
3939
[Test]
4040
public void TestComboBoxSelectionMethods()
4141
{
42-
Assert.AreEqual(DropdownOption.Default.GetText(), comboBox.SelectedText, "Option's text mismatch");
42+
Assert.That(comboBox.SelectedText, Is.EqualTo(DropdownOption.Default.GetText()), "Option's text mismatch");
4343
comboBox.SelectByValue(DropdownOption.First.GetValue());
44-
Assert.AreEqual(DropdownOption.First.GetValue(), comboBox.SelectedValue, "Option's value mismatch");
44+
Assert.That(comboBox.SelectedValue, Is.EqualTo(DropdownOption.First.GetValue()), "Option's value mismatch");
4545
comboBox.SelectByText(DropdownOption.Second.GetText());
46-
Assert.AreEqual(DropdownOption.Second.GetText(), comboBox.SelectedText, "Option's text mismatch");
46+
Assert.That(comboBox.SelectedText, Is.EqualTo(DropdownOption.Second.GetText()), "Option's text mismatch");
4747
comboBox.ClickAndSelectByText(DropdownOption.First.GetText());
48-
Assert.AreEqual(DropdownOption.First.GetText(), comboBox.SelectedText, "Option's text mismatch");
48+
Assert.That(comboBox.SelectedText, Is.EqualTo(DropdownOption.First.GetText()), "Option's text mismatch");
4949
comboBox.ClickAndSelectByValue(DropdownOption.Second.GetValue());
50-
Assert.AreEqual(DropdownOption.Second.GetValue(), comboBox.SelectedValue, "Option's value mismatch");
50+
Assert.That(comboBox.SelectedValue, Is.EqualTo(DropdownOption.Second.GetValue()), "Option's value mismatch");
5151
comboBox.SelectByContainingText(DropdownOption.First.GetValue());
52-
Assert.AreEqual(DropdownOption.First.GetText(), comboBox.SelectedText, "Option's text mismatch");
52+
Assert.That(comboBox.SelectedText, Is.EqualTo(DropdownOption.First.GetText()), "Option's text mismatch");
5353
comboBox.SelectByContainingValue(DropdownOption.Second.GetValue());
54-
Assert.AreEqual(DropdownOption.Second.GetValue(), comboBox.SelectedValue, "Option's value mismatch");
54+
Assert.That(comboBox.SelectedValue, Is.EqualTo(DropdownOption.Second.GetValue()), "Option's value mismatch");
5555
comboBox.SelectByIndex(DropdownOption.First.GetIndex());
56-
Assert.AreEqual(DropdownOption.First.GetText(), comboBox.SelectedText, "Option's text mismatch");
56+
Assert.That(comboBox.SelectedText, Is.EqualTo(DropdownOption.First.GetText()), "Option's text mismatch");
5757
}
5858

5959
[Test]
6060
public void TestFindChildElementWithName()
6161
{
62-
Assert.AreEqual(DropdownOption.Second.GetValue(),
62+
Assert.That(
6363
comboBox.FindChildElement<ILabel>(GetChildLocator(DropdownOption.Second.GetValue()), "2")
6464
.GetAttribute("value"),
65+
Is.EqualTo(DropdownOption.Second.GetValue()),
6566
"Child option's value mismatch");
6667
}
6768

6869
[Test]
6970
public void TestFindChildElementWithoutName()
7071
{
71-
Assert.AreEqual(DropdownOption.First.GetText(),
72-
comboBox.FindChildElement<ILabel>(GetChildLocator(DropdownOption.First.GetText()))
73-
.Text,
74-
"Child option's text mismatch");
72+
Assert.That(
73+
comboBox.FindChildElement<ILabel>(GetChildLocator(DropdownOption.First.GetText())).Text,
74+
Is.EqualTo(DropdownOption.First.GetText()),
75+
"Child option's text mismatch");
7576
}
7677
}
7778
}

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Samples/Android/Web/WebLinkTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public void OpenLinkPage() =>
1717

1818
[Test]
1919
public void TestLinkGetsHref() =>
20-
Assert.IsTrue(link.Href.Contains("redirect"), "Link href mismatch");
20+
Assert.That(link.Href.Contains("redirect"), Is.True, "Link href mismatch");
2121

2222
[Test]
2323
public void TestLinkClickable()
2424
{
2525
link.State.WaitForClickable();
2626
link.Click();
27-
Assert.IsTrue(link.State.WaitForNotExist(), "Link was not clicked properly as it isn't disappeared");
27+
Assert.That(link.State.WaitForNotExist(), Is.True, "Link was not clicked properly as it isn't disappeared");
2828
}
2929
}
3030
}

Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Samples/Android/Web/WebTextBoxTest.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Aquality.Appium.Mobile.Applications;
22
using NUnit.Framework;
33
using OpenQA.Selenium;
4+
using OpenQA.Selenium.Appium;
45

56
namespace Aquality.Appium.Mobile.Tests.Samples.Android.Web
67
{
@@ -21,23 +22,24 @@ public void TextBoxInteraction()
2122
txbSearch.Focus();
2223
CheckIsKeyboardShown(expectedState: true, "Keyboard should be shown when focus successful");
2324
txbSearch.Type(ValueToSubmit);
24-
Assert.AreEqual(ValueToSubmit, txbSearch.Value, "Submitted value should match to expected");
25+
Assert.That(txbSearch.Value, Is.EqualTo(ValueToSubmit), "Submitted value should match to expected");
2526
txbSearch.Clear();
26-
Assert.AreEqual(string.Empty, txbSearch.Value, "Value should be cleared");
27+
Assert.That(txbSearch.Value, Is.EqualTo(string.Empty), "Value should be cleared");
2728
txbSearch.TypeSecret(ValueToSubmit);
28-
Assert.AreEqual(ValueToSubmit, txbSearch.Value, "Submitted value should match to expected");
29+
Assert.That(txbSearch.Value, Is.EqualTo(ValueToSubmit), "Submitted value should match to expected");
2930
txbSearch.ClearAndType(ValueToSubmit);
30-
Assert.AreEqual(ValueToSubmit, txbSearch.Value, "Submitted value should match to expected");
31+
Assert.That(txbSearch.Value, Is.EqualTo(ValueToSubmit), "Submitted value should match to expected");
3132
txbSearch.ClearAndTypeSecret(ValueToSubmit);
32-
Assert.AreEqual(ValueToSubmit, txbSearch.Value, "Submitted value should match to expected");
33+
Assert.That(txbSearch.Value, Is.EqualTo(ValueToSubmit), "Submitted value should match to expected");
3334
txbSearch.SendKeys(Keys.Enter);
34-
Assert.IsTrue(txbSearch.State.WaitForNotDisplayed(), "text field should disappear after the submit");
35+
Assert.That(txbSearch.State.WaitForNotDisplayed(), Is.True, "text field should disappear after the submit");
3536
}
3637

3738
private static void CheckIsKeyboardShown(bool expectedState, string message)
3839
{
39-
// TODO: not yet implemented in dotnet Appium client: http://appium.io/docs/en/commands/device/keys/is-keyboard-shown/
40-
Assert.AreEqual(expectedState, expectedState, message);
40+
var waitResult = AqualityServices.ConditionalWait.WaitFor(driver => ((AppiumDriver)driver).IsKeyboardShown() == expectedState,
41+
message:$"is keyboard shown condition should be {expectedState}");
42+
Assert.That(AqualityServices.Application.Driver.IsKeyboardShown(), Is.EqualTo(expectedState), message);
4143
}
4244
}
4345
}

0 commit comments

Comments
 (0)