diff --git a/.editorconfig b/.editorconfig index 31db5cbb..8967ae35 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,6 @@ indent_size = 4 [*.cs] indent_style = space indent_size = 4 + +# Set up additional disposal methods for a specific diagnostic rule +dotnet_diagnostic.NUnit1032.additional_dispose_methods = Quit \ No newline at end of file diff --git a/test/integration/Android/ActivityTest.cs b/test/integration/Android/ActivityTest.cs index 254d49fd..e91f5590 100644 --- a/test/integration/Android/ActivityTest.cs +++ b/test/integration/Android/ActivityTest.cs @@ -41,11 +41,11 @@ public void StartActivityInThisAppTestCase() { _driver.StartActivity(AppId, ".ApiDemos"); - Assert.AreEqual(_driver.CurrentActivity, ".ApiDemos"); + Assert.That(_driver.CurrentActivity, Is.EqualTo(".ApiDemos")); _driver.StartActivity(AppId, ".accessibility.AccessibilityNodeProviderActivity"); - Assert.AreEqual(_driver.CurrentActivity, ".accessibility.AccessibilityNodeProviderActivity"); + Assert.That(_driver.CurrentActivity, Is.EqualTo(".accessibility.AccessibilityNodeProviderActivity")); } [Test] @@ -53,12 +53,12 @@ public void StartActivityWithWaitingAppTestCase() { _driver.StartActivity(AppId, ".ApiDemos", AppId, ".ApiDemos"); - Assert.AreEqual(_driver.CurrentActivity, ".ApiDemos"); + Assert.That(_driver.CurrentActivity, Is.EqualTo(".ApiDemos")); _driver.StartActivity(AppId, ".accessibility.AccessibilityNodeProviderActivity", "io.appium.android.apis", ".accessibility.AccessibilityNodeProviderActivity"); - Assert.AreEqual(_driver.CurrentActivity, ".accessibility.AccessibilityNodeProviderActivity"); + Assert.That(_driver.CurrentActivity, Is.EqualTo(".accessibility.AccessibilityNodeProviderActivity")); } [Test] @@ -66,13 +66,13 @@ public void StartActivityInNewAppTestCase() { _driver.StartActivity(AppId, ".ApiDemos"); - Assert.AreEqual(_driver.CurrentActivity, ".ApiDemos"); + Assert.That(_driver.CurrentActivity, Is.EqualTo(".ApiDemos")); _driver.StartActivity("com.android.contacts", ContactsActivity); - Assert.AreEqual(_driver.CurrentActivity, ContactsActivity); + Assert.That(_driver.CurrentActivity, Is.EqualTo(ContactsActivity)); _driver.PressKeyCode(AndroidKeyCode.Back); - Assert.AreEqual(_driver.CurrentActivity, ".ApiDemos"); + Assert.That(_driver.CurrentActivity, Is.EqualTo(".ApiDemos")); } [Test] @@ -80,14 +80,14 @@ public void StartActivityInNewAppTestCaseWithoutClosingApp() { _driver.StartActivity(AppId, ".accessibility.AccessibilityNodeProviderActivity"); - Assert.AreEqual(_driver.CurrentActivity, ".accessibility.AccessibilityNodeProviderActivity"); + Assert.That(_driver.CurrentActivity, Is.EqualTo(".accessibility.AccessibilityNodeProviderActivity")); _driver.StartActivity("com.android.contacts", ContactsActivity, "com.android.contacts", ContactsActivity, false); - Assert.AreEqual(_driver.CurrentActivity, ContactsActivity); + Assert.That(_driver.CurrentActivity, Is.EqualTo(ContactsActivity)); _driver.PressKeyCode(AndroidKeyCode.Back); - Assert.AreEqual(_driver.CurrentActivity, ".accessibility.AccessibilityNodeProviderActivity"); + Assert.That(_driver.CurrentActivity, Is.EqualTo(".accessibility.AccessibilityNodeProviderActivity")); } [OneTimeTearDown] diff --git a/test/integration/Android/AndroidUiScrollableTests.cs b/test/integration/Android/AndroidUiScrollableTests.cs index ce694b03..ba05faeb 100644 --- a/test/integration/Android/AndroidUiScrollableTests.cs +++ b/test/integration/Android/AndroidUiScrollableTests.cs @@ -20,7 +20,7 @@ public void Setup() public void NewScrollablesStartWithEmptyConstructorCall() { var statement = _sut.Build(); - Assert.AreEqual(ScrollableCtor, statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor)); } [Test] @@ -28,133 +28,133 @@ public void NewScrollableUsesCustomScrollContainerSelector() { var selector = new AndroidUiSelector().Instance(7); var statement = new AndroidUiScrollable(selector).Build(); - Assert.AreEqual("new UiScrollable(new UiSelector().instance(7))", statement); + Assert.That(statement, Is.EqualTo("new UiScrollable(new UiSelector().instance(7))")); } [Test] public void FlingBackwardAddsCorrectCallToStatement() { var statement = _sut.FlingBackward().Build(); - Assert.AreEqual(ScrollableCtor + ".flingBackward()", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".flingBackward()")); } [Test] public void FlingForwardAddsCorrectCallToStatement() { var statement = _sut.FlingForward().Build(); - Assert.AreEqual(ScrollableCtor + ".flingForward()", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".flingForward()")); } [Test] public void FlingToBeginningAddsCorrectCallToStatement() { var statement = _sut.FlingToBeginning(45).Build(); - Assert.AreEqual(ScrollableCtor + ".flingToBeginning(45)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".flingToBeginning(45)")); } [Test] public void FlingToEndAddsCorrectCallToStatement() { var statement = _sut.FlingToEnd(77).Build(); - Assert.AreEqual(ScrollableCtor + ".flingToEnd(77)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".flingToEnd(77)")); } [Test] public void GetChildByDescriptionAddsCorrectCallToStatement() { var statement = _sut.GetChildByDescription(new AndroidUiSelector(), "Hello World", false).Build(); - Assert.AreEqual(ScrollableCtor + ".getChildByDescription(new UiSelector(), \"Hello World\", false)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".getChildByDescription(new UiSelector(), \"Hello World\", false)")); } [Test] public void GetChildByInstanceAddsCorrectCallToStatement() { var statement = _sut.GetChildByInstance(new AndroidUiSelector(), 9).Build(); - Assert.AreEqual(ScrollableCtor + ".getChildByInstance(new UiSelector(), 9)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".getChildByInstance(new UiSelector(), 9)")); } [Test] public void GetChildByTextAddsCorrectCallToStatement() { var statement = _sut.GetChildByText(new AndroidUiSelector(), "Help", false).Build(); - Assert.AreEqual(ScrollableCtor + ".getChildByText(new UiSelector(), \"Help\", false)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".getChildByText(new UiSelector(), \"Help\", false)")); } [Test] public void ScrollBackwardAddsCorrectCallToStatement() { var statement = _sut.ScrollBackward(32).Build(); - Assert.AreEqual(ScrollableCtor + ".scrollBackward(32)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".scrollBackward(32)")); } [Test] public void ScrollDescriptionIntoViewAddsCorrectCallToStatement() { var statement = _sut.ScrollDescriptionIntoView("Description Here").Build(); - Assert.AreEqual(ScrollableCtor + ".scrollDescriptionIntoView(\"Description Here\")", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".scrollDescriptionIntoView(\"Description Here\")")); } [Test] public void ScrollForwardAddsCorrectCallToStatement() { var statement = _sut.ScrollForward(46).Build(); - Assert.AreEqual(ScrollableCtor + ".scrollForward(46)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".scrollForward(46)")); } [Test] public void ScrollIntoViewAddsCorrectCallToStatement() { var statement = _sut.ScrollIntoView(new AndroidUiSelector()).Build(); - Assert.AreEqual(ScrollableCtor + ".scrollIntoView(new UiSelector())", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".scrollIntoView(new UiSelector())")); } [Test] public void ScrollTextIntoViewAddsCorrectCallToStatement() { var statement = _sut.ScrollTextIntoView("Some Text").Build(); - Assert.AreEqual(ScrollableCtor + ".scrollTextIntoView(\"Some Text\")", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".scrollTextIntoView(\"Some Text\")")); } [Test] public void ScrollToBeginningAddsCorrectCallToStatement() { var statement = _sut.ScrollToBeginning(12, 90).Build(); - Assert.AreEqual(ScrollableCtor + ".scrollToBeginning(12, 90)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".scrollToBeginning(12, 90)")); } [Test] public void ScrollToEndAddsCorrectCallToStatement() { var statement = _sut.ScrollToEnd(32, 51).Build(); - Assert.AreEqual(ScrollableCtor + ".scrollToEnd(32, 51)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".scrollToEnd(32, 51)")); } [Test] public void SetScrollDirectionVerticalAddsCorrectCallToStatement() { var statement = _sut.SetScrollDirection(ListDirection.Vertical).Build(); - Assert.AreEqual(ScrollableCtor + ".setAsVerticalList()", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".setAsVerticalList()")); } [Test] public void SetScrollDirectionHorizontalAddsCorrectCallToStatement() { var statement = _sut.SetScrollDirection(ListDirection.Horizontal).Build(); - Assert.AreEqual(ScrollableCtor + ".setAsHorizontalList()", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".setAsHorizontalList()")); } [Test] public void SetMaxSearchSwipesAddsCorrectCallToStatement() { var statement = _sut.SetMaxSearchSwipes(80).Build(); - Assert.AreEqual(ScrollableCtor + ".setMaxSearchSwipes(80)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".setMaxSearchSwipes(80)")); } [Test] public void SetSwipeDeadZonePercentageAddsCorrectCallToStatement() { var statement = _sut.SetSwipeDeadZonePercentage(.67).Build(); - Assert.AreEqual(ScrollableCtor + ".setSwipeDeadZonePercentage(0.67)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".setSwipeDeadZonePercentage(0.67)")); } [TestCase(1.1)] @@ -172,14 +172,14 @@ public void SomeStatementsCanBeChained() .SetSwipeDeadZonePercentage(0.11) .SetMaxSearchSwipes(44) .Build(); - Assert.AreEqual(ScrollableCtor + ".setSwipeDeadZonePercentage(0.11).setMaxSearchSwipes(44)", statement); + Assert.That(statement, Is.EqualTo(ScrollableCtor + ".setSwipeDeadZonePercentage(0.11).setMaxSearchSwipes(44)")); } [Test] public void AddRawTextAppendsText() { var statment = _sut.AddRawText("@").Build(); - Assert.AreEqual(ScrollableCtor + "@", statment); + Assert.That(statment, Is.EqualTo(ScrollableCtor + "@")); } [Test] @@ -187,7 +187,7 @@ public void RequestingStatementTerminationOnBuildAppendsSemicolon() { var statement = _sut.SetSwipeDeadZonePercentage(.67).Build(true); var lastCharOfStatement = statement[statement.Length - 1]; - Assert.AreEqual(';', lastCharOfStatement); + Assert.That(lastCharOfStatement, Is.EqualTo(';')); } } } diff --git a/test/integration/Android/AndroidUiSelectorTests.cs b/test/integration/Android/AndroidUiSelectorTests.cs index d667eded..5f50ba4f 100644 --- a/test/integration/Android/AndroidUiSelectorTests.cs +++ b/test/integration/Android/AndroidUiSelectorTests.cs @@ -18,203 +18,203 @@ public void Setup() public void NewSelectorStartsWithJustConstructorCall() { var statement = _sut.Build(); - Assert.AreEqual(CtorStatement, statement); + Assert.That(statement, Is.EqualTo(CtorStatement)); } [Test] public void IsCheckableAddsCorrectCallToStatement() { var statement = _sut.IsCheckable(true).Build(); - Assert.AreEqual(CtorStatement + ".checkable(true)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".checkable(true)")); } [Test] public void IsCheckedAddsCorrectCallToStatement() { var statement = _sut.IsChecked(false).Build(); - Assert.AreEqual(CtorStatement + ".checked(false)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".checked(false)")); } [Test] public void ChildSelectorAddsCorrectCallToStatement() { var statement = _sut.ChildSelector(new AndroidUiSelector()).Build(); - Assert.AreEqual(CtorStatement + $".childSelector({CtorStatement})", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + $".childSelector({CtorStatement})")); } [Test] public void ClassNameEqualsAddsCorrectCallToStatement() { var statement = _sut.ClassNameEquals("Class1").Build(); - Assert.AreEqual(CtorStatement + ".className(\"Class1\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".className(\"Class1\")")); } [Test] public void ClassNameMatchesAddsCorrectCallToStatement() { var statement = _sut.ClassNameMatches("regex").Build(); - Assert.AreEqual(CtorStatement + ".classNameMatches(\"regex\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".classNameMatches(\"regex\")")); } [Test] public void IsClickableAddsCorrectCallToStatement() { var statement = _sut.IsClickable(true).Build(); - Assert.AreEqual(CtorStatement + ".clickable(true)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".clickable(true)")); } [Test] public void DescriptionEqualsAddsCorrectCallToStatement() { var statement = _sut.DescriptionEquals("Desc").Build(); - Assert.AreEqual(CtorStatement + ".description(\"Desc\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".description(\"Desc\")")); } [Test] public void DescriptionContainsAddsCorrectCallToStatement() { var statement = _sut.DescriptionContains("Val").Build(); - Assert.AreEqual(CtorStatement + ".descriptionContains(\"Val\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".descriptionContains(\"Val\")")); } [Test] public void DescriptionMatchesAddsCorrectCallToStatement() { var statement = _sut.DescriptionMatches("regex").Build(); - Assert.AreEqual(CtorStatement + ".descriptionMatches(\"regex\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".descriptionMatches(\"regex\")")); } [Test] public void DescriptionStartsWithAddsCorrectCallToStatement() { var statement = _sut.DescriptionStartsWith("Hello").Build(); - Assert.AreEqual(CtorStatement + ".descriptionStartsWith(\"Hello\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".descriptionStartsWith(\"Hello\")")); } [Test] public void IsEnabledAddsCorrectCallToStatement() { var statement = _sut.IsEnabled(true).Build(); - Assert.AreEqual(CtorStatement + ".enabled(true)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".enabled(true)")); } [Test] public void IsFocusableAddsCorrectCallToStatement() { var statement = _sut.IsFocusable(true).Build(); - Assert.AreEqual(CtorStatement + ".focusable(true)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".focusable(true)")); } [Test] public void IsFocusedAddsCorrectCallToStatement() { var statement = _sut.IsFocused(false).Build(); - Assert.AreEqual(CtorStatement + ".focused(false)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".focused(false)")); } [Test] public void FromParentAddsCorrectCallToStatement() { var statement = _sut.FromParent(new AndroidUiSelector()).Build(); - Assert.AreEqual(CtorStatement + $".fromParent({CtorStatement})", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + $".fromParent({CtorStatement})")); } [Test] public void IndexAddsCorrectCallToStatement() { var statement = _sut.Index(7).Build(); - Assert.AreEqual(CtorStatement + ".index(7)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".index(7)")); } [Test] public void InstanceAddsCorrectCallToStatement() { var statement = _sut.Instance(4).Build(); - Assert.AreEqual(CtorStatement + ".instance(4)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".instance(4)")); } [Test] public void LongClickableAddsCorrectCallToStatement() { var statement = _sut.IsLongClickable(false).Build(); - Assert.AreEqual(CtorStatement + ".longClickable(false)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".longClickable(false)")); } [Test] public void PackageNameEqualsAddsCorrectCallToStatement() { var statement = _sut.PackageNameEquals("com.org.unique").Build(); - Assert.AreEqual(CtorStatement + ".packageName(\"com.org.unique\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".packageName(\"com.org.unique\")")); } [Test] public void PackageNameMatchesAddsCorrectCallToStatement() { var statement = _sut.PackageNameMatches("regex").Build(); - Assert.AreEqual(CtorStatement + ".packageNameMatches(\"regex\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".packageNameMatches(\"regex\")")); } [Test] public void ResourceIdEqualsAddsCorrectCallToStatement() { var statement = _sut.ResourceIdEquals("my-id").Build(); - Assert.AreEqual(CtorStatement + ".resourceId(\"my-id\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".resourceId(\"my-id\")")); } [Test] public void ResourceIdMatchesAddsCorrectCallToStatement() { var statement = _sut.ResourceIdMatches("regex").Build(); - Assert.AreEqual(CtorStatement + ".resourceIdMatches(\"regex\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".resourceIdMatches(\"regex\")")); } [Test] public void IsScrollableAddsCorrectCallToStatement() { var statement = _sut.IsScrollable(true).Build(); - Assert.AreEqual(CtorStatement + ".scrollable(true)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".scrollable(true)")); } [Test] public void IsSelectedAddsCorrectCallToStatement() { var statement = _sut.IsSelected(false).Build(); - Assert.AreEqual(CtorStatement + ".selected(false)", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".selected(false)")); } [Test] public void TextEqualsAddsCorrectCallToStatement() { var statement = _sut.TextEquals("some text").Build(); - Assert.AreEqual(CtorStatement + ".text(\"some text\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".text(\"some text\")")); } [Test] public void TextContainsAddsCorrectCallToStatement() { var statement = _sut.TextContains("some text").Build(); - Assert.AreEqual(CtorStatement + ".textContains(\"some text\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".textContains(\"some text\")")); } [Test] public void TextMatchesAddsCorrectCallToStatement() { var statement = _sut.TextMatches("some text").Build(); - Assert.AreEqual(CtorStatement + ".textMatches(\"some text\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".textMatches(\"some text\")")); } [Test] public void TextStartsWithAddsCorrectCallToStatement() { var statement = _sut.TextStartsWith("some text").Build(); - Assert.AreEqual(CtorStatement + ".textStartsWith(\"some text\")", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".textStartsWith(\"some text\")")); } [Test] public void AddRawTextAppendsText() { var statement = _sut.AddRawText("@").Build(); - Assert.AreEqual(CtorStatement + "@", statement); + Assert.That(statement, Is.EqualTo(CtorStatement + "@")); } [Test] @@ -225,8 +225,7 @@ public void CanChainCalls() .ClassNameEquals("andoid.widget.TextField") .IsLongClickable(true) .Build(); - Assert.AreEqual(CtorStatement + ".resourceIdMatches(\".*my_id\").className(\"andoid.widget.TextField\").longClickable(true)", - statement); + Assert.That(statement, Is.EqualTo(CtorStatement + ".resourceIdMatches(\".*my_id\").className(\"andoid.widget.TextField\").longClickable(true)")); } } } diff --git a/test/integration/Android/AppStringsTest.cs b/test/integration/Android/AppStringsTest.cs index b52df1ab..7ead7592 100644 --- a/test/integration/Android/AppStringsTest.cs +++ b/test/integration/Android/AppStringsTest.cs @@ -32,13 +32,13 @@ public void AfterAll() [Test] public void GetAppStrings() { - Assert.AreNotSame(0, _driver.GetAppStringDictionary().Count); + Assert.That(_driver.GetAppStringDictionary(), Is.Not.Empty); } [Test] public void GetAppStringsUsingLang() { - Assert.AreNotSame(0, _driver.GetAppStringDictionary("en").Count); + Assert.That(_driver.GetAppStringDictionary("en"), Is.Not.Empty); } } } \ No newline at end of file diff --git a/test/integration/Android/ClipboardTest.cs b/test/integration/Android/ClipboardTest.cs index 3d5d8537..64a23b9c 100644 --- a/test/integration/Android/ClipboardTest.cs +++ b/test/integration/Android/ClipboardTest.cs @@ -30,10 +30,11 @@ public void SetUp() _driver?.LaunchApp(); } - [TearDown] - public void TearDown() + [OneTimeTearDown] + public void OneTimeTearDown() { _driver?.CloseApp(); + _driver?.Quit(); } [Test] diff --git a/test/integration/Android/ConnectionTest.cs b/test/integration/Android/ConnectionTest.cs index 8212c18c..ad974276 100644 --- a/test/integration/Android/ConnectionTest.cs +++ b/test/integration/Android/ConnectionTest.cs @@ -33,10 +33,10 @@ public void AfterAll() public void NetworkConnectionTest() { ((AndroidDriver) _driver).ConnectionType = ConnectionType.AirplaneMode; - Assert.AreEqual(ConnectionType.AirplaneMode, ((AndroidDriver) _driver).ConnectionType); + Assert.That(((AndroidDriver) _driver).ConnectionType, Is.EqualTo(ConnectionType.AirplaneMode)); ((AndroidDriver) _driver).ConnectionType = ConnectionType.AllNetworkOn; - Assert.AreEqual(ConnectionType.AllNetworkOn, ((AndroidDriver) _driver).ConnectionType); + Assert.That(((AndroidDriver) _driver).ConnectionType, Is.EqualTo(ConnectionType.AllNetworkOn)); } } } \ No newline at end of file diff --git a/test/integration/Android/CurrentPackageTest.cs b/test/integration/Android/CurrentPackageTest.cs index 3b82a3ca..d477b743 100644 --- a/test/integration/Android/CurrentPackageTest.cs +++ b/test/integration/Android/CurrentPackageTest.cs @@ -27,10 +27,11 @@ public void SetUp() _driver?.LaunchApp(); } - [TearDown] + [OneTimeTearDown] public void TearDowwn() { _driver?.CloseApp(); + _driver?.Quit(); } [Test] diff --git a/test/integration/Android/Device/AuthenticationTest.cs b/test/integration/Android/Device/AuthenticationTest.cs index 6c608417..e6e1cdbd 100644 --- a/test/integration/Android/Device/AuthenticationTest.cs +++ b/test/integration/Android/Device/AuthenticationTest.cs @@ -25,10 +25,11 @@ public void SetUp() _driver?.LaunchApp(); } - [TearDown] - public void TearDown() + [OneTimeTearDown] + public void OneTimeTearDown() { _driver?.CloseApp(); + _driver?.Quit(); } [Test] diff --git a/test/integration/Android/Device/BrowserTests.cs b/test/integration/Android/Device/BrowserTests.cs index b179a459..46746732 100644 --- a/test/integration/Android/Device/BrowserTests.cs +++ b/test/integration/Android/Device/BrowserTests.cs @@ -34,7 +34,7 @@ public void TearDown() public void Browser() { _driver.Navigate().GoToUrl("https://github.com/appium"); - Assert.IsNotEmpty(_driver.PageSource); + Assert.That(_driver.PageSource, Is.Not.Empty); } } } \ No newline at end of file diff --git a/test/integration/Android/Device/KeyboardTests.cs b/test/integration/Android/Device/KeyboardTests.cs index f07481f6..0de1f999 100644 --- a/test/integration/Android/Device/KeyboardTests.cs +++ b/test/integration/Android/Device/KeyboardTests.cs @@ -48,7 +48,7 @@ public void IsKeyBoardShownTestCase() _driver.FindElement(text_edit_btn).Clear(); _driver.FindElement(text_edit_btn).Click(); bool keyboard_bool = _driver.IsKeyboardShown(); - Assert.IsTrue(keyboard_bool); + Assert.That(keyboard_bool); } } } \ No newline at end of file diff --git a/test/integration/Android/Device/PerformanceDataTests.cs b/test/integration/Android/Device/PerformanceDataTests.cs index e9649745..e073310a 100644 --- a/test/integration/Android/Device/PerformanceDataTests.cs +++ b/test/integration/Android/Device/PerformanceDataTests.cs @@ -33,7 +33,7 @@ public void TearDown() public void GetPerformanceDataTypesTest() { var androidDriver = _driver as AndroidDriver; - Assert.IsNotNull(androidDriver.GetPerformanceDataTypes()); + Assert.That(androidDriver.GetPerformanceDataTypes(), Is.Not.Null); } [Test] diff --git a/test/integration/Android/ElementTest.cs b/test/integration/Android/ElementTest.cs index c331b10e..de7b56bd 100644 --- a/test/integration/Android/ElementTest.cs +++ b/test/integration/Android/ElementTest.cs @@ -33,29 +33,35 @@ public void SetUp() public void FindByAccessibilityIdTest() { By byAccessibilityId = new ByAccessibilityId("Graphics"); - Assert.AreNotEqual(_driver.FindElement(MobileBy.Id("android:id/content")).FindElement(byAccessibilityId).Text, null); - Assert.AreNotEqual(_driver.FindElement(MobileBy.Id("android:id/content")).Text, null); - Assert.GreaterOrEqual(_driver.FindElement(MobileBy.Id("android:id/content")).FindElements(byAccessibilityId).Count, - 1); + Assert.Multiple(() => + { + Assert.That(_driver.FindElement(MobileBy.Id("android:id/content")).FindElement(byAccessibilityId).Text, Is.Not.EqualTo(null)); + Assert.That(_driver.FindElement(MobileBy.Id("android:id/content")).Text, Is.Not.EqualTo(null)); + Assert.That(_driver.FindElement(MobileBy.Id("android:id/content")).FindElements(byAccessibilityId), Is.Not.Empty); + }); } [Test] public void FindByAndroidUiAutomatorTest() { By byAndroidUiAutomator = new ByAndroidUIAutomator("new UiSelector().clickable(true)"); - Assert.IsNotNull(_driver.FindElement(MobileBy.Id("android:id/content")).FindElement(byAndroidUiAutomator).Text); - Assert.GreaterOrEqual(_driver.FindElement(MobileBy.Id("android:id/content")).FindElements(byAndroidUiAutomator).Count, - 1); + Assert.Multiple(() => + { + Assert.That(_driver.FindElement(MobileBy.Id("android:id/content")).FindElement(byAndroidUiAutomator).Text, Is.Not.Null); + Assert.That(_driver.FindElement(MobileBy.Id("android:id/content")).FindElements(byAndroidUiAutomator), Is.Not.Empty); + }); } [Test] public void FindByAndroidUiAutomatorBuilderTest() { By byAndroidUiAutomator = new ByAndroidUIAutomator(new AndroidUiSelector().IsClickable(true)); - Assert.IsNotNull(_driver.FindElement(MobileBy.Id("android:id/content")).FindElement(byAndroidUiAutomator).Text); - Assert.GreaterOrEqual( - _driver.FindElement(MobileBy.Id("android:id/content")).FindElements(byAndroidUiAutomator).Count, - 1); + Assert.Multiple(() => + { + Assert.That(_driver.FindElement(MobileBy.Id("android:id/content")).FindElement(byAndroidUiAutomator).Text, Is.Not.Null); + Assert.That( + _driver.FindElement(MobileBy.Id("android:id/content")).FindElements(byAndroidUiAutomator), Is.Not.Empty); + }); } [Test] @@ -67,8 +73,11 @@ public void CanFindByDescriptionUsingBuilderWhenNewlineCharacterIncluded() "2. Enable Explore-by-Touch (Settings -> Accessibility -> Explore by Touch). \n\n" + "3. Touch explore the list.")); - Assert.IsNotNull(_driver.FindElement(MobileBy.Id("android:id/content")).FindElement(byAndroidUiAutomator).Text); - Assert.GreaterOrEqual(_driver.FindElement(MobileBy.Id("android:id/content")).FindElements(byAndroidUiAutomator).Count, 1); + Assert.Multiple(() => + { + Assert.That(_driver.FindElement(MobileBy.Id("android:id/content")).FindElement(byAndroidUiAutomator).Text, Is.Not.Null); + Assert.That(_driver.FindElement(MobileBy.Id("android:id/content")).FindElements(byAndroidUiAutomator), Is.Not.Empty); + }); } [Test] @@ -78,8 +87,11 @@ public void CanFindByDescriptionUsingBuilderWhenDoubleQuoteCharacterIncluded() By byAndroidUiAutomator = new ByAndroidUIAutomator(new AndroidUiSelector() .DescriptionContains("Use a \"tel:\" URL")); - Assert.IsNotNull(_driver.FindElement(MobileBy.Id("android:id/content")).FindElement(byAndroidUiAutomator).Text); - Assert.GreaterOrEqual(_driver.FindElement(MobileBy.Id("android:id/content")).FindElements(byAndroidUiAutomator).Count, 1); + Assert.Multiple(() => + { + Assert.That(_driver.FindElement(MobileBy.Id("android:id/content")).FindElement(byAndroidUiAutomator).Text, Is.Not.Null); + Assert.That(_driver.FindElement(MobileBy.Id("android:id/content")).FindElements(byAndroidUiAutomator), Is.Not.Empty); + }); } [Test] @@ -95,12 +107,12 @@ public void ReplaceValueTest() editElement.SendKeys(originalValue); - Assert.AreEqual(originalValue, editElement.Text); + Assert.That(editElement.Text, Is.EqualTo(originalValue)); _driver.ExecuteScript("mobile: replaceElementValue", new Dictionary { { "elementId", editElement.Id } , { "text", replacedValue } }); - Assert.AreEqual(replacedValue, editElement.Text); + Assert.That(editElement.Text, Is.EqualTo(replacedValue)); } @@ -112,7 +124,11 @@ public void ScrollingToSubElement() var locator = new ByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(" + "new UiSelector().text(\"Radio Group\"));"); var radioGroup = list.FindElement(locator); - Assert.NotNull(radioGroup.Location); + Assert.Multiple(() => + { + Assert.That(radioGroup.Location.X, Is.GreaterThanOrEqualTo(0)); + Assert.That(radioGroup.Location.Y, Is.GreaterThanOrEqualTo(0)); + }); } [Test] @@ -123,7 +139,11 @@ public void ScrollingToSubElementUsingBuilder() var locator = new ByAndroidUIAutomator(new AndroidUiScrollable() .ScrollIntoView(new AndroidUiSelector().TextEquals("Radio Group"))); var radioGroup = list.FindElement(locator); - Assert.NotNull(radioGroup.Location); + Assert.Multiple(() => + { + Assert.That(radioGroup.Location.X, Is.GreaterThanOrEqualTo(0)); + Assert.That(radioGroup.Location.Y, Is.GreaterThanOrEqualTo(0)); + }); } [Test] @@ -131,7 +151,7 @@ public void FindAppiumElementUsingNestedElement() { var myElement = _driver.FindElement(MobileBy.Id("android:id/content")); AppiumElement nestedElement = myElement.FindElement(By.Id("android:id/text1")); - Assert.NotNull(nestedElement); + Assert.That(nestedElement, Is.Not.Null); } [Test] @@ -139,7 +159,7 @@ public void FindAppiumElementsListUsingNestedElement() { var myElement = _driver.FindElement(MobileBy.Id("android:id/content")); IList myDerivedElements = myElement.FindElements(By.Id("android:id/text1")); - Assert.AreNotEqual(myDerivedElements.Count,0); + Assert.That(myDerivedElements, Is.Not.Empty); } [OneTimeTearDown] diff --git a/test/integration/Android/ElementTestEspresso.cs b/test/integration/Android/ElementTestEspresso.cs index 2ee7c43d..8fc07e3c 100644 --- a/test/integration/Android/ElementTestEspresso.cs +++ b/test/integration/Android/ElementTestEspresso.cs @@ -35,12 +35,13 @@ public void FindByAndroidDataMatcherTest() By byAndroidDataMatcher = new ByAndroidDataMatcher(selectorData); - Assert.AreNotEqual( - _driver.FindElement(MobileBy.Id("android:id/list")).FindElement(byAndroidDataMatcher).Text, - null); - Assert.GreaterOrEqual( - _driver.FindElement(MobileBy.Id("android:id/list")).FindElements(byAndroidDataMatcher).Count, - 1); + Assert.Multiple(() => + { + Assert.That( + Is.Not.EqualTo(_driver.FindElement(MobileBy.Id("android:id/list")).FindElement(byAndroidDataMatcher).Text), null); + Assert.That( + _driver.FindElement(MobileBy.Id("android:id/list")).FindElements(byAndroidDataMatcher), Is.Not.Empty); + }); } [Test] @@ -56,12 +57,13 @@ public void FindByAndroidViewMatcherTest() By byAndroidViewMatcher = new ByAndroidViewMatcher(selectorData); - Assert.AreNotEqual( - _driver.FindElement(MobileBy.Id("android:id/list")).FindElement(byAndroidViewMatcher).Text, - null); - Assert.GreaterOrEqual( - _driver.FindElement(MobileBy.Id("android:id/list")).FindElements(byAndroidViewMatcher).Count, - 1); + Assert.Multiple(() => + { + Assert.That( + Is.Not.EqualTo(_driver.FindElement(MobileBy.Id("android:id/list")).FindElement(byAndroidViewMatcher).Text), null); + Assert.That( + _driver.FindElement(MobileBy.Id("android:id/list")).FindElements(byAndroidViewMatcher), Is.Not.Empty); + }); } [OneTimeTearDown] diff --git a/test/integration/Android/EmulatorDeviceTime.cs b/test/integration/Android/EmulatorDeviceTime.cs index cec25d69..feb96e16 100644 --- a/test/integration/Android/EmulatorDeviceTime.cs +++ b/test/integration/Android/EmulatorDeviceTime.cs @@ -38,10 +38,10 @@ public void DeviceTimeTest() var time = _driver.DeviceTime; Assert.Multiple(() => { - Assert.NotNull(time); - Assert.AreNotEqual(Empty, time); + Assert.That(time, Is.Not.Null); + Assert.That(time, Is.Not.EqualTo(Empty)); Console.WriteLine(time); - Assert.NotNull(DateTime.Parse(time)); + Assert.That(DateTime.Parse(time), Is.Not.EqualTo(DateTime.Now.AddDays(3))); }); } } diff --git a/test/integration/Android/FileInteractionTest.cs b/test/integration/Android/FileInteractionTest.cs index 43b28032..e09311a2 100644 --- a/test/integration/Android/FileInteractionTest.cs +++ b/test/integration/Android/FileInteractionTest.cs @@ -40,7 +40,7 @@ public void PushStringTest() _driver.PushFile("/data/local/tmp/remote.txt", data); var returnDataBytes = _driver.PullFile("/data/local/tmp/remote.txt"); var returnedData = Encoding.UTF8.GetString(returnDataBytes); - Assert.AreEqual(data, returnedData); + Assert.That(returnedData, Is.EqualTo(data)); } [Test] @@ -54,7 +54,7 @@ public void PushBytesTest() _driver.PushFile("/data/local/tmp/remote.txt", Convert.FromBase64String(base64)); var returnDataBytes = _driver.PullFile("/data/local/tmp/remote.txt"); var returnedData = Encoding.UTF8.GetString(returnDataBytes); - Assert.AreEqual(data, returnedData); + Assert.That(returnedData, Is.EqualTo(data)); } [Test] @@ -73,9 +73,8 @@ public void PushFileTest() _driver.PushFile("/data/local/tmp/remote.txt", file); var returnDataBytes = _driver.PullFile("/data/local/tmp/remote.txt"); var returnedData = Encoding.UTF8.GetString(returnDataBytes); - Assert.AreEqual( - "The eventual code is no more than the deposit of your understanding. ~E. W. Dijkstra", - returnedData); + Assert.That( + returnedData, Is.EqualTo("The eventual code is no more than the deposit of your understanding. ~E. W. Dijkstra")); } finally { diff --git a/test/integration/Android/LockDeviceTest.cs b/test/integration/Android/LockDeviceTest.cs index 2eb9c40e..babbebd0 100644 --- a/test/integration/Android/LockDeviceTest.cs +++ b/test/integration/Android/LockDeviceTest.cs @@ -33,9 +33,9 @@ public void AfterEach() public void LockTest() { _driver.Lock(); - Assert.AreEqual(true, _driver.IsLocked()); + Assert.That(_driver.IsLocked(), Is.EqualTo(true)); _driver.Unlock(); - Assert.AreEqual(false, _driver.IsLocked()); + Assert.That(_driver.IsLocked(), Is.EqualTo(false)); } } } \ No newline at end of file diff --git a/test/integration/Android/OrientationTest.cs b/test/integration/Android/OrientationTest.cs index d6440370..093b0af2 100644 --- a/test/integration/Android/OrientationTest.cs +++ b/test/integration/Android/OrientationTest.cs @@ -36,7 +36,7 @@ public void DeviceOrientationTest() { var rotatable = ((IRotatable) _driver); rotatable.Orientation = ScreenOrientation.Portrait; - Assert.AreEqual(ScreenOrientation.Portrait, rotatable.Orientation); + Assert.That(rotatable.Orientation, Is.EqualTo(ScreenOrientation.Portrait)); } } } \ No newline at end of file diff --git a/test/integration/Android/ScreenRecordingTest.cs b/test/integration/Android/ScreenRecordingTest.cs index a0468f47..b301f77e 100644 --- a/test/integration/Android/ScreenRecordingTest.cs +++ b/test/integration/Android/ScreenRecordingTest.cs @@ -38,7 +38,7 @@ public void ScreenRecordTest() _driver.StartRecordingScreen(); Thread.Sleep(1000); var result = _driver.StopRecordingScreen(); - Assert.IsNotEmpty(result); + Assert.That(result, Is.Not.Empty); } [Test] @@ -51,7 +51,7 @@ public void ScreenRecordWithOptionsTest() .WithVideoSize("720x1280")); Thread.Sleep(1000); var result = _driver.StopRecordingScreen(); - Assert.IsNotEmpty(result); + Assert.That(result, Is.Not.Empty); } } } diff --git a/test/integration/Android/SearchingTest.cs b/test/integration/Android/SearchingTest.cs index 7fc61297..c9278d80 100644 --- a/test/integration/Android/SearchingTest.cs +++ b/test/integration/Android/SearchingTest.cs @@ -42,24 +42,33 @@ public void AfterAll() public void FindByAccessibilityIdTest() { By byAccessibilityId = new ByAccessibilityId("Graphics"); - Assert.AreNotEqual(_driver.FindElement(byAccessibilityId).Text, null); - Assert.GreaterOrEqual(_driver.FindElements(byAccessibilityId).Count, 1); + Assert.Multiple(() => + { + Assert.That(_driver.FindElement(byAccessibilityId).Text, Is.EqualTo("Graphics")); + Assert.That(_driver.FindElements(byAccessibilityId), Is.Not.Empty); + }); } [Test] public void FindByAndroidUiAutomatorTest() { By byAndroidUiAutomator = new ByAndroidUIAutomator("new UiSelector().clickable(true)"); - Assert.IsNotNull(_driver.FindElement(byAndroidUiAutomator).Text); - Assert.GreaterOrEqual(_driver.FindElements(byAndroidUiAutomator).Count, 1); + Assert.Multiple(() => + { + Assert.That(_driver.FindElement(byAndroidUiAutomator).Text, Is.Not.Null); + Assert.That(_driver.FindElements(byAndroidUiAutomator), Is.Not.Empty); + }); } [Test] public void FindByXPathTest() { var byXPath = "//android.widget.TextView[contains(@text, 'Animat')]"; - Assert.IsNotNull(_driver.FindElement(MobileBy.XPath( byXPath)).Text); - Assert.AreEqual(1, _driver.FindElements(MobileBy.XPath(byXPath)).Count); + Assert.Multiple(() => + { + Assert.That(_driver.FindElement(By.XPath(byXPath)).Text, Is.Not.Null); + Assert.That(_driver.FindElements(By.XPath(byXPath)), Has.Count.EqualTo(1)); + }); } [Test] @@ -70,7 +79,7 @@ public void FindScrollable() .FindElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()" + ".resourceId(\"android:id/list\")).scrollIntoView(" + "new UiSelector().text(\"Radio Group\"));")); - Assert.NotNull(radioGroup.Location); + Assert.That(radioGroup.Location.X, Is.Not.Negative); } } } \ No newline at end of file diff --git a/test/integration/Android/Session/GeolocationTests.cs b/test/integration/Android/Session/GeolocationTests.cs index fd32be5f..83ccf319 100644 --- a/test/integration/Android/Session/GeolocationTests.cs +++ b/test/integration/Android/Session/GeolocationTests.cs @@ -38,9 +38,9 @@ public void GetLocationTest() { Assert.That(() => _driver.Location, Is.Not.Null); Assert.DoesNotThrow(() => _driver.Location.ToDictionary()); - Assert.That(_driver.Location.Altitude, Is.Not.Null.Or.Empty); - Assert.That(_driver.Location.Longitude, Is.Not.Null.Or.Empty); - Assert.That(_driver.Location.Latitude, Is.Not.Null.Or.Empty); + Assert.That(_driver.Location.Altitude, Is.Not.Empty); + Assert.That(_driver.Location.Longitude, Is.Not.Empty); + Assert.That(_driver.Location.Latitude, Is.Not.Empty); }); } @@ -58,9 +58,9 @@ public void SetLocationTest() { Assert.That(() => _driver.Location, Is.Not.Null); Assert.DoesNotThrow(() => _driver.Location.ToDictionary()); - Assert.That(_driver.Location.Altitude, Is.Not.Null.Or.Empty); - Assert.That(_driver.Location.Longitude, Is.Not.Null.Or.Empty); - Assert.That(_driver.Location.Latitude, Is.Not.Null.Or.Empty); + Assert.That(_driver.Location.Altitude, Is.Not.Empty); + Assert.That(_driver.Location.Longitude, Is.Not.Empty); + Assert.That(_driver.Location.Latitude, Is.Not.Empty); }); } } diff --git a/test/integration/Android/Session/LogTests.cs b/test/integration/Android/Session/LogTests.cs index 982cacf2..df6f7e91 100644 --- a/test/integration/Android/Session/LogTests.cs +++ b/test/integration/Android/Session/LogTests.cs @@ -40,7 +40,7 @@ public void CanRetrieveLogTypesTest() Assert.Multiple(() => { Assert.That(logs.AvailableLogTypes, Is.Not.Null); - Assert.That(availableLogTypes.Count, Is.GreaterThan(0), nameof(availableLogTypes)); + Assert.That(availableLogTypes, Is.Not.Empty, nameof(availableLogTypes)); }); Console.WriteLine(@"Available log types:"); foreach (var logType in availableLogTypes) @@ -54,7 +54,7 @@ public void CanCaptureLogcatTest() { var availableLogTypes = _driver.Manage().Logs.AvailableLogTypes; Assert.That(availableLogTypes, Is.Not.Null); - CollectionAssert.Contains(availableLogTypes, LogcatLogType); + Assert.That(availableLogTypes, Has.Member(LogcatLogType)); Assert.DoesNotThrow(() => _driver.Manage().Logs.GetLog(LogcatLogType)); } @@ -64,7 +64,7 @@ public void CanCaptureServerTest() { var availableLogTypes = _driver.Manage().Logs.AvailableLogTypes; Assert.That(availableLogTypes, Is.Not.Null); - CollectionAssert.Contains(availableLogTypes, ServerLogType); + Assert.That(availableLogTypes, Has.Member(ServerLogType)); var appiumServerLog = _driver.Manage().Logs.GetLog(LogType.Server); Assert.That(appiumServerLog, Is.Not.Null.And.Count.GreaterThan(1)); @@ -81,7 +81,7 @@ public void CanCaptureBugReportTest() { var availableLogTypes = _driver.Manage().Logs.AvailableLogTypes; Assert.That(availableLogTypes, Is.Not.Null); - CollectionAssert.Contains(availableLogTypes, BugReportLogType); + Assert.That(availableLogTypes, Has.Member(BugReportLogType)); var bugReportLogEntry = _driver.Manage().Logs.GetLog(BugReportLogType); Assert.That(bugReportLogEntry, Is.Not.Null.And.Count.EqualTo(1)); diff --git a/test/integration/Android/SessionTest.cs b/test/integration/Android/SessionTest.cs index 4f2cc559..7928d44e 100644 --- a/test/integration/Android/SessionTest.cs +++ b/test/integration/Android/SessionTest.cs @@ -35,14 +35,14 @@ public void AfterAll() public void GetDeviceUdidTest() { var deviceUiid = _driver.SessionDetails["deviceUDID"].ToString(); - Assert.NotNull(deviceUiid); + Assert.That(deviceUiid, Is.Not.Null); } [Test] public void GetDeviceDictionaryData() { var dictionary = (Dictionary) _driver.SessionDetails["desired"]; - Assert.AreNotEqual(dictionary.Count, 0); + Assert.That(dictionary.Count, Is.Not.EqualTo(0)); } } } \ No newline at end of file diff --git a/test/integration/Android/SettingTest.cs b/test/integration/Android/SettingTest.cs index 4113f5e4..018778b7 100644 --- a/test/integration/Android/SettingTest.cs +++ b/test/integration/Android/SettingTest.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using Appium.Net.Integration.Tests.helpers; using NUnit.Framework; -using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Android; using OpenQA.Selenium.Appium.Android.Enums; @@ -29,10 +28,10 @@ public void IgnoreUnimportantViewsTest() _driver.IgnoreUnimportantViews(true); var ignoreViews = (bool) _driver.Settings[AutomatorSetting.IgnoreUnimportantViews]; - Assert.True(ignoreViews); + Assert.That(ignoreViews, Is.True); _driver.IgnoreUnimportantViews(false); ignoreViews = (bool) _driver.Settings[AutomatorSetting.IgnoreUnimportantViews]; - Assert.False(ignoreViews); + Assert.That(ignoreViews, Is.False); } [Test] @@ -45,11 +44,14 @@ public void ConfiguratorTest() _driver.ConfiguratorSetWaitForSelectorTimeout(1000); var settings = _driver.Settings; - Assert.AreEqual(settings[AutomatorSetting.KeyInjectionDelay], 400); - Assert.AreEqual(settings[AutomatorSetting.WaitActionAcknowledgmentTimeout], 500); - Assert.AreEqual(settings[AutomatorSetting.WaitForIDLETimeout], 600); - Assert.AreEqual(settings[AutomatorSetting.WaitForSelectorTimeout], 1000); - Assert.AreEqual(settings[AutomatorSetting.WaitScrollAcknowledgmentTimeout], 300); + Assert.Multiple(() => + { + Assert.That(settings[AutomatorSetting.KeyInjectionDelay], Is.EqualTo(400)); + Assert.That(settings[AutomatorSetting.WaitActionAcknowledgmentTimeout], Is.EqualTo(500)); + Assert.That(settings[AutomatorSetting.WaitForIDLETimeout], Is.EqualTo(600)); + Assert.That(settings[AutomatorSetting.WaitForSelectorTimeout], Is.EqualTo(1000)); + Assert.That(settings[AutomatorSetting.WaitScrollAcknowledgmentTimeout], Is.EqualTo(300)); + }); } [Test] @@ -66,11 +68,14 @@ public void ConfiguratorPropertyTest() _driver.Settings = data; var settings = _driver.Settings; - Assert.AreEqual(settings[AutomatorSetting.KeyInjectionDelay], 1500); - Assert.AreEqual(settings[AutomatorSetting.WaitActionAcknowledgmentTimeout], 2500); - Assert.AreEqual(settings[AutomatorSetting.WaitForIDLETimeout], 3500); - Assert.AreEqual(settings[AutomatorSetting.WaitForSelectorTimeout], 5000); - Assert.AreEqual(settings[AutomatorSetting.WaitScrollAcknowledgmentTimeout], 7000); + Assert.Multiple(() => + { + Assert.That(settings[AutomatorSetting.KeyInjectionDelay], Is.EqualTo(1500)); + Assert.That(settings[AutomatorSetting.WaitActionAcknowledgmentTimeout], Is.EqualTo(2500)); + Assert.That(settings[AutomatorSetting.WaitForIDLETimeout], Is.EqualTo(3500)); + Assert.That(settings[AutomatorSetting.WaitForSelectorTimeout], Is.EqualTo(5000)); + Assert.That(settings[AutomatorSetting.WaitScrollAcknowledgmentTimeout], Is.EqualTo(7000)); + }); } [OneTimeTearDown] diff --git a/test/integration/Android/TouchActionTest.cs b/test/integration/Android/TouchActionTest.cs index a8179426..e48c01f2 100644 --- a/test/integration/Android/TouchActionTest.cs +++ b/test/integration/Android/TouchActionTest.cs @@ -63,7 +63,7 @@ public void SimpleTouchActionTestCase() els = _driver.FindElements(MobileBy.ClassName("android.widget.TextView")); - Assert.AreNotEqual(number1, els.Count); + Assert.That(els.Count, Is.Not.EqualTo(number1)); } [Test] @@ -80,7 +80,7 @@ public void ComplexTouchActionTestCase() var touchAction = new TouchAction(_driver); touchAction.Press(loc1.X, loc1.Y).Wait(800) .MoveTo(loc2.X, loc2.Y).Release().Perform(); - Assert.AreNotEqual(loc2.Y, target.Location.Y); + Assert.That(target.Location.Y, Is.Not.EqualTo(loc2.Y)); } [Test] @@ -102,7 +102,7 @@ public void SingleMultiActionTestCase() var multiAction = new MultiAction(_driver); multiAction.Add(swipe).Perform(); - Assert.AreNotEqual(loc2.Y, target.Location.Y); + Assert.That(target.Location.Y, Is.Not.EqualTo(loc2.Y)); } [Test] @@ -113,7 +113,7 @@ public void SequentalMultiActionTestCase() var multiTouch = new MultiAction(_driver); var tap1 = new TouchAction(_driver); - tap1.Press(els[5]).Wait(1500).Release(); + tap1.Press(els[6]).Wait(1500).Release(); multiTouch.Add(tap1).Add(tap1).Perform(); @@ -127,7 +127,7 @@ public void SequentalMultiActionTestCase() multiTouch2.Add(tap2).Add(tap2).Perform(); Thread.Sleep(2500); - Assert.AreNotEqual(originalActivity, _driver.CurrentActivity); + Assert.That(_driver.CurrentActivity, Is.Not.EqualTo(originalActivity)); } } } \ No newline at end of file diff --git a/test/integration/Android/WaitTests.cs b/test/integration/Android/WaitTests.cs index 2f3e05bb..6b8c8f61 100644 --- a/test/integration/Android/WaitTests.cs +++ b/test/integration/Android/WaitTests.cs @@ -46,7 +46,7 @@ public void WebDriverWaitElementNotFoundTestCase() catch (Exception wx) { var excpetionType = wx.GetType(); - Assert.AreEqual(excpetionType, typeof(WebDriverTimeoutException)); + Assert.That(typeof(WebDriverTimeoutException), Is.EqualTo(excpetionType)); } } @@ -67,7 +67,7 @@ public void WebDriverWaitIsWaitingTestCase() { stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Assert.AreEqual(ts.Seconds, _driverTimeOut.Seconds); + Assert.That(_driverTimeOut.Seconds, Is.EqualTo(ts.Seconds)); } } diff --git a/test/integration/Appium.Net.Integration.Tests.csproj b/test/integration/Appium.Net.Integration.Tests.csproj index dc85c222..ca1e4ea2 100644 --- a/test/integration/Appium.Net.Integration.Tests.csproj +++ b/test/integration/Appium.Net.Integration.Tests.csproj @@ -10,6 +10,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/integration/IOS/AlertTests.cs b/test/integration/IOS/AlertTests.cs index 2a9e2fe3..96549c02 100644 --- a/test/integration/IOS/AlertTests.cs +++ b/test/integration/IOS/AlertTests.cs @@ -51,7 +51,7 @@ public void TextAlertTest() _driver.FindElement(MobileBy.IosNSPredicate("label == 'show alert'")).Click(); Thread.Sleep(500); string alertText = _driver.SwitchTo().Alert().Text; - Assert.AreEqual("Cool title\r\nthis alert is so cool.", alertText); + Assert.That(alertText, Is.EqualTo("Cool title\r\nthis alert is so cool.")); } } } \ No newline at end of file diff --git a/test/integration/IOS/AppStringsTest.cs b/test/integration/IOS/AppStringsTest.cs index 49b4983d..86f3835c 100644 --- a/test/integration/IOS/AppStringsTest.cs +++ b/test/integration/IOS/AppStringsTest.cs @@ -31,19 +31,19 @@ public void AfterEach() [Test] public void GetAppStrings() { - Assert.AreNotSame(0, _driver.GetAppStringDictionary().Count); + Assert.That(_driver.GetAppStringDictionary(), Is.Not.Empty); } [Test] public void GetAppStringsUsingLang() { - Assert.AreNotSame(0, _driver.GetAppStringDictionary("en").Count); + Assert.That(_driver.GetAppStringDictionary("en"), Is.Not.Empty); } [Test] public void GetAppStringsUsingLangAndFileStrings() { - Assert.AreNotSame(0, _driver.GetAppStringDictionary("en", "Localizable.strings").Count); + Assert.That(_driver.GetAppStringDictionary("en", "Localizable.strings"), Is.Not.Empty); } } } \ No newline at end of file diff --git a/test/integration/IOS/ElementTest.cs b/test/integration/IOS/ElementTest.cs index 028c05c4..4f598cd3 100644 --- a/test/integration/IOS/ElementTest.cs +++ b/test/integration/IOS/ElementTest.cs @@ -33,19 +33,22 @@ public void AfterEach() public void FindByAccessibilityIdTest() { By byAccessibilityId = new ByAccessibilityId("ComputeSumButton"); - Assert.AreNotEqual(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElement(byAccessibilityId).Text, - null); - Assert.GreaterOrEqual(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElements(byAccessibilityId).Count, - 1); + Assert.Multiple(() => + { + Assert.That(Is.Not.EqualTo(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElement(byAccessibilityId).Text), null); + Assert.That(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElements(byAccessibilityId), Is.Not.Empty); + }); } [Test] public void FindByByIosUiAutomationTest() { By byIosUiAutomation = new ByIosUIAutomation(".elements().withName(\"Answer\")"); - Assert.IsNotNull(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElement(byIosUiAutomation).Text); - Assert.GreaterOrEqual(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElements(byIosUiAutomation).Count, - 1); + Assert.Multiple(() => + { + Assert.That(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElement(byIosUiAutomation).Text, Is.Not.Null); + Assert.That(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElements(byIosUiAutomation), Is.Not.Empty); + }); } } diff --git a/test/integration/IOS/LockDeviceTest.cs b/test/integration/IOS/LockDeviceTest.cs index 0efcccc8..520aacd1 100644 --- a/test/integration/IOS/LockDeviceTest.cs +++ b/test/integration/IOS/LockDeviceTest.cs @@ -32,33 +32,33 @@ public void Cleanup() [Test] public void IsLockedTest() { - Assert.AreEqual(_driver.IsLocked(), false); + Assert.That(_driver.IsLocked(), Is.EqualTo(false)); } [Test] public void LockTest() { - Assert.AreEqual(_driver.IsLocked(), false); + Assert.That(_driver.IsLocked(), Is.EqualTo(false)); _driver.Lock(); - Assert.AreEqual(_driver.IsLocked(), true); + Assert.That(_driver.IsLocked(), Is.EqualTo(true)); } [Test] public void LockTestWithSeconds() { - Assert.AreEqual(_driver.IsLocked(), false); + Assert.That(_driver.IsLocked(), Is.EqualTo(false)); _driver.Lock(5); - Assert.AreEqual(_driver.IsLocked(), false); + Assert.That(_driver.IsLocked(), Is.EqualTo(false)); } [Test] public void UnlockTest() { - Assert.AreEqual(_driver.IsLocked(), false); + Assert.That(_driver.IsLocked(), Is.EqualTo(false)); _driver.Lock(); - Assert.AreEqual(_driver.IsLocked(), true); + Assert.That(_driver.IsLocked(), Is.EqualTo(true)); _driver.Unlock(); - Assert.AreEqual(_driver.IsLocked(), false); + Assert.That(_driver.IsLocked(), Is.EqualTo(false)); } } } \ No newline at end of file diff --git a/test/integration/IOS/OrientationTest.cs b/test/integration/IOS/OrientationTest.cs index f23d9302..306e394e 100644 --- a/test/integration/IOS/OrientationTest.cs +++ b/test/integration/IOS/OrientationTest.cs @@ -34,7 +34,7 @@ public void DeviceOrientationTest() { var rotatable = ((IRotatable) _driver); rotatable.Orientation = ScreenOrientation.Landscape; - Assert.AreEqual(ScreenOrientation.Landscape, rotatable.Orientation); + Assert.That(rotatable.Orientation, Is.EqualTo(ScreenOrientation.Landscape)); } } } \ No newline at end of file diff --git a/test/integration/IOS/ScreenRecordingTest.cs b/test/integration/IOS/ScreenRecordingTest.cs index 3cb85003..6917d2b9 100644 --- a/test/integration/IOS/ScreenRecordingTest.cs +++ b/test/integration/IOS/ScreenRecordingTest.cs @@ -37,7 +37,7 @@ public void ScreenRecordTest() _driver.StartRecordingScreen(); Thread.Sleep(1000); var result = _driver.StopRecordingScreen(); - Assert.IsNotEmpty(result); + Assert.That(result, Is.Not.Empty); } [Test] @@ -51,7 +51,7 @@ public void ScreenRecordWithOptionsTest() .WithVideoScale("320:240")); Thread.Sleep(1000); var result = _driver.StopRecordingScreen(); - Assert.IsNotEmpty(result); + Assert.That(result, Is.Not.Empty); } } } diff --git a/test/integration/IOS/ScrollingSearchingTest.cs b/test/integration/IOS/ScrollingSearchingTest.cs index cc9fbb70..749525f9 100644 --- a/test/integration/IOS/ScrollingSearchingTest.cs +++ b/test/integration/IOS/ScrollingSearchingTest.cs @@ -34,7 +34,7 @@ public void ScrollToTestCase() var slider = _driver .FindElement(new ByIosUIAutomation(".tableViews()[0]" + ".scrollToElementWithPredicate(\"name CONTAINS 'Slider'\")")); - Assert.AreEqual(slider.GetAttribute("name"), "Sliders"); + Assert.That(slider.GetAttribute("name"), Is.EqualTo("Sliders")); } [Test] @@ -43,7 +43,7 @@ public void ScrollToExactTestCase() var table = _driver.FindElement(new ByIosUIAutomation(".tableViews()[0]")); var slider = table.FindElement( new ByIosUIAutomation(".scrollToElementWithPredicate(\"name CONTAINS 'Slider'\")")); - Assert.AreEqual(slider.GetAttribute("name"), "Sliders"); + Assert.That(slider.GetAttribute("name"), Is.EqualTo("Sliders")); } } } \ No newline at end of file diff --git a/test/integration/IOS/SearchingClassChainTest.cs b/test/integration/IOS/SearchingClassChainTest.cs index d6813a06..3990072d 100644 --- a/test/integration/IOS/SearchingClassChainTest.cs +++ b/test/integration/IOS/SearchingClassChainTest.cs @@ -34,9 +34,9 @@ public void FindByClassChainTest() var sliderCellStaticTextElements1 = _driver .FindElements( new ByIosClassChain("**/XCUIElementTypeCell/XCUIElementTypeStaticText[`name == 'Sliders'`]")); - Assert.AreEqual(1, sliderCellStaticTextElements1.Count); + Assert.That(sliderCellStaticTextElements1.Count, Is.EqualTo(1)); var sliderCellStaticTextElements2 = _driver.FindElements(MobileBy.IosClassChain("**/XCUIElementTypeCell")); - Assert.AreEqual(18, sliderCellStaticTextElements2.Count); + Assert.That(sliderCellStaticTextElements2.Count, Is.EqualTo(18)); } } } \ No newline at end of file diff --git a/test/integration/IOS/SearchingTest.cs b/test/integration/IOS/SearchingTest.cs index 185e47a4..7c705f34 100644 --- a/test/integration/IOS/SearchingTest.cs +++ b/test/integration/IOS/SearchingTest.cs @@ -40,16 +40,22 @@ public void AfterAll() public void FindByAccessibilityIdTest() { By byAccessibilityId = new ByAccessibilityId("ComputeSumButton"); - Assert.AreNotEqual(_driver.FindElement(byAccessibilityId).Text, null); - Assert.GreaterOrEqual(_driver.FindElements(byAccessibilityId).Count, 1); + Assert.Multiple(() => + { + Assert.That(Is.Not.EqualTo(_driver.FindElement(byAccessibilityId).Text), null); + Assert.That(_driver.FindElements(byAccessibilityId), Is.Not.Empty); + }); } [Test] public void FindByByIosUiAutomationTest() { By byIosUiAutomation = new ByIosUIAutomation(".elements().withName(\"Answer\")"); - Assert.IsNotNull(_driver.FindElement(byIosUiAutomation).Text); - Assert.GreaterOrEqual(_driver.FindElements(byIosUiAutomation).Count, 1); + Assert.Multiple(() => + { + Assert.That(_driver.FindElement(byIosUiAutomation).Text, Is.Not.Null); + Assert.That(_driver.FindElements(byIosUiAutomation), Is.Not.Empty); + }); } } } \ No newline at end of file diff --git a/test/integration/IOS/Session/LogTests.cs b/test/integration/IOS/Session/LogTests.cs index 664a0cf3..c31080d5 100644 --- a/test/integration/IOS/Session/LogTests.cs +++ b/test/integration/IOS/Session/LogTests.cs @@ -39,7 +39,7 @@ public void CanRetrieveLogTypesTest() Assert.Multiple(() => { Assert.That(logs.AvailableLogTypes, Is.Not.Null); - Assert.That(availableLogTypes.Count, Is.GreaterThan(0), nameof(availableLogTypes)); + Assert.That(availableLogTypes, Is.Not.Empty, nameof(availableLogTypes)); }); Console.WriteLine(@"Available log types:"); foreach (var logType in availableLogTypes) @@ -53,7 +53,7 @@ public void CanCaptureSyslogTest() { var availableLogTypes = _driver.Manage().Logs.AvailableLogTypes; Assert.That(availableLogTypes, Is.Not.Null); - CollectionAssert.Contains(availableLogTypes, SyslogLogType); + Assert.That(availableLogTypes, Has.Member(SyslogLogType)); Assert.DoesNotThrow(() => _driver.Manage().Logs.GetLog(SyslogLogType)); } @@ -63,7 +63,7 @@ public void CanCaptureCrashlogTest() { var availableLogTypes = _driver.Manage().Logs.AvailableLogTypes; Assert.That(availableLogTypes, Is.Not.Null); - CollectionAssert.Contains(availableLogTypes, CrashLogType); + Assert.That(availableLogTypes, Has.Member(CrashLogType)); Assert.DoesNotThrow(() => _driver.Manage().Logs.GetLog(CrashLogType)); } @@ -73,7 +73,7 @@ public void CanCaptureServerTest() { var availableLogTypes = _driver.Manage().Logs.AvailableLogTypes; Assert.That(availableLogTypes, Is.Not.Null); - CollectionAssert.Contains(availableLogTypes, ServerLogType); + Assert.That(availableLogTypes, Has.Member(ServerLogType)); var appiumServerLog = _driver.Manage().Logs.GetLog(LogType.Server); Assert.That(appiumServerLog, Is.Not.Null.And.Count.GreaterThan(1)); diff --git a/test/integration/IOS/SettingTest.cs b/test/integration/IOS/SettingTest.cs index 5a68835b..b3b4da0d 100644 --- a/test/integration/IOS/SettingTest.cs +++ b/test/integration/IOS/SettingTest.cs @@ -35,13 +35,13 @@ public void SettingsUpdateTest() setting: "useJSONSource", value: true); - Assert.IsTrue((bool)_driver.Settings["useJSONSource"]); + Assert.That((bool)_driver.Settings["useJSONSource"]); _driver.SetSetting( setting: "useJSONSource", value: false); - Assert.IsFalse((bool)_driver.Settings["useJSONSource"]); + Assert.That((bool)_driver.Settings["useJSONSource"], Is.False); } } } \ No newline at end of file diff --git a/test/integration/IOS/TouchActionTest.cs b/test/integration/IOS/TouchActionTest.cs index 18977456..e4f0c6e1 100644 --- a/test/integration/IOS/TouchActionTest.cs +++ b/test/integration/IOS/TouchActionTest.cs @@ -54,7 +54,7 @@ public void SimpleActionTestCase() action.Press(el, 10, 10).Release(); action.Perform(); const string str = "4"; - Assert.AreEqual(_driver.FindElement(MobileBy.XPath("//*[@name = \"Answer\"]")).Text, str); + Assert.That(_driver.FindElement(MobileBy.XPath("//*[@name = \"Answer\"]")).Text, Is.EqualTo(str)); } [Test] @@ -73,7 +73,7 @@ public void MultiActionTestCase() m.Add(a1).Add(a2); m.Perform(); const string str = "6"; - Assert.AreEqual(_driver.FindElement(MobileBy.XPath("//*[@name = \"Answer\"]")).Text, str); + Assert.That(_driver.FindElement(MobileBy.XPath("//*[@name = \"Answer\"]")).Text, Is.EqualTo(str)); } } } \ No newline at end of file diff --git a/test/integration/IOS/WebviewTest.cs b/test/integration/IOS/WebviewTest.cs index 2cee393e..3b0672d9 100644 --- a/test/integration/IOS/WebviewTest.cs +++ b/test/integration/IOS/WebviewTest.cs @@ -52,7 +52,7 @@ public void GetPageTestCase() el.SendKeys("Appium"); el.SendKeys(Keys.Return); Thread.Sleep(1000); - Assert.IsTrue(_driver.Title.Contains("Appium")); + Assert.That(_driver.Title.Contains("Appium")); } } } \ No newline at end of file diff --git a/test/integration/ServerTests/AppiumClientConfigTest.cs b/test/integration/ServerTests/AppiumClientConfigTest.cs index cdadf36f..9bbf18b2 100644 --- a/test/integration/ServerTests/AppiumClientConfigTest.cs +++ b/test/integration/ServerTests/AppiumClientConfigTest.cs @@ -25,10 +25,10 @@ public class AppiumClientConfigTest public void SetAndGetDirectConnect() { var clientConfig = AppiumClientConfig.DefaultConfig(); - Assert.IsFalse(clientConfig.DirectConnect); + Assert.That(clientConfig.DirectConnect, Is.False); clientConfig.DirectConnect = true; - Assert.IsTrue(clientConfig.DirectConnect); + Assert.That(clientConfig.DirectConnect); } } } diff --git a/test/integration/ServerTests/AppiumLocalServerLaunchingTest.cs b/test/integration/ServerTests/AppiumLocalServerLaunchingTest.cs index 91d0aa38..55a60878 100644 --- a/test/integration/ServerTests/AppiumLocalServerLaunchingTest.cs +++ b/test/integration/ServerTests/AppiumLocalServerLaunchingTest.cs @@ -48,7 +48,7 @@ public void CheckAbilityToBuildDefaultService() try { service.Start(); - Assert.AreEqual(true, service.IsRunning); + Assert.That(service.IsRunning, Is.EqualTo(true)); } finally { @@ -62,19 +62,27 @@ public void CheckAbilityToLogServiceOutputToConsole() var service = AppiumLocalService.BuildDefaultService(); var lines = new List(); - service.OutputDataReceived += (sender, e) => { lines.Add(e.Data); Console.Out.WriteLine(e.Data); }; + ManualResetEvent dataReceivedEvent = new ManualResetEvent(false); + + service.OutputDataReceived += (sender, e) => + { + lines.Add(e.Data); + Console.Out.WriteLine(e.Data); + dataReceivedEvent.Set(); + }; try { service.Start(); - Assert.AreEqual(true, service.IsRunning); + Assert.That(service.IsRunning, Is.EqualTo(true)); + dataReceivedEvent.WaitOne(TimeSpan.FromSeconds(10)); } finally { service.Dispose(); } - Assert.IsNotEmpty(lines); + Assert.That(lines, Is.Not.Empty); } [Test] @@ -87,7 +95,7 @@ public void CheckAbilityToBuildServiceUsingNodeDefinedInProperties() Environment.SetEnvironmentVariable(AppiumServiceConstants.AppiumBinaryPath, definedNode); service = AppiumLocalService.BuildDefaultService(); service.Start(); - Assert.AreEqual(true, service.IsRunning); + Assert.That(service.IsRunning, Is.EqualTo(true)); } finally { @@ -104,7 +112,7 @@ public void CheckAbilityToBuildServiceUsingNodeDefinedExplicitly() { service = new AppiumServiceBuilder().WithAppiumJS(new FileInfo(_pathToAppiumPackageIndex)).Build(); service.Start(); - Assert.AreEqual(true, service.IsRunning); + Assert.That(service.IsRunning, Is.EqualTo(true)); } finally { @@ -120,7 +128,7 @@ public void CheckAbilityToStartServiceOnAFreePort() { service = new AppiumServiceBuilder().UsingAnyFreePort().Build(); service.Start(); - Assert.AreEqual(true, service.IsRunning); + Assert.That(service.IsRunning, Is.EqualTo(true)); } finally { @@ -135,7 +143,7 @@ public void CheckStartingOfAServiceWithNonLocalhostIp() try { service.Start(); - Assert.IsTrue(service.IsRunning); + Assert.That(service.IsRunning); } finally { @@ -153,7 +161,7 @@ public void CheckAbilityToStartServiceUsingFlags() { service = new AppiumServiceBuilder().WithArguments(args).Build(); service.Start(); - Assert.IsTrue(service.IsRunning); + Assert.That(service.IsRunning); } finally { @@ -170,7 +178,7 @@ public void CheckAbilityToStartServiceUsingBasePathFlag() { service = new AppiumServiceBuilder().WithArguments(args).Build(); service.Start(); - Assert.IsTrue(service.IsRunning); + Assert.That(service.IsRunning); } finally { @@ -195,7 +203,7 @@ public void CheckAbilityToStartServiceUsingCapabilities() { service = new AppiumServiceBuilder().WithArguments(args).Build(); service.Start(); - Assert.IsTrue(service.IsRunning); + Assert.That(service.IsRunning); } finally { @@ -221,7 +229,7 @@ public void CheckAbilityToStartServiceUsingCapabilitiesAndFlags() { service = new AppiumServiceBuilder().WithArguments(args).Build(); service.Start(); - Assert.IsTrue(service.IsRunning); + Assert.That(service.IsRunning); } finally { @@ -235,7 +243,7 @@ public void CheckAbilityToShutDownService() var service = AppiumLocalService.BuildDefaultService(); service.Start(); service.Dispose(); - Assert.IsTrue(!service.IsRunning); + Assert.That(!service.IsRunning); } [Test] @@ -256,10 +264,13 @@ public void CheckAbilityToStartAndShutDownFewServices() service3.Dispose(); Thread.Sleep(1000); service4.Dispose(); - Assert.IsTrue(!service1.IsRunning); - Assert.IsTrue(!service2.IsRunning); - Assert.IsTrue(!service3.IsRunning); - Assert.IsTrue(!service4.IsRunning); + Assert.Multiple(() => + { + Assert.That(!service1.IsRunning); + Assert.That(!service2.IsRunning); + Assert.That(!service3.IsRunning); + Assert.That(!service4.IsRunning); + }); } @@ -271,8 +282,11 @@ public void CheckTheAbilityToDefineTheDesiredLogFile() try { service.Start(); - Assert.IsTrue(log.Exists); - Assert.IsTrue(log.Length > 0); //There should be Appium greeting messages + Assert.Multiple(() => + { + Assert.That(log.Exists, Is.True); + Assert.That(log.Length, Is.GreaterThan(0)); //There should be Appium greeting messages + }); } finally { diff --git a/test/integration/ServerTests/DirectConnectTest.cs b/test/integration/ServerTests/DirectConnectTest.cs index 46ecbf87..81a45394 100644 --- a/test/integration/ServerTests/DirectConnectTest.cs +++ b/test/integration/ServerTests/DirectConnectTest.cs @@ -33,7 +33,7 @@ public void WithAnEmptyBody() response.Value = emptyBody; DirectConnect directConnect = new DirectConnect(response); - Assert.IsNull(directConnect.GetUri()); + Assert.That(directConnect.GetUri(), Is.Null); } @@ -51,7 +51,7 @@ public void WithAppiumPrefixResponsesWithAppium() response.Value = body; DirectConnect directConnect = new DirectConnect(response); - Assert.AreEqual(directConnect.GetUri(), "https://example.com:9090/path/to/new/direction"); + Assert.That(directConnect.GetUri().ToString(), Is.EqualTo("https://example.com:9090/path/to/new/direction")); } [Test] @@ -68,7 +68,7 @@ public void WithAppiumPrefixResponsesWithoutAppium() response.Value = body; DirectConnect directConnect = new DirectConnect(response); - Assert.AreEqual(directConnect.GetUri(), "https://example.com:9090/path/to/new/direction"); + Assert.That(directConnect.GetUri().ToString(), Is.EqualTo("https://example.com:9090/path/to/new/direction")); } [Test] @@ -85,7 +85,7 @@ public void WithAppiumPrefixResponsesInvalidProtocol() response.Value = body; DirectConnect directConnect = new DirectConnect(response); - Assert.IsNull(directConnect.GetUri()); + Assert.That(directConnect.GetUri(), Is.Null); } } } diff --git a/test/integration/ServerTests/StartingAppLocallyTest.cs b/test/integration/ServerTests/StartingAppLocallyTest.cs index 53139f66..9a94e667 100644 --- a/test/integration/ServerTests/StartingAppLocallyTest.cs +++ b/test/integration/ServerTests/StartingAppLocallyTest.cs @@ -151,7 +151,7 @@ public void CheckThatServiceIsNotRunWhenTheCreatingOfANewSessionIsFailed() } catch (Exception e) { - Assert.IsTrue(!service.IsRunning); + Assert.That(!service.IsRunning); return; } throw new Exception("Any exception was expected"); diff --git a/test/integration/Windows/ClickElementTest.cs b/test/integration/Windows/ClickElementTest.cs index 67e47c61..9f32894b 100644 --- a/test/integration/Windows/ClickElementTest.cs +++ b/test/integration/Windows/ClickElementTest.cs @@ -42,7 +42,7 @@ public void BeforeAll() _calculatorSession.FindElement(MobileBy.Name("Clear")).Click(); _calculatorSession.FindElement(MobileBy.Name("Seven")).Click(); CalculatorResult = _calculatorSession.FindElement(MobileBy.Name("Display is 7")); - Assert.IsNotNull(CalculatorResult); + Assert.That(CalculatorResult, Is.Not.Null); } [OneTimeTearDown] @@ -58,7 +58,7 @@ public void OneTimeTearDown() public void SetUp() { _calculatorSession.FindElement(MobileBy.Name("Clear")).Click(); - Assert.AreEqual("Display is 0", CalculatorResult.Text); + Assert.That(CalculatorResult.Text, Is.EqualTo("Display is 0")); } [Test] @@ -68,7 +68,7 @@ public void Addition() _calculatorSession.FindElement(MobileBy.Name("Plus")).Click(); _calculatorSession.FindElement(MobileBy.Name("Seven")).Click(); _calculatorSession.FindElement(MobileBy.Name("Equals")).Click(); - Assert.AreEqual("Display is 8", CalculatorResult.Text); + Assert.That(CalculatorResult.Text, Is.EqualTo("Display is 8")); } [Test] @@ -78,7 +78,7 @@ public void AdditionWithCompoundBys() _calculatorSession.FindElement(MobileBy.AccessibilityId("plusButton")).Click(); _calculatorSession.FindElement(MobileBy.Name("Calculator")).FindElement(MobileBy.Name("Five")).Click(); _calculatorSession.FindElement(MobileBy.Name("Equals")).Click(); - Assert.AreEqual("Display is 6", CalculatorResult.Text); + Assert.That(CalculatorResult.Text, Is.EqualTo("Display is 6")); } [Test] @@ -93,7 +93,7 @@ public void Combination() _calculatorSession.FindElement(MobileBy.Name("Divide by")).Click(); _calculatorSession.FindElement(MobileBy.Name("Eight")).Click(); _calculatorSession.FindElement(MobileBy.Name("Equals")).Click(); - Assert.AreEqual("Display is 8", CalculatorResult.Text); + Assert.That(CalculatorResult.Text, Is.EqualTo("Display is 8")); } [Test] @@ -105,7 +105,7 @@ public void Division() _calculatorSession.FindElement(MobileBy.Name("One")).Click(); _calculatorSession.FindElement(MobileBy.Name("One")).Click(); _calculatorSession.FindElement(MobileBy.Name("Equals")).Click(); - Assert.AreEqual("Display is 8", CalculatorResult.Text); + Assert.That(CalculatorResult.Text, Is.EqualTo("Display is 8")); } [Test] @@ -115,7 +115,7 @@ public void Multiplication() _calculatorSession.FindElement(MobileBy.Name("Multiply by")).Click(); _calculatorSession.FindElement(MobileBy.Name("Nine")).Click(); _calculatorSession.FindElement(MobileBy.Name("Equals")).Click(); - Assert.AreEqual("Display is 81", CalculatorResult.Text); + Assert.That(CalculatorResult.Text, Is.EqualTo("Display is 81")); } [Test] @@ -125,7 +125,7 @@ public void Subtraction() _calculatorSession.FindElement(MobileBy.Name("Minus")).Click(); _calculatorSession.FindElement(MobileBy.Name("One")).Click(); _calculatorSession.FindElement(MobileBy.Name("Equals")).Click(); - Assert.AreEqual("Display is 8", CalculatorResult.Text); + Assert.That(CalculatorResult.Text, Is.EqualTo("Display is 8")); } } } \ No newline at end of file diff --git a/test/integration/Windows/ImagesComparisonTest.cs b/test/integration/Windows/ImagesComparisonTest.cs index d4503698..ac087fda 100644 --- a/test/integration/Windows/ImagesComparisonTest.cs +++ b/test/integration/Windows/ImagesComparisonTest.cs @@ -44,8 +44,11 @@ public void SimilarityCalculation() var similarityResult = _calculatorSession.GetImagesSimilarity(screenshot.AsBase64EncodedString, screenshot.AsBase64EncodedString, options); - Assert.Greater(similarityResult.Score, 0); - Assert.IsNotNull(similarityResult.Visualization); + Assert.Multiple(() => + { + Assert.That(similarityResult.Score, Is.GreaterThan(0)); + Assert.That(similarityResult.Visualization, Is.Not.Null); + }); } [Test] @@ -56,8 +59,11 @@ public void OccurencesLookup() var occurencesResult = _calculatorSession.FindImageOccurence(screenshot.AsBase64EncodedString, screenshot.AsBase64EncodedString, options); - Assert.IsNotNull(occurencesResult.Rect); - Assert.IsNotNull(occurencesResult.Visualization); + Assert.Multiple(() => + { + Assert.That(occurencesResult.Rect, Is.Not.Empty); + Assert.That(occurencesResult.Visualization, Is.Not.Null); + }); } [Test] @@ -73,12 +79,18 @@ public void FeaturesMatching() var occurencesResult = _calculatorSession.MatchImageFeatures(screenshot.AsBase64EncodedString, screenshot.AsBase64EncodedString, options); - Assert.IsNotNull(occurencesResult.Visualization); - Assert.Greater(occurencesResult.TotalCount, 0); - Assert.Greater(occurencesResult.Points1.Count, 0); - Assert.Greater(occurencesResult.Points2.Count, 0); - Assert.IsNotNull(occurencesResult.Rect1); - Assert.IsNotNull(occurencesResult.Rect2); + Assert.Multiple(() => + { + Assert.That(occurencesResult.Visualization, Is.Not.Null); + Assert.That(occurencesResult.TotalCount, Is.GreaterThan(0)); + Assert.That(occurencesResult.Points1, Is.Not.Empty); + Assert.That(occurencesResult.Points2, Is.Not.Empty); + }); + Assert.Multiple(() => + { + Assert.That(occurencesResult.Rect1.Width, Is.Not.Empty); + Assert.That(occurencesResult.Rect2.Height, Is.Not.Empty); + }); } } } diff --git a/test/integration/Windows/MultiSelectControlTest.cs b/test/integration/Windows/MultiSelectControlTest.cs index 9a5faf06..98b78855 100644 --- a/test/integration/Windows/MultiSelectControlTest.cs +++ b/test/integration/Windows/MultiSelectControlTest.cs @@ -33,10 +33,13 @@ public class MultiSelectControlTest public void Setup() { // Launch the AlarmClock app - var appCapabilities = new AppiumOptions(); - appCapabilities.App = "Microsoft.WindowsAlarms_8wekyb3d8bbwe!App"; - appCapabilities.PlatformName ="Windows"; - appCapabilities.DeviceName = "WindowsPC"; + var appCapabilities = new AppiumOptions + { + App = "Microsoft.WindowsAlarms_8wekyb3d8bbwe!App", + PlatformName = "Windows", + DeviceName = "WindowsPC", + AutomationName = "Windows" + }; appCapabilities.AddAdditionalAppiumOption("ms:experimental-webdriver", true); var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri; @@ -44,17 +47,20 @@ public void Setup() AlarmClockSession = new WindowsDriver(serverUri, appCapabilities); - Assert.IsNotNull(AlarmClockSession); + Assert.That(AlarmClockSession, Is.Not.Null); AlarmClockSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2); // Create a session for Desktop - var desktopCapabilities = new AppiumOptions(); - desktopCapabilities.App = "Root"; - desktopCapabilities.DeviceName = "WindowsPC"; + var desktopCapabilities = new AppiumOptions + { + App = "Root", + DeviceName = "WindowsPC", + AutomationName = "Windows" + }; DesktopSession = new WindowsDriver(serverUri, desktopCapabilities); - Assert.IsNotNull(DesktopSession); + Assert.That(DesktopSession, Is.Not.Null); } @@ -77,6 +83,8 @@ public void OneTimeTearDown() AlarmClockSession.Dispose(); AlarmClockSession = null; + DesktopSession.Dispose(); + DesktopSession = null; } [Test] @@ -85,14 +93,14 @@ public void FullMultiSelectScenario() // Read the current local time SwitchToWorldClockTab(); var localTimeText = ReadLocalTime(); - Assert.IsTrue(localTimeText.Length > 0); + Assert.That(localTimeText.Length > 0); // Add an alarm at 1 minute after local time SwitchToAlarmTab(); AddAlarm(localTimeText); Thread.Sleep(300); var alarmEntries = AlarmClockSession.FindElements(MobileBy.Name("Windows Application Driver Test Alarm")); - Assert.IsTrue(alarmEntries.Count > 0); + Assert.That(alarmEntries.Count > 0); } public static void SwitchToAlarmTab() @@ -168,7 +176,7 @@ public void DismissNotification() try { AppiumElement newNotification = DesktopSession.FindElement(MobileBy.Name("New notification")); - Assert.IsTrue(newNotification.FindElement(MobileBy.AccessibilityId("MessageText")).Text + Assert.That(newNotification.FindElement(MobileBy.AccessibilityId("MessageText")).Text .Contains("Windows Application Driver Test Alarm")); newNotification.FindElement(MobileBy.Name("Dismiss")).Click(); } diff --git a/test/integration/Windows/PentTest.cs b/test/integration/Windows/PentTest.cs index 45de2f20..d64af768 100644 --- a/test/integration/Windows/PentTest.cs +++ b/test/integration/Windows/PentTest.cs @@ -213,16 +213,16 @@ public void CreateNewStickyNote() // Preserve existing or previously opened Sticky Notes by keeping track of them on initialize var openedStickyNotesWindowsBefore = session.FindElements(MobileBy.ClassName("ApplicationFrameWindow")); - Assert.IsNotNull(openedStickyNotesWindowsBefore); - Assert.IsTrue(openedStickyNotesWindowsBefore.Count > 0); + Assert.That(openedStickyNotesWindowsBefore, Is.Not.Null); + Assert.That(openedStickyNotesWindowsBefore.Count > 0, Is.True); // Create a new Sticky Note by pressing Ctrl + N openedStickyNotesWindowsBefore[0].SendKeys(Keys.Control + "n" + Keys.Control); Thread.Sleep(TimeSpan.FromSeconds(2)); var openedStickyNotesWindowsAfter = session.FindElements(MobileBy.ClassName("ApplicationFrameWindow")); - Assert.IsNotNull(openedStickyNotesWindowsAfter); - Assert.AreEqual(openedStickyNotesWindowsBefore.Count + 1, openedStickyNotesWindowsAfter.Count); + Assert.That(openedStickyNotesWindowsAfter, Is.Not.Null); + Assert.That(openedStickyNotesWindowsAfter.Count, Is.EqualTo(openedStickyNotesWindowsBefore.Count + 1)); // Identify the newly opened Sticky Note by removing the previously opened ones from the list List openedStickyNotes = new List(openedStickyNotesWindowsAfter); @@ -230,7 +230,7 @@ public void CreateNewStickyNote() { openedStickyNotes.Remove(preExistingStickyNote); } - Assert.AreEqual(1, openedStickyNotes.Count); + Assert.That(openedStickyNotes.Count, Is.EqualTo(1)); // Create a new session based from the newly opened Sticky Notes window var newStickyNoteWindowHandle = openedStickyNotes[0].GetAttribute("NativeWindowHandle"); @@ -239,7 +239,7 @@ public void CreateNewStickyNote() appCapabilities.AddAdditionalAppiumOption("appTopLevelWindow", newStickyNoteWindowHandle); appCapabilities.DeviceName = "WindowsPC"; newStickyNoteSession = new WindowsDriver(serverUri, appCapabilities); - Assert.IsNotNull(newStickyNoteSession); + Assert.That(newStickyNoteSession, Is.Not.Null); // Resize and re-position the Sticky Notes window we are working with newStickyNoteSession.Manage().Window.Size = new Size(stickyNoteWidth, stickyNoteHeight); @@ -248,9 +248,9 @@ public void CreateNewStickyNote() // Verify that this Sticky Notes is indeed new. Newly created Sticky Notes has both // RichEditBox and InkCanvas in the UI tree. Once modified by a pen or key input, // it will only contain one or the other. - Assert.IsNotNull(newStickyNoteSession.FindElement(MobileBy.AccessibilityId("RichEditBox"))); + Assert.That(newStickyNoteSession.FindElement(MobileBy.AccessibilityId("RichEditBox")), Is.Not.Null); inkCanvas = newStickyNoteSession.FindElement(MobileBy.AccessibilityId("InkCanvas")); - Assert.IsNotNull(inkCanvas); + Assert.That(inkCanvas, Is.Not.Null); } [TearDown] @@ -272,6 +272,7 @@ public void DeleteStickyNote() } inkCanvas = null; + newStickyNoteSession?.Quit(); } } } diff --git a/test/integration/Windows/StickyNotesTest.cs b/test/integration/Windows/StickyNotesTest.cs index c761705d..d6b1c634 100644 --- a/test/integration/Windows/StickyNotesTest.cs +++ b/test/integration/Windows/StickyNotesTest.cs @@ -66,7 +66,7 @@ public void BeforeAll() appCapabilities.DeviceName = "WindowsPC"; session = new WindowsDriver(serverUri, appCapabilities); } - Assert.IsNotNull(session); + Assert.That(session, Is.Not.Null); // Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);