diff --git a/dotnet/test/common/AlertsTest.cs b/dotnet/test/common/AlertsTest.cs index 84a05f4a6a78c..8d093a783acf9 100644 --- a/dotnet/test/common/AlertsTest.cs +++ b/dotnet/test/common/AlertsTest.cs @@ -48,7 +48,7 @@ public void ShouldAllowUsersToAcceptAnAlertManually() alert.Accept(); // If we can perform any action, we're good to go - Assert.AreEqual("Testing Alerts", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Testing Alerts")); } [Test] @@ -81,7 +81,7 @@ public void ShouldAllowUsersToAcceptAnAlertWithNoTextManually() alert.Accept(); // If we can perform any action, we're good to go - Assert.AreEqual("Testing Alerts", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Testing Alerts")); } [Test] @@ -95,7 +95,7 @@ public void ShouldAllowUsersToDismissAnAlertManually() alert.Dismiss(); // If we can perform any action, we're good to go - Assert.AreEqual("Testing Alerts", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Testing Alerts")); } [Test] @@ -109,7 +109,7 @@ public void ShouldAllowAUserToAcceptAPrompt() alert.Accept(); // If we can perform any action, we're good to go - Assert.AreEqual("Testing Prompt", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Testing Prompt")); } [Test] @@ -123,7 +123,7 @@ public void ShouldAllowAUserToDismissAPrompt() alert.Dismiss(); // If we can perform any action, we're good to go - Assert.AreEqual("Testing Prompt", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Testing Prompt")); } [Test] @@ -138,7 +138,7 @@ public void ShouldAllowAUserToSetTheValueOfAPrompt() alert.Accept(); string result = driver.FindElement(By.Id("text")).Text; - Assert.AreEqual("cheese", result); + Assert.That(result, Is.EqualTo("cheese")); } [Test] @@ -173,7 +173,7 @@ public void ShouldAllowTheUserToGetTheTextOfAnAlert() string value = alert.Text; alert.Accept(); - Assert.AreEqual("cheese", value); + Assert.That(value, Is.EqualTo("cheese")); } [Test] @@ -187,7 +187,7 @@ public void ShouldAllowTheUserToGetTheTextOfAPrompt() string value = alert.Text; alert.Accept(); - Assert.AreEqual("Enter something", value); + Assert.That(value, Is.EqualTo("Enter something")); } [Test] @@ -222,7 +222,7 @@ public void ShouldAllowUsersToAcceptAnAlertInAFrame() alert.Accept(); // If we can perform any action, we're good to go - Assert.AreEqual("Testing Alerts", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Testing Alerts")); } [Test] @@ -244,7 +244,7 @@ public void ShouldAllowUsersToAcceptAnAlertInANestedFrame() alert.Accept(); // If we can perform any action, we're good to go - Assert.AreEqual("Testing Alerts", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Testing Alerts")); } [Test] @@ -298,7 +298,7 @@ public void PromptShouldUseDefaultValueIfNoKeysSent() IWebElement element = driver.FindElement(By.Id("text")); WaitFor(ElementTextToEqual(element, "This is a default value"), "Element text was not 'This is a default value'"); - Assert.AreEqual("This is a default value", element.Text); + Assert.That(element.Text, Is.EqualTo("This is a default value")); } [Test] @@ -311,7 +311,7 @@ public void PromptShouldHaveNullValueIfDismissed() alert.Dismiss(); IWebElement element = driver.FindElement(By.Id("text")); WaitFor(ElementTextToEqual(element, "null"), "Element text was not 'null'"); - Assert.AreEqual("null", element.Text); + Assert.That(element.Text, Is.EqualTo("null")); } [Test] @@ -349,10 +349,10 @@ function displayTwoPrompts() { IWebElement element1 = driver.FindElement(By.Id("text1")); WaitFor(ElementTextToEqual(element1, "brie"), "Element text was not 'brie'"); - Assert.AreEqual("brie", element1.Text); + Assert.That(element1.Text, Is.EqualTo("brie")); IWebElement element2 = driver.FindElement(By.Id("text2")); WaitFor(ElementTextToEqual(element2, "cheddar"), "Element text was not 'cheddar'"); - Assert.AreEqual("cheddar", element2.Text); + Assert.That(element2.Text, Is.EqualTo("cheddar")); } [Test] @@ -370,7 +370,7 @@ public void ShouldHandleAlertOnPageLoad() string value = alert.Text; alert.Accept(); - Assert.AreEqual("onload", value); + Assert.That(value, Is.EqualTo("onload")); IWebElement element = driver.FindElement(By.TagName("p")); WaitFor(ElementTextToEqual(element, "Page with onload event handler"), "Element text was not 'Page with onload event handler'"); } @@ -387,7 +387,7 @@ public void ShouldHandleAlertOnPageLoadUsingGet() string value = alert.Text; alert.Accept(); - Assert.AreEqual("onload", value); + Assert.That(value, Is.EqualTo("onload")); WaitFor(ElementTextToEqual(driver.FindElement(By.TagName("p")), "Page with onload event handler"), "Could not find element with text 'Page with onload event handler'"); } @@ -412,7 +412,7 @@ public void ShouldNotHandleAlertInAnotherWindow() driver.FindElement(By.Id("open-new-window")).Click(); List allWindows = new List(driver.WindowHandles); allWindows.Remove(mainWindow); - Assert.AreEqual(1, allWindows.Count); + Assert.That(allWindows, Has.One.Items); onloadWindow = allWindows[0]; Assert.That(() => @@ -472,8 +472,8 @@ public void ShouldHandleAlertOnFormSubmit() string text = alert.Text; alert.Accept(); - Assert.AreEqual("Tasty cheese", text); - Assert.AreEqual("Testing Alerts", driver.Title); + Assert.That(text, Is.EqualTo("Tasty cheese")); + Assert.That(driver.Title, Is.EqualTo("Testing Alerts")); } private IAlert AlertToBePresent() diff --git a/dotnet/test/common/ChildrenFindingTest.cs b/dotnet/test/common/ChildrenFindingTest.cs index 1bbe8ccfe1e6e..6588c7c88a43a 100644 --- a/dotnet/test/common/ChildrenFindingTest.cs +++ b/dotnet/test/common/ChildrenFindingTest.cs @@ -31,7 +31,7 @@ public void FindElementByXPath() driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Name("form2")); IWebElement child = element.FindElement(By.XPath("select")); - Assert.AreEqual("2", child.GetAttribute("id")); + Assert.That(child.GetAttribute("id"), Is.EqualTo("2")); } [Test] @@ -41,7 +41,7 @@ public void FindingElementsOnElementByXPathShouldFindTopLevelElements() IWebElement parent = driver.FindElement(By.Id("multiline")); ReadOnlyCollection allParaElements = driver.FindElements(By.XPath("//p")); ReadOnlyCollection children = parent.FindElements(By.XPath("//p")); - Assert.AreEqual(allParaElements.Count, children.Count); + Assert.That(children, Has.Exactly(allParaElements.Count).Items); } [Test] @@ -49,9 +49,10 @@ public void FindingDotSlashElementsOnElementByXPathShouldFindNotTopLevelElements { driver.Url = simpleTestPage; IWebElement parent = driver.FindElement(By.Id("multiline")); + ReadOnlyCollection children = parent.FindElements(By.XPath("./p")); - Assert.AreEqual(1, children.Count); - Assert.AreEqual("A div containing", children[0].Text); + Assert.That(children, Has.One.Items); + Assert.That(children[0].Text, Is.EqualTo("A div containing")); } [Test] @@ -59,7 +60,10 @@ public void FindElementByXPathWhenNoMatch() { driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Name("form2")); - Assert.That(() => element.FindElement(By.XPath("select/x")), Throws.InstanceOf()); + + Assert.That( + () => element.FindElement(By.XPath("select/x")), + Throws.InstanceOf()); } [Test] @@ -67,10 +71,11 @@ public void FindElementsByXPath() { driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Name("form2")); + ReadOnlyCollection children = element.FindElements(By.XPath("select/option")); - Assert.AreEqual(8, children.Count); - Assert.AreEqual("One", children[0].Text); - Assert.AreEqual("Two", children[1].Text); + Assert.That(children, Has.Exactly(8).Items); + Assert.That(children[0].Text, Is.EqualTo("One")); + Assert.That(children[1].Text, Is.EqualTo("Two")); } [Test] @@ -79,7 +84,7 @@ public void FindElementsByXPathWhenNoMatch() driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Name("form2")); ReadOnlyCollection children = element.FindElements(By.XPath("select/x")); - Assert.AreEqual(0, children.Count); + Assert.That(children, Is.Empty); } [Test] @@ -88,7 +93,7 @@ public void FindElementByName() driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Name("form2")); IWebElement child = element.FindElement(By.Name("selectomatic")); - Assert.AreEqual("2", child.GetAttribute("id")); + Assert.That(child.GetAttribute("id"), Is.EqualTo("2")); } [Test] @@ -96,8 +101,9 @@ public void FindElementsByName() { driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Name("form2")); + ReadOnlyCollection children = element.FindElements(By.Name("selectomatic")); - Assert.AreEqual(children.Count, 2); + Assert.That(children, Has.Exactly(2).Items); } [Test] @@ -105,8 +111,9 @@ public void FindElementById() { driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Name("form2")); + IWebElement child = element.FindElement(By.Id("2")); - Assert.AreEqual(child.GetAttribute("name"), "selectomatic"); + Assert.That(child.GetAttribute("name"), Is.EqualTo("selectomatic")); } @@ -115,8 +122,9 @@ public void FindElementByIdWhenMultipleMatchesExist() { driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Id("test_id_div")); + IWebElement child = element.FindElement(By.Id("test_id")); - Assert.AreEqual(child.Text, "inside"); + Assert.That(child.Text, Is.EqualTo("inside")); } [Test] @@ -124,8 +132,9 @@ public void FindElementByIdWhenIdContainsNonAlphanumericCharacters() { driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Id("test_special_chars")); + IWebElement childWithSpaces = element.FindElement(By.Id("white space")); - Assert.That(childWithSpaces.Text.Contains("space")); + Assert.That(childWithSpaces.Text, Does.Contain("space")); IWebElement childWithCssChars = element.FindElement(By.Id("css#.chars")); Assert.That(childWithCssChars.Text, Is.EqualTo("css escapes")); } @@ -135,7 +144,10 @@ public void FindElementByIdWhenNoMatchInContext() { driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Id("test_id_div")); - Assert.That(() => element.FindElement(By.Id("test_id_out")), Throws.InstanceOf()); + + Assert.That( + () => element.FindElement(By.Id("test_id_out")), + Throws.InstanceOf()); } [Test] @@ -144,7 +156,7 @@ public void FindElementsById() driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Name("form2")); ReadOnlyCollection children = element.FindElements(By.Id("2")); - Assert.AreEqual(children.Count, 2); + Assert.That(children, Has.Exactly(2).Items); } [Test] @@ -153,9 +165,9 @@ public void FindElementsByIdWithNonAlphanumericCharacters() driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Id("test_special_chars")); ReadOnlyCollection children = element.FindElements(By.Id("white space")); - Assert.That(children.Count, Is.EqualTo(1)); + Assert.That(children, Has.One.Items); ReadOnlyCollection children2 = element.FindElements(By.Id("css#.chars")); - Assert.That(children2.Count, Is.EqualTo(1)); + Assert.That(children2, Has.One.Items); } [Test] @@ -163,8 +175,9 @@ public void FindElementByLinkText() { driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Name("div1")); + IWebElement child = element.FindElement(By.LinkText("hello world")); - Assert.AreEqual(child.GetAttribute("name"), "link1"); + Assert.That(child.GetAttribute("name"), Is.EqualTo("link1")); } @@ -175,9 +188,9 @@ public void FindElementsByLinkText() IWebElement element = driver.FindElement(By.Name("div1")); ReadOnlyCollection elements = element.FindElements(By.LinkText("hello world")); - Assert.AreEqual(2, elements.Count); - Assert.AreEqual(elements[0].GetAttribute("name"), "link1"); - Assert.AreEqual(elements[1].GetAttribute("name"), "link2"); + Assert.That(elements, Has.Exactly(2).Items); + Assert.That(elements[0].GetAttribute("name"), Is.EqualTo("link1")); + Assert.That(elements[1].GetAttribute("name"), Is.EqualTo("link2")); } [Test] @@ -185,8 +198,9 @@ public void ShouldFindChildElementsById() { driver.Url = nestedPage; IWebElement parent = driver.FindElement(By.Id("test_id_div")); + IWebElement element = parent.FindElement(By.Id("test_id")); - Assert.AreEqual("inside", element.Text); + Assert.That(element.Text, Is.EqualTo("inside")); } [Test] @@ -195,8 +209,10 @@ public void ShouldNotReturnRootElementWhenFindingChildrenById() driver.Url = nestedPage; IWebElement parent = driver.FindElement(By.Id("test_id")); - Assert.AreEqual(0, parent.FindElements(By.Id("test_id")).Count); - Assert.That(() => parent.FindElement(By.Id("test_id")), Throws.InstanceOf()); + Assert.That(parent.FindElements(By.Id("test_id")), Is.Empty); + Assert.That( + () => parent.FindElement(By.Id("test_id")), + Throws.InstanceOf()); } [Test] @@ -207,7 +223,7 @@ public void ShouldFindChildElementsByClassName() IWebElement element = parent.FindElement(By.ClassName("one")); - Assert.AreEqual("Find me", element.Text); + Assert.That(element.Text, Is.EqualTo("Find me")); } [Test] @@ -218,7 +234,7 @@ public void ShouldFindChildrenByClassName() ReadOnlyCollection elements = parent.FindElements(By.ClassName("one")); - Assert.AreEqual(2, elements.Count); + Assert.That(elements, Has.Exactly(2).Items); } @@ -230,7 +246,7 @@ public void ShouldFindChildElementsByTagName() IWebElement element = parent.FindElement(By.TagName("a")); - Assert.AreEqual("link1", element.GetAttribute("name")); + Assert.That(element.GetAttribute("name"), Is.EqualTo("link1")); } @@ -242,7 +258,7 @@ public void ShouldFindChildrenByTagName() ReadOnlyCollection elements = parent.FindElements(By.TagName("a")); - Assert.AreEqual(2, elements.Count); + Assert.That(elements, Has.Exactly(2).Items); } [Test] @@ -253,7 +269,7 @@ public void ShouldBeAbleToFindAnElementByCssSelector() IWebElement element = parent.FindElement(By.CssSelector("*[name=\"selectomatic\"]")); - Assert.AreEqual("2", element.GetAttribute("id")); + Assert.That(element.GetAttribute("id"), Is.EqualTo("2")); } [Test] @@ -264,7 +280,7 @@ public void ShouldBeAbleToFindAnElementByCss3Selector() IWebElement element = parent.FindElement(By.CssSelector("*[name^=\"selecto\"]")); - Assert.AreEqual("2", element.GetAttribute("id")); + Assert.That(element.GetAttribute("id"), Is.EqualTo("2")); } [Test] @@ -275,7 +291,7 @@ public void ShouldBeAbleToFindElementsByCssSelector() ReadOnlyCollection elements = parent.FindElements(By.CssSelector("*[name=\"selectomatic\"]")); - Assert.AreEqual(2, elements.Count); + Assert.That(elements, Has.Exactly(2).Items); } [Test] @@ -284,8 +300,9 @@ public void ShouldBeAbleToFindChildrenOfANode() driver.Url = selectableItemsPage; ReadOnlyCollection elements = driver.FindElements(By.XPath("/html/head")); IWebElement head = elements[0]; + ReadOnlyCollection importedScripts = head.FindElements(By.TagName("script")); - Assert.That(importedScripts.Count, Is.EqualTo(3)); + Assert.That(importedScripts, Has.Exactly(3).Items); } [Test] @@ -293,9 +310,9 @@ public void ReturnAnEmptyListWhenThereAreNoChildrenOfANode() { driver.Url = xhtmlTestPage; IWebElement table = driver.FindElement(By.Id("table")); - ReadOnlyCollection rows = table.FindElements(By.TagName("tr")); - Assert.That(rows.Count, Is.EqualTo(0)); + ReadOnlyCollection rows = table.FindElements(By.TagName("tr")); + Assert.That(rows, Is.Empty); } [Test] @@ -311,7 +328,9 @@ public void ShouldNotFindElementOutSideTree() { driver.Url = formsPage; IWebElement element = driver.FindElement(By.Name("login")); - Assert.That(() => element.FindElement(By.Name("x")), Throws.InstanceOf()); + Assert.That( + () => element.FindElement(By.Name("x")), + Throws.InstanceOf()); } [Test] @@ -320,8 +339,8 @@ public void FindingByTagNameShouldNotIncludeParentElementIfSameTagType() driver.Url = xhtmlTestPage; IWebElement parent = driver.FindElement(By.Id("my_span")); - Assert.AreEqual(2, parent.FindElements(By.TagName("div")).Count); - Assert.AreEqual(2, parent.FindElements(By.TagName("span")).Count); + Assert.That(parent.FindElements(By.TagName("div")), Has.Exactly(2).Items); + Assert.That(parent.FindElements(By.TagName("span")), Has.Exactly(2).Items); } [Test] @@ -331,7 +350,7 @@ public void FindingByCssShouldNotIncludeParentElementIfSameTagType() IWebElement parent = driver.FindElement(By.CssSelector("div#parent")); IWebElement child = parent.FindElement(By.CssSelector("div")); - Assert.AreEqual("child", child.GetAttribute("id")); + Assert.That(child.GetAttribute("id"), Is.EqualTo("child")); } [Test] @@ -342,7 +361,7 @@ public void FindMultipleElements() ReadOnlyCollection elements = elem.FindElements(By.PartialLinkText("link")); Assert.That(elements, Is.Not.Null); - Assert.AreEqual(6, elements.Count); + Assert.That(elements, Has.Exactly(6).Items); } [Test] @@ -353,7 +372,7 @@ public void LinkWithLeadingSpaces() IWebElement elem = driver.FindElement(By.Id("links")); IWebElement res = elem.FindElement(By.PartialLinkText("link with leading space")); - Assert.AreEqual("link with leading space", res.Text); + Assert.That(res.Text, Is.EqualTo("link with leading space")); } [Test] @@ -364,7 +383,7 @@ public void LinkWithTrailingSpace() IWebElement elem = driver.FindElement(By.Id("links")); IWebElement res = elem.FindElement(By.PartialLinkText("link with trailing space")); - Assert.AreEqual("link with trailing space", res.Text); + Assert.That(res.Text, Is.EqualTo("link with trailing space")); } [Test] @@ -374,7 +393,7 @@ public void ElementCanGetLinkByLinkTestIgnoringTrailingWhitespace() IWebElement elem = driver.FindElement(By.Id("links")); IWebElement link = elem.FindElement(By.LinkText("link with trailing space")); - Assert.AreEqual("linkWithTrailingSpace", link.GetAttribute("id")); + Assert.That(link.GetAttribute("id"), Is.EqualTo("linkWithTrailingSpace")); } } } diff --git a/dotnet/test/common/ClearTest.cs b/dotnet/test/common/ClearTest.cs index 9d31803834b63..d65a7f7e7a00a 100644 --- a/dotnet/test/common/ClearTest.cs +++ b/dotnet/test/common/ClearTest.cs @@ -31,7 +31,7 @@ public void WritableTextInputShouldClear() driver.Url = readOnlyPage; IWebElement element = driver.FindElement(By.Id("writableTextInput")); element.Clear(); - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); } [Test] @@ -42,7 +42,9 @@ public void TextInputShouldNotClearWhenDisabled() driver.Url = readOnlyPage; IWebElement element = driver.FindElement(By.Id("textInputNotEnabled")); Assert.That(element.Enabled, Is.False); - Assert.That(() => element.Clear(), Throws.InstanceOf()); + Assert.That( + () => element.Clear(), + Throws.InstanceOf()); } [Test] @@ -50,7 +52,9 @@ public void TextInputShouldNotClearWhenReadOnly() { driver.Url = readOnlyPage; IWebElement element = driver.FindElement(By.Id("readOnlyTextInput")); - Assert.That(() => element.Clear(), Throws.InstanceOf()); + Assert.That( + () => element.Clear(), + Throws.InstanceOf()); } [Test] @@ -59,7 +63,7 @@ public void WritableTextAreaShouldClear() driver.Url = readOnlyPage; IWebElement element = driver.FindElement(By.Id("writableTextArea")); element.Clear(); - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); } [Test] @@ -77,7 +81,9 @@ public void TextAreaShouldNotClearWhenReadOnly() { driver.Url = readOnlyPage; IWebElement element = driver.FindElement(By.Id("textAreaReadOnly")); - Assert.That(() => element.Clear(), Throws.InstanceOf()); + Assert.That( + () => element.Clear(), + Throws.InstanceOf()); } [Test] @@ -86,7 +92,8 @@ public void ContentEditableAreaShouldClear() driver.Url = readOnlyPage; IWebElement element = driver.FindElement(By.Id("content-editable")); element.Clear(); - Assert.AreEqual(string.Empty, element.Text); + + Assert.That(element.Text, Is.Empty); } [Test] @@ -195,9 +202,10 @@ private void ShouldBeAbleToClearInput(By locator, string oldValue, string cleare { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("inputs.html"); IWebElement element = driver.FindElement(locator); - Assert.AreEqual(oldValue, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo(oldValue)); + element.Clear(); - Assert.AreEqual(clearedValue, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo(clearedValue)); } } } diff --git a/dotnet/test/common/ClickScrollingTest.cs b/dotnet/test/common/ClickScrollingTest.cs index 92489f1c6d943..e217f88d53a60 100644 --- a/dotnet/test/common/ClickScrollingTest.cs +++ b/dotnet/test/common/ClickScrollingTest.cs @@ -69,7 +69,8 @@ public void ShouldBeAbleToClickOnAnElementHiddenByOverflow() IWebElement link = driver.FindElement(By.Id("line8")); // This used to throw a MoveTargetOutOfBoundsException - we don't expect it to link.Click(); - Assert.AreEqual("line8", driver.FindElement(By.Id("clicked")).Text); + + Assert.That(driver.FindElement(By.Id("clicked")).Text, Is.EqualTo("line8")); } [Test] @@ -109,7 +110,7 @@ public void ShouldNotScrollOverflowElementsWhichAreVisible() IWebElement item = list.FindElement(By.Id("desired")); item.Click(); long yOffset = (long)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].scrollTop;", list); - Assert.AreEqual(0, yOffset, "Should not have scrolled"); + Assert.That(yOffset, Is.Zero, "Should not have scrolled"); } @@ -122,7 +123,7 @@ public void ShouldNotScrollIfAlreadyScrolledAndElementIsInView() driver.FindElement(By.Id("button2")).Click(); double scrollTop = GetScrollTop(); driver.FindElement(By.Id("button1")).Click(); - Assert.AreEqual(scrollTop, GetScrollTop()); + Assert.That(GetScrollTop(), Is.EqualTo(scrollTop)); } [Test] @@ -139,7 +140,7 @@ public void ShouldScrollOverflowElementsIfClickPointIsOutOfViewButElementIsInVie { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("scroll5.html"); driver.FindElement(By.Id("inner")).Click(); - Assert.AreEqual("clicked", driver.FindElement(By.Id("clicked")).Text); + Assert.That(driver.FindElement(By.Id("clicked")).Text, Is.EqualTo("clicked")); } [Test] @@ -238,7 +239,7 @@ public void ShouldNotScrollWhenGettingElementSize() driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("scroll3.html"); double scrollTop = GetScrollTop(); Size ignoredSize = driver.FindElement(By.Id("button1")).Size; - Assert.AreEqual(scrollTop, GetScrollTop()); + Assert.That(GetScrollTop(), Is.EqualTo(scrollTop)); } [Test] @@ -266,7 +267,7 @@ public void ShouldBeAbleToClickInlineTextElementWithChildElementAfterScrolling() IWebElement label = driver.FindElement(By.Id("wrapper")); label.Click(); IWebElement checkbox = driver.FindElement(By.Id("check")); - Assert.IsFalse(checkbox.Selected, "Checkbox should not be selected after click"); + Assert.That(checkbox.Selected, Is.False, "Checkbox should not be selected after click"); } private double GetScrollTop() diff --git a/dotnet/test/common/ClickTest.cs b/dotnet/test/common/ClickTest.cs index 5a5f9cd06a4fa..20739bbe3d114 100644 --- a/dotnet/test/common/ClickTest.cs +++ b/dotnet/test/common/ClickTest.cs @@ -43,7 +43,7 @@ public void CanClickOnALinkAndFollowIt() { driver.FindElement(By.Id("normal")).Click(); WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -63,7 +63,7 @@ public void CanClickOnAnAnchorAndNotReloadThePage() bool samePage = (bool)((IJavaScriptExecutor)driver).ExecuteScript("return document.latch"); - Assert.AreEqual(true, samePage, "Latch was reset"); + Assert.That(samePage, Is.True, "Latch was reset"); } [Test] @@ -115,7 +115,7 @@ public void CanClickOnAnElementWithTopSetToANegativeNumber() driver.FindElement(By.Name("btn")).Click(); string log = driver.FindElement(By.Id("log")).Text; - Assert.AreEqual("click", log); + Assert.That(log, Is.EqualTo("click")); } [Test] @@ -136,7 +136,7 @@ public void ShouldSetRelatedTargetForMouseOver() } else { - Assert.AreEqual("parent matches? true", log); + Assert.That(log, Is.EqualTo("parent matches? true")); } } @@ -145,7 +145,7 @@ public void ShouldClickOnFirstBoundingClientRectWithNonZeroSize() { driver.FindElement(By.Id("twoClientRects")).Click(); WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -158,7 +158,7 @@ public void ShouldOnlyFollowHrefOnce() driver.FindElement(By.Id("new-window")).Click(); WaitFor(() => { return driver.WindowHandles.Count >= windowHandlesBefore + 1; }, "Window handles was not " + (windowHandlesBefore + 1).ToString()); - Assert.AreEqual(windowHandlesBefore + 1, driver.WindowHandles.Count); + Assert.That(driver.WindowHandles, Has.Exactly(windowHandlesBefore + 1).Items); } [Test] @@ -176,7 +176,7 @@ public void CanClickOnALinkWithEnclosedImage() { driver.FindElement(By.Id("link-with-enclosed-image")).Click(); WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -184,7 +184,7 @@ public void CanClickOnAnImageEnclosedInALink() { driver.FindElement(By.Id("link-with-enclosed-image")).FindElement(By.TagName("img")).Click(); WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -192,7 +192,7 @@ public void CanClickOnALinkThatContainsTextWrappedInASpan() { driver.FindElement(By.Id("link-with-enclosed-span")).Click(); WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -201,7 +201,7 @@ public void CanClickOnALinkThatContainsEmbeddedBlockElements() { driver.FindElement(By.Id("embeddedBlock")).Click(); WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -209,7 +209,7 @@ public void CanClickOnAnElementEnclosedInALink() { driver.FindElement(By.Id("link-with-enclosed-span")).FindElement(By.TagName("span")).Click(); WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -287,7 +287,7 @@ public void ShouldBeAbleToClickOnRightToLeftLanguageLink() element.Click(); WaitFor(() => driver.Title == "clicks", "Expected title to be 'clicks'"); - Assert.AreEqual("clicks", driver.Title); + Assert.That(driver.Title, Is.EqualTo("clicks")); } [Test] @@ -298,7 +298,7 @@ public void ShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooter() driver.FindElement(By.Id("link")).Click(); WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -309,7 +309,7 @@ public void ShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooterInQuirksMode() driver.FindElement(By.Id("link")).Click(); WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -321,7 +321,7 @@ public void ShouldBeAbleToClickOnLinksWithNoHrefAttribute() element.Click(); WaitFor(() => driver.Title == "Changed", "Expected title to be 'Changed'"); - Assert.AreEqual("Changed", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Changed")); } [Test] @@ -332,7 +332,7 @@ public void ShouldBeAbleToClickOnALinkThatWrapsToTheNextLine() driver.FindElement(By.Id("link")).Click(); WaitFor(() => driver.Title == "Submitted Successfully!", "Expected title to be 'Submitted Successfully!'"); - Assert.AreEqual("Submitted Successfully!", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Submitted Successfully!")); } [Test] @@ -343,7 +343,7 @@ public void ShouldBeAbleToClickOnASpanThatWrapsToTheNextLine() driver.FindElement(By.Id("span")).Click(); WaitFor(() => driver.Title == "Submitted Successfully!", "Expected title to be 'Submitted Successfully!'"); - Assert.AreEqual("Submitted Successfully!", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Submitted Successfully!")); } [Test] @@ -364,7 +364,7 @@ public void ShouldBeAbleToClickLinkContainingLineBreak() driver.Url = simpleTestPage; driver.FindElement(By.Id("multilinelink")).Click(); WaitFor(() => { return driver.Title == "We Arrive Here"; }, "Browser title was not 'We Arrive Here'"); - Assert.AreEqual("We Arrive Here", driver.Title); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } } } diff --git a/dotnet/test/common/ContentEditableTest.cs b/dotnet/test/common/ContentEditableTest.cs index f927694ba078e..73f1e2c3cc20f 100644 --- a/dotnet/test/common/ContentEditableTest.cs +++ b/dotnet/test/common/ContentEditableTest.cs @@ -63,7 +63,7 @@ public void NonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet() element.SendKeys("Dishy" + Keys.Backspace + Keys.Left + Keys.Left); element.SendKeys(Keys.Left + Keys.Left + "F" + Keys.Delete + Keys.End + "ee!"); - Assert.AreEqual("Fishee!", element.Text); + Assert.That(element.Text, Is.EqualTo("Fishee!")); } [Test] @@ -137,7 +137,7 @@ public void AppendsTextToEndOfContentEditableWithMultipleTextNodes() IWebElement input = driver.FindElement(By.Id("editable")); input.SendKeys(", world!"); WaitFor(() => input.Text != "Why hello", "Text remained the original text"); - Assert.AreEqual("Why hello, world!", input.Text); + Assert.That(input.Text, Is.EqualTo("Why hello, world!")); } } } diff --git a/dotnet/test/common/CookieImplementationTest.cs b/dotnet/test/common/CookieImplementationTest.cs index 846d1a832bdeb..a329895d79b7d 100644 --- a/dotnet/test/common/CookieImplementationTest.cs +++ b/dotnet/test/common/CookieImplementationTest.cs @@ -54,7 +54,7 @@ public void ShouldGetCookieByName() ((IJavaScriptExecutor)driver).ExecuteScript("document.cookie = arguments[0] + '=set';", key); Cookie cookie = driver.Manage().Cookies.GetCookieNamed(key); - Assert.AreEqual("set", cookie.Value); + Assert.That(cookie.Value, Is.EqualTo("set")); } [Test] @@ -73,7 +73,7 @@ public void ShouldBeAbleToAddCookie() driver.Manage().Cookies.AddCookie(cookie); AssertCookieHasValue(key, value); - Assert.That(driver.Manage().Cookies.AllCookies.Contains(cookie), "Cookie was not added successfully"); + Assert.That(driver.Manage().Cookies.AllCookies, Does.Contain(cookie), "Cookie was not added successfully"); } [Test] @@ -101,7 +101,7 @@ public void GetAllCookies() driver.Url = simpleTestPage; cookies = driver.Manage().Cookies.AllCookies; - Assert.AreEqual(count + 2, cookies.Count); + Assert.That(cookies, Has.Count.EqualTo(count + 2)); Assert.That(cookies, Does.Contain(one)); Assert.That(cookies, Does.Contain(two)); @@ -389,7 +389,7 @@ public void ShouldWalkThePathToDeleteACookie() Assert.That(driver.Manage().Cookies.GetCookieNamed("rodent"), Is.Null); ReadOnlyCollection cookies = driver.Manage().Cookies.AllCookies; - Assert.That(cookies, Has.Count.EqualTo(2)); + Assert.That(cookies, Has.Exactly(2).Items); Assert.That(cookies, Does.Contain(cookie1)); Assert.That(cookies, Does.Contain(cookie3)); @@ -450,7 +450,7 @@ public void CookieEqualityAfterSetAndGet() Assert.That(retrievedCookie, Is.Not.Null); //Cookie.equals only compares name, domain and path - Assert.AreEqual(cookie1, retrievedCookie); + Assert.That(retrievedCookie, Is.EqualTo(cookie1)); } [Test] @@ -472,7 +472,7 @@ public void ShouldRetainCookieExpiry() Cookie retrieved = options.Cookies.GetCookieNamed("fish"); Assert.That(retrieved, Is.Not.Null); - Assert.AreEqual(addCookie.Expiry, retrieved.Expiry, "Cookies are not equal"); + Assert.That(retrieved.Expiry, Is.EqualTo(addCookie.Expiry), "Cookies are not equal"); } [Test] @@ -713,7 +713,7 @@ public void ShouldAddCookieToCurrentDomainAndPath() Cookie cookie = new Cookie("Homer", "Simpson", this.hostname, "/" + EnvironmentManager.Instance.UrlBuilder.Path, null); options.Cookies.AddCookie(cookie); ReadOnlyCollection cookies = options.Cookies.AllCookies; - Assert.That(cookies.Contains(cookie), "Valid cookie was not returned"); + Assert.That(cookies, Does.Contain(cookie), "Valid cookie was not returned"); } [Test] @@ -727,7 +727,10 @@ public void ShouldNotShowCookieAddedToDifferentDomain() driver.Url = macbethPage; IOptions options = driver.Manage(); Cookie cookie = new Cookie("Bart", "Simpson", EnvironmentManager.Instance.UrlBuilder.HostName + ".com", EnvironmentManager.Instance.UrlBuilder.Path, null); - Assert.That(() => options.Cookies.AddCookie(cookie), Throws.InstanceOf().Or.InstanceOf()); + Assert.That( + () => options.Cookies.AddCookie(cookie), + Throws.InstanceOf().Or.InstanceOf()); + ReadOnlyCollection cookies = options.Cookies.AllCookies; Assert.That(cookies, Does.Not.Contain(cookie), "Invalid cookie was returned"); } @@ -771,7 +774,9 @@ public void ShouldThrowExceptionWhenAddingCookieToCookieAverseDocument() IOptions options = driver.Manage(); Cookie cookie = new Cookie("question", "dunno"); - Assert.That(() => options.Cookies.AddCookie(cookie), Throws.InstanceOf().Or.InstanceOf()); + Assert.That( + () => options.Cookies.AddCookie(cookie), + Throws.InstanceOf().Or.InstanceOf()); } [Test] @@ -803,7 +808,7 @@ public void ShouldAddCookieToCurrentDomain() Cookie cookie = new Cookie("Marge", "Simpson", "/"); options.Cookies.AddCookie(cookie); ReadOnlyCollection cookies = options.Cookies.AllCookies; - Assert.That(cookies.Contains(cookie), "Valid cookie was not returned"); + Assert.That(cookies, Does.Contain(cookie), "Valid cookie was not returned"); } [Test] @@ -824,7 +829,7 @@ public void ShouldDeleteCookie() options.Cookies.DeleteCookie(cookieToDelete); ReadOnlyCollection cookies2 = options.Cookies.AllCookies; Assert.That(cookies2, Does.Not.Contain(cookieToDelete), "Cookie was not deleted successfully"); - Assert.That(cookies2.Contains(cookieToKeep), "Valid cookie was not returned"); + Assert.That(cookies2, Does.Contain(cookieToKeep), "Valid cookie was not returned"); } ////////////////////////////////////////////// @@ -924,21 +929,21 @@ private string GetDocumentCookieOrNull() private void AssertNoCookiesArePresent() { - Assert.That(driver.Manage().Cookies.AllCookies.Count, Is.EqualTo(0), "Cookies were not empty"); + Assert.That(driver.Manage().Cookies.AllCookies, Is.Empty, "Cookies were not empty"); string documentCookie = GetDocumentCookieOrNull(); if (documentCookie != null) { - Assert.AreEqual(string.Empty, documentCookie, "Cookies were not empty"); + Assert.That(documentCookie, Is.Empty, "Cookies were not empty"); } } private void AssertSomeCookiesArePresent() { - Assert.That(driver.Manage().Cookies.AllCookies.Count, Is.Not.EqualTo(0), "Cookies were empty"); + Assert.That(driver.Manage().Cookies.AllCookies, Is.Not.Empty, "Cookies were empty"); String documentCookie = GetDocumentCookieOrNull(); if (documentCookie != null) { - Assert.AreNotEqual(string.Empty, documentCookie, "Cookies were empty"); + Assert.That(documentCookie, Is.Not.Empty, "Cookies were empty"); } } @@ -964,7 +969,7 @@ private void AssertCookieIsPresentWithName(string key) private void AssertCookieHasValue(string key, string value) { - Assert.AreEqual(value, driver.Manage().Cookies.GetCookieNamed(key).Value, "Cookie had wrong value"); + Assert.That(driver.Manage().Cookies.GetCookieNamed(key).Value, Is.EqualTo(value), "Cookie had wrong value"); string documentCookie = GetDocumentCookieOrNull(); if (documentCookie != null) { diff --git a/dotnet/test/common/CorrectEventFiringTest.cs b/dotnet/test/common/CorrectEventFiringTest.cs index d30e205b485fd..6e1da8e0313bd 100644 --- a/dotnet/test/common/CorrectEventFiringTest.cs +++ b/dotnet/test/common/CorrectEventFiringTest.cs @@ -158,7 +158,7 @@ public void ShouldIssueMouseDownEvents() driver.FindElement(By.Id("mousedown")).Click(); String result = driver.FindElement(By.Id("result")).Text; - Assert.AreEqual(result, "mouse down"); + Assert.That(result, Is.EqualTo("mouse down")); } [Test] @@ -168,7 +168,7 @@ public void ShouldIssueClickEvents() driver.FindElement(By.Id("mouseclick")).Click(); String result = driver.FindElement(By.Id("result")).Text; - Assert.AreEqual("mouse click", result); + Assert.That(result, Is.EqualTo("mouse click")); } [Test] @@ -178,7 +178,7 @@ public void ShouldIssueMouseUpEvents() driver.FindElement(By.Id("mouseup")).Click(); String result = driver.FindElement(By.Id("result")).Text; - Assert.AreEqual(result, "mouse up"); + Assert.That(result, Is.EqualTo("mouse up")); } [Test] @@ -188,7 +188,7 @@ public void MouseEventsShouldBubbleUpToContainingElements() driver.FindElement(By.Id("child")).Click(); String result = driver.FindElement(By.Id("result")).Text; - Assert.AreEqual(result, "mouse down"); + Assert.That(result, Is.EqualTo("mouse down")); } [Test] @@ -205,9 +205,9 @@ public void ShouldEmitOnChangeEventsWhenSelectingElements() IWebElement bar = allOptions[1]; foo.Click(); - Assert.AreEqual(driver.FindElement(By.Id("result")).Text, initialTextValue); + Assert.That(driver.FindElement(By.Id("result")).Text, Is.EqualTo(initialTextValue)); bar.Click(); - Assert.AreEqual(driver.FindElement(By.Id("result")).Text, "bar"); + Assert.That(driver.FindElement(By.Id("result")).Text, Is.EqualTo("bar")); } [Test] @@ -221,9 +221,9 @@ public void ShouldEmitOnClickEventsWhenSelectingElements() IWebElement bar = allOptions[1]; foo.Click(); - Assert.AreEqual(driver.FindElement(By.Id("result")).Text, "foo"); + Assert.That(driver.FindElement(By.Id("result")).Text, Is.EqualTo("foo")); bar.Click(); - Assert.AreEqual(driver.FindElement(By.Id("result")).Text, "bar"); + Assert.That(driver.FindElement(By.Id("result")).Text, Is.EqualTo("bar")); } [Test] @@ -234,7 +234,7 @@ public void ShouldEmitOnChangeEventsWhenChangingTheStateOfACheckbox() IWebElement checkbox = driver.FindElement(By.Id("checkbox")); checkbox.Click(); - Assert.AreEqual(driver.FindElement(By.Id("result")).Text, "checkbox thing"); + Assert.That(driver.FindElement(By.Id("result")).Text, Is.EqualTo("checkbox thing")); } [Test] @@ -245,7 +245,7 @@ public void ShouldEmitClickEventWhenClickingOnATextInputElement() IWebElement clicker = driver.FindElement(By.Id("clickField")); clicker.Click(); - Assert.AreEqual(clicker.GetAttribute("value"), "Clicked"); + Assert.That(clicker.GetAttribute("value"), Is.EqualTo("Clicked")); } [Test] @@ -269,7 +269,7 @@ public void ClearingAnElementShouldCauseTheOnChangeHandlerToFire() element.Clear(); IWebElement result = driver.FindElement(By.Id("result")); - Assert.AreEqual("Cleared", result.Text.Trim()); + Assert.That(result.Text.Trim(), Is.EqualTo("Cleared")); } [Test] @@ -416,7 +416,7 @@ public void UploadingFileShouldFireOnChangeEvent() driver.Url = formsPage; IWebElement uploadElement = driver.FindElement(By.Id("upload")); IWebElement result = driver.FindElement(By.Id("fileResults")); - Assert.AreEqual(string.Empty, result.Text); + Assert.That(result.Text, Is.Empty); string filePath = System.IO.Path.Combine(EnvironmentManager.Instance.CurrentDirectory, "test.txt"); System.IO.FileInfo inputFile = new System.IO.FileInfo(filePath); @@ -429,7 +429,7 @@ public void UploadingFileShouldFireOnChangeEvent() driver.FindElement(By.Id("id-name1")).Click(); inputFile.Delete(); - Assert.AreEqual("changed", result.Text); + Assert.That(result.Text, Is.EqualTo("changed")); } [Test] @@ -445,8 +445,8 @@ public void ShouldReportTheXAndYCoordinatesWhenClicking() string clientY = driver.FindElement(By.Id("clientY")).Text; driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0); - Assert.AreNotEqual("0", clientX); - Assert.AreNotEqual("0", clientY); + Assert.That(clientX, Is.Not.EqualTo("0")); + Assert.That(clientY, Is.Not.EqualTo("0")); } [Test] @@ -487,7 +487,7 @@ public void ClickAnElementThatDisappear() driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_tests/disappearing_element.html"); driver.FindElement(By.Id("over")).Click(); - Assert.That(driver.FindElement(By.Id("log")).Text.StartsWith(expectedLogBuilder.ToString())); + Assert.That(driver.FindElement(By.Id("log")).Text, Does.StartWith(expectedLogBuilder.ToString())); } private void AssertEventNotFired(string eventName) diff --git a/dotnet/test/common/DownloadsTest.cs b/dotnet/test/common/DownloadsTest.cs index b03d44d7d8f8d..0043316b2025f 100644 --- a/dotnet/test/common/DownloadsTest.cs +++ b/dotnet/test/common/DownloadsTest.cs @@ -76,7 +76,7 @@ public void CanDownloadFile() ((RemoteWebDriver)driver).DownloadFile(fileName, targetDirectory); string fileContent = File.ReadAllText(Path.Combine(targetDirectory, fileName)); - Assert.AreEqual("Hello, World!", fileContent.Trim()); + Assert.That(fileContent.Trim(), Is.EqualTo("Hello, World!")); Directory.Delete(targetDirectory, recursive: true); } @@ -90,7 +90,7 @@ public void CanDeleteFiles() ((RemoteWebDriver)driver).DeleteDownloadableFiles(); IReadOnlyList names = ((RemoteWebDriver)driver).GetDownloadableFiles(); - Assert.IsEmpty(names, "The names list should be empty."); + Assert.That(names, Is.Empty, "The names list should be empty."); } private void DownloadWithBrowser() diff --git a/dotnet/test/common/ElementAttributeTest.cs b/dotnet/test/common/ElementAttributeTest.cs index 43a1be4a063a9..9eb59cfff2f5a 100644 --- a/dotnet/test/common/ElementAttributeTest.cs +++ b/dotnet/test/common/ElementAttributeTest.cs @@ -52,7 +52,7 @@ public void ShouldReturnAnAbsoluteUrlWhenGettingSrcAttributeOfAValidImgTag() driver.Url = simpleTestPage; IWebElement img = driver.FindElement(By.Id("validImgTag")); string attribute = img.GetAttribute("src"); - Assert.AreEqual(EnvironmentManager.Instance.UrlBuilder.WhereIs("icon.gif"), attribute); + Assert.That(attribute, Is.EqualTo(EnvironmentManager.Instance.UrlBuilder.WhereIs("icon.gif"))); } [Test] @@ -61,7 +61,7 @@ public void ShouldReturnAnAbsoluteUrlWhenGettingHrefAttributeOfAValidAnchorTag() driver.Url = simpleTestPage; IWebElement img = driver.FindElement(By.Id("validAnchorTag")); string attribute = img.GetAttribute("href"); - Assert.AreEqual(EnvironmentManager.Instance.UrlBuilder.WhereIs("icon.gif"), attribute); + Assert.That(attribute, Is.EqualTo(EnvironmentManager.Instance.UrlBuilder.WhereIs("icon.gif"))); } @@ -70,7 +70,7 @@ public void ShouldReturnEmptyAttributeValuesWhenPresentAndTheValueIsActuallyEmpt { driver.Url = simpleTestPage; IWebElement body = driver.FindElement(By.XPath("//body")); - Assert.AreEqual(string.Empty, body.GetAttribute("style")); + Assert.That(body.GetAttribute("style"), Is.Empty); } [Test] @@ -93,7 +93,7 @@ public void ShouldReturnTheValueOfTheIndexAttrbuteEvenIfItIsMissing() IWebElement multiSelect = driver.FindElement(By.Id("multi")); ReadOnlyCollection options = multiSelect.FindElements(By.TagName("option")); - Assert.AreEqual("1", options[1].GetAttribute("index")); + Assert.That(options[1].GetAttribute("index"), Is.EqualTo("1")); } @@ -133,7 +133,7 @@ public void ShouldThrowExceptionIfSendingKeysToElementDisabledUsingRandomDisable disabledTextElement1.SendKeys("foo"); }, Throws.TypeOf()); - Assert.AreEqual(string.Empty, disabledTextElement1.Text); + Assert.That(disabledTextElement1.Text, Is.Empty); IWebElement disabledTextElement2 = driver.FindElement(By.Id("disabledTextElement2")); @@ -141,7 +141,7 @@ public void ShouldThrowExceptionIfSendingKeysToElementDisabledUsingRandomDisable () => disabledTextElement2.SendKeys("bar"), Throws.TypeOf()); - Assert.AreEqual(string.Empty, disabledTextElement2.Text); + Assert.That(disabledTextElement2.Text, Is.Empty); } [Test] @@ -169,9 +169,9 @@ public void ShouldReturnTheValueOfCheckedForACheckboxOnlyIfItIsChecked() { driver.Url = formsPage; IWebElement checkbox = driver.FindElement(By.XPath("//input[@id='checky']")); - Assert.AreEqual(null, checkbox.GetAttribute("checked")); + Assert.That(checkbox.GetAttribute("checked"), Is.Null); checkbox.Click(); - Assert.AreEqual("true", checkbox.GetAttribute("checked")); + Assert.That(checkbox.GetAttribute("checked"), Is.EqualTo("true")); } [Test] @@ -182,14 +182,14 @@ public void ShouldOnlyReturnTheValueOfSelectedForRadioButtonsIfItIsSet() IWebElement initiallyNotSelected = driver.FindElement(By.Id("peas")); IWebElement initiallySelected = driver.FindElement(By.Id("cheese_and_peas")); - Assert.AreEqual(null, neverSelected.GetAttribute("selected"), "false"); - Assert.AreEqual(null, initiallyNotSelected.GetAttribute("selected"), "false"); - Assert.AreEqual("true", initiallySelected.GetAttribute("selected"), "true"); + Assert.That(neverSelected.GetAttribute("selected"), Is.Null, "false"); + Assert.That(initiallyNotSelected.GetAttribute("selected"), Is.Null, "false"); + Assert.That(initiallySelected.GetAttribute("selected"), Is.EqualTo("true"), "true"); initiallyNotSelected.Click(); - Assert.AreEqual(null, neverSelected.GetAttribute("selected")); - Assert.AreEqual("true", initiallyNotSelected.GetAttribute("selected")); - Assert.AreEqual(null, initiallySelected.GetAttribute("selected")); + Assert.That(neverSelected.GetAttribute("selected"), Is.Null); + Assert.That(initiallyNotSelected.GetAttribute("selected"), Is.EqualTo("true")); + Assert.That(initiallySelected.GetAttribute("selected"), Is.Null); } [Test] @@ -202,8 +202,8 @@ public void ShouldReturnTheValueOfSelectedForOptionsOnlyIfTheyAreSelected() IWebElement two = options[1]; Assert.That(one.Selected, Is.True); Assert.That(two.Selected, Is.False); - Assert.AreEqual("true", one.GetAttribute("selected")); - Assert.AreEqual(null, two.GetAttribute("selected")); + Assert.That(one.GetAttribute("selected"), Is.EqualTo("true")); + Assert.That(two.GetAttribute("selected"), Is.Null); } [Test] @@ -214,7 +214,7 @@ public void ShouldReturnValueOfClassAttributeOfAnElement() IWebElement heading = driver.FindElement(By.XPath("//h1")); String className = heading.GetAttribute("class"); - Assert.AreEqual("header", className); + Assert.That(className, Is.EqualTo("header")); } [Test] @@ -224,7 +224,7 @@ public void ShouldReturnTheContentsOfATextAreaAsItsValue() String value = driver.FindElement(By.Id("withText")).GetAttribute("value"); - Assert.AreEqual("Example text", value); + Assert.That(value, Is.EqualTo("Example text")); } [Test] @@ -260,7 +260,7 @@ public void ShouldReturnHiddenTextForTextContentAttribute() IWebElement element = driver.FindElement(By.Id("hiddenline")); string textContent = element.GetAttribute("textContent"); - Assert.AreEqual("A hidden line of text", textContent); + Assert.That(textContent, Is.EqualTo("A hidden line of text")); } [Test] @@ -268,7 +268,7 @@ public void ShouldGetNumericAtribute() { driver.Url = formsPage; IWebElement element = driver.FindElement(By.Id("withText")); - Assert.AreEqual("5", element.GetAttribute("rows")); + Assert.That(element.GetAttribute("rows"), Is.EqualTo("5")); } [Test] @@ -288,11 +288,11 @@ public void ShouldCorrectlyReportValueOfColspan() IWebElement th1 = driver.FindElement(By.Id("th1")); IWebElement td2 = driver.FindElement(By.Id("td2")); - Assert.AreEqual("th1", th1.GetAttribute("id"), "th1 id"); - Assert.AreEqual("3", th1.GetAttribute("colspan"), "th1 colspan should be 3"); + Assert.That(th1.GetAttribute("id"), Is.EqualTo("th1"), "th1 id"); + Assert.That(th1.GetAttribute("colspan"), Is.EqualTo("3"), "th1 colspan should be 3"); - Assert.AreEqual("td2", td2.GetAttribute("id"), "td2 id"); - Assert.AreEqual("2", td2.GetAttribute("colspan"), "td2 colspan should be 2"); + Assert.That(td2.GetAttribute("id"), Is.EqualTo("td2"), "td2 id"); + Assert.That(td2.GetAttribute("colspan"), Is.EqualTo("2"), "td2 colspan should be 2"); } // This is a test-case re-creating issue 900. @@ -325,7 +325,7 @@ public void GetAttributeDoesNotReturnAnObjectForSvgProperties() driver.Url = svgPage; IWebElement svgElement = driver.FindElement(By.Id("rotate")); - Assert.AreEqual("rotate(30)", svgElement.GetAttribute("transform")); + Assert.That(svgElement.GetAttribute("transform"), Is.EqualTo("rotate(30)")); } [Test] @@ -333,9 +333,9 @@ public void CanRetrieveTheCurrentValueOfATextFormField_textInput() { driver.Url = formsPage; IWebElement element = driver.FindElement(By.Id("working")); - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); element.SendKeys("hello world"); - Assert.AreEqual("hello world", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("hello world")); } [Test] @@ -343,9 +343,9 @@ public void CanRetrieveTheCurrentValueOfATextFormField_emailInput() { driver.Url = formsPage; IWebElement element = driver.FindElement(By.Id("email")); - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); element.SendKeys("hello world"); - Assert.AreEqual("hello world", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("hello world")); } [Test] @@ -353,9 +353,9 @@ public void CanRetrieveTheCurrentValueOfATextFormField_textArea() { driver.Url = formsPage; IWebElement element = driver.FindElement(By.Id("emptyTextArea")); - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); element.SendKeys("hello world"); - Assert.AreEqual("hello world", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("hello world")); } [Test] @@ -373,15 +373,15 @@ public void ShouldReturnTrueForPresentBooleanAttributes() { driver.Url = booleanAttributes; IWebElement element1 = driver.FindElement(By.Id("emailRequired")); - Assert.AreEqual("true", element1.GetAttribute("required")); + Assert.That(element1.GetAttribute("required"), Is.EqualTo("true")); IWebElement element2 = driver.FindElement(By.Id("emptyTextAreaRequired")); - Assert.AreEqual("true", element2.GetAttribute("required")); + Assert.That(element2.GetAttribute("required"), Is.EqualTo("true")); IWebElement element3 = driver.FindElement(By.Id("inputRequired")); - Assert.AreEqual("true", element3.GetAttribute("required")); + Assert.That(element3.GetAttribute("required"), Is.EqualTo("true")); IWebElement element4 = driver.FindElement(By.Id("textAreaRequired")); - Assert.AreEqual("true", element4.GetAttribute("required")); + Assert.That(element4.GetAttribute("required"), Is.EqualTo("true")); IWebElement element5 = driver.FindElement(By.Id("unwrappable")); - Assert.AreEqual("true", element5.GetAttribute("nowrap")); + Assert.That(element5.GetAttribute("nowrap"), Is.EqualTo("true")); } [Test] @@ -389,7 +389,7 @@ public void MultipleAttributeShouldBeNullWhenNotSet() { driver.Url = selectPage; IWebElement element = driver.FindElement(By.Id("selectWithoutMultiple")); - Assert.AreEqual(null, element.GetAttribute("multiple")); + Assert.That(element.GetAttribute("multiple"), Is.Null); } [Test] @@ -397,7 +397,7 @@ public void MultipleAttributeShouldBeTrueWhenSet() { driver.Url = selectPage; IWebElement element = driver.FindElement(By.Id("selectWithMultipleEqualsMultiple")); - Assert.AreEqual("true", element.GetAttribute("multiple")); + Assert.That(element.GetAttribute("multiple"), Is.EqualTo("true")); } [Test] @@ -405,7 +405,7 @@ public void MultipleAttributeShouldBeTrueWhenSelectHasMultipleWithValueAsBlank() { driver.Url = selectPage; IWebElement element = driver.FindElement(By.Id("selectWithEmptyStringMultiple")); - Assert.AreEqual("true", element.GetAttribute("multiple")); + Assert.That(element.GetAttribute("multiple"), Is.EqualTo("true")); } [Test] @@ -413,7 +413,7 @@ public void MultipleAttributeShouldBeTrueWhenSelectHasMultipleWithoutAValue() { driver.Url = selectPage; IWebElement element = driver.FindElement(By.Id("selectWithMultipleWithoutValue")); - Assert.AreEqual("true", element.GetAttribute("multiple")); + Assert.That(element.GetAttribute("multiple"), Is.EqualTo("true")); } [Test] @@ -421,7 +421,7 @@ public void MultipleAttributeShouldBeTrueWhenSelectHasMultipleWithValueAsSomethi { driver.Url = selectPage; IWebElement element = driver.FindElement(By.Id("selectWithRandomMultipleValue")); - Assert.AreEqual("true", element.GetAttribute("multiple")); + Assert.That(element.GetAttribute("multiple"), Is.EqualTo("true")); } [Test] @@ -429,7 +429,7 @@ public void GetAttributeOfUserDefinedProperty() { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("userDefinedProperty.html"); IWebElement element = driver.FindElement(By.Id("d")); - Assert.AreEqual("sampleValue", element.GetAttribute("dynamicProperty")); + Assert.That(element.GetAttribute("dynamicProperty"), Is.EqualTo("sampleValue")); } [Test] @@ -440,7 +440,7 @@ public void ShouldReturnValueOfClassAttributeOfAnElementAfterSwitchingIFrame() IWebElement wallace = driver.FindElement(By.XPath("//div[@id='wallace']")); String className = wallace.GetAttribute("class"); - Assert.AreEqual("gromit", className); + Assert.That(className, Is.EqualTo("gromit")); } } } diff --git a/dotnet/test/common/ElementEqualityTest.cs b/dotnet/test/common/ElementEqualityTest.cs index b86111ae4414c..0ecf01983c9b8 100644 --- a/dotnet/test/common/ElementEqualityTest.cs +++ b/dotnet/test/common/ElementEqualityTest.cs @@ -34,7 +34,7 @@ public void SameElementLookedUpDifferentWaysShouldBeEqual() IWebElement body = driver.FindElement(By.TagName("body")); IWebElement xbody = driver.FindElement(By.XPath("//body")); - Assert.AreEqual(body, xbody); + Assert.That(xbody, Is.EqualTo(body)); } [Test] @@ -44,7 +44,7 @@ public void DifferentElementsShouldNotBeEqual() ReadOnlyCollection ps = driver.FindElements(By.TagName("p")); - Assert.AreNotEqual(ps[0], ps[1]); + Assert.That(ps[1], Is.Not.EqualTo(ps[0])); } [Test] @@ -54,7 +54,7 @@ public void SameElementLookedUpDifferentWaysUsingFindElementShouldHaveSameHashCo IWebElement body = driver.FindElement(By.TagName("body")); IWebElement xbody = driver.FindElement(By.XPath("//body")); - Assert.AreEqual(body.GetHashCode(), xbody.GetHashCode()); + Assert.That(xbody.GetHashCode(), Is.EqualTo(body.GetHashCode())); } public void SameElementLookedUpDifferentWaysUsingFindElementsShouldHaveSameHashCode() @@ -63,7 +63,7 @@ public void SameElementLookedUpDifferentWaysUsingFindElementsShouldHaveSameHashC ReadOnlyCollection body = driver.FindElements(By.TagName("body")); ReadOnlyCollection xbody = driver.FindElements(By.XPath("//body")); - Assert.AreEqual(body[0].GetHashCode(), xbody[0].GetHashCode()); + Assert.That(xbody[0].GetHashCode(), Is.EqualTo(body[0].GetHashCode())); } [Test] @@ -76,7 +76,7 @@ public void AnElementFoundInViaJsShouldHaveSameId() IWebElement element = (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript("return document.getElementById('oneline');"); - Assert.AreEqual(first, element); + Assert.That(element, Is.EqualTo(first)); } } } diff --git a/dotnet/test/common/ElementFindingTest.cs b/dotnet/test/common/ElementFindingTest.cs index 313077382fc4f..f1375531be5f3 100644 --- a/dotnet/test/common/ElementFindingTest.cs +++ b/dotnet/test/common/ElementFindingTest.cs @@ -34,7 +34,7 @@ public void ShouldBeAbleToFindASingleElementById() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.Id("linkId")); - Assert.AreEqual("linkId", element.GetAttribute("id")); + Assert.That(element.GetAttribute("id"), Is.EqualTo("linkId")); } [Test] @@ -60,7 +60,7 @@ public void ShouldBeAbleToFindMultipleElementsById() { driver.Url = nestedPage; ReadOnlyCollection elements = driver.FindElements(By.Id("2")); - Assert.AreEqual(8, elements.Count); + Assert.That(elements, Has.Exactly(8).Items); } [Test] @@ -68,7 +68,7 @@ public void ShouldBeAbleToFindMultipleElementsByNumericId() { driver.Url = nestedPage; ReadOnlyCollection elements = driver.FindElements(By.Id("2")); - Assert.That(elements.Count, Is.EqualTo(8)); + Assert.That(elements, Has.Exactly(8).Items); } [Test] @@ -76,9 +76,9 @@ public void ShouldBeAbleToFindMultipleElementsByIdWithNonAlphanumericCharacters( { driver.Url = nestedPage; ReadOnlyCollection elements = driver.FindElements(By.Id("white space")); - Assert.That(elements.Count, Is.EqualTo(2)); + Assert.That(elements, Has.Exactly(2).Items); ReadOnlyCollection elements2 = driver.FindElements(By.Id("css#.chars")); - Assert.That(elements2.Count, Is.EqualTo(2)); + Assert.That(elements2, Has.Exactly(2).Items); } // By.id negative @@ -95,7 +95,7 @@ public void ShouldNotBeAbleToLocateByIdMultipleElementsThatDoNotExist() { driver.Url = formsPage; ReadOnlyCollection elements = driver.FindElements(By.Id("nonExistentButton")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } [Test] @@ -110,7 +110,7 @@ public void FindingMultipleElementsByEmptyIdShouldReturnEmptyList() { driver.Url = formsPage; ReadOnlyCollection elements = driver.FindElements(By.Id("")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } [Test] @@ -125,7 +125,7 @@ public void FindingMultipleElementsByIdWithSpaceShouldReturnEmptyList() { driver.Url = formsPage; ReadOnlyCollection elements = driver.FindElements(By.Id("nonexistent button")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } // By.Name positive @@ -135,7 +135,7 @@ public void ShouldBeAbleToFindASingleElementByName() { driver.Url = formsPage; IWebElement element = driver.FindElement(By.Name("checky")); - Assert.AreEqual("furrfu", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("furrfu")); } [Test] @@ -151,7 +151,7 @@ public void ShouldBeAbleToFindAnElementThatDoesNotSupportTheNameProperty() { driver.Url = nestedPage; IWebElement element = driver.FindElement(By.Name("div1")); - Assert.AreEqual("div1", element.GetAttribute("name")); + Assert.That(element.GetAttribute("name"), Is.EqualTo("div1")); } // By.Name negative @@ -168,7 +168,7 @@ public void ShouldNotBeAbleToLocateByNameMultipleElementsThatDoNotExist() { driver.Url = formsPage; ReadOnlyCollection elements = driver.FindElements(By.Name("nonExistentButton")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } [Test] @@ -183,7 +183,7 @@ public void FindingMultipleElementsByEmptyNameShouldReturnEmptyList() { driver.Url = formsPage; ReadOnlyCollection elements = driver.FindElements(By.Name("")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } [Test] @@ -198,7 +198,7 @@ public void FindingMultipleElementsByNameWithSpaceShouldReturnEmptyList() { driver.Url = formsPage; ReadOnlyCollection elements = driver.FindElements(By.Name("nonexistent button")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } // By.tagName positive @@ -208,7 +208,7 @@ public void ShouldBeAbleToFindASingleElementByTagName() { driver.Url = formsPage; IWebElement element = driver.FindElement(By.TagName("input")); - Assert.AreEqual("input", element.TagName.ToLower()); + Assert.That(element.TagName.ToLower(), Is.EqualTo("input")); } [Test] @@ -233,7 +233,7 @@ public void ShouldNotBeAbleToLocateByTagNameMultipleElementsThatDoNotExist() { driver.Url = formsPage; ReadOnlyCollection elements = driver.FindElements(By.TagName("nonExistentButton")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } [Test] @@ -255,7 +255,7 @@ public void FindingMultipleElementsByTagNameWithSpaceShouldReturnEmptyList() { driver.Url = formsPage; ReadOnlyCollection elements = driver.FindElements(By.TagName("nonexistent button")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } // By.ClassName positive @@ -273,7 +273,7 @@ public void ShouldBeAbleToFindMultipleElementsByClassName() { driver.Url = xhtmlTestPage; ReadOnlyCollection elements = driver.FindElements(By.ClassName("nameC")); - Assert.That(elements.Count, Is.GreaterThan(1)); + Assert.That(elements, Has.Count.GreaterThan(1)); } [Test] @@ -281,7 +281,7 @@ public void ShouldFindElementByClassWhenItIsTheFirstNameAmongMany() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.ClassName("nameA")); - Assert.AreEqual("An H2 title", element.Text); + Assert.That(element.Text, Is.EqualTo("An H2 title")); } [Test] @@ -289,7 +289,7 @@ public void ShouldFindElementByClassWhenItIsTheLastNameAmongMany() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.ClassName("nameC")); - Assert.AreEqual("An H2 title", element.Text); + Assert.That(element.Text, Is.EqualTo("An H2 title")); } [Test] @@ -297,7 +297,7 @@ public void ShouldFindElementByClassWhenItIsInTheMiddleAmongMany() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.ClassName("nameBnoise")); - Assert.AreEqual("An H2 title", element.Text); + Assert.That(element.Text, Is.EqualTo("An H2 title")); } [Test] @@ -305,7 +305,7 @@ public void ShouldFindElementByClassWhenItsNameIsSurroundedByWhitespace() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.ClassName("spaceAround")); - Assert.AreEqual("Spaced out", element.Text); + Assert.That(element.Text, Is.EqualTo("Spaced out")); } [Test] @@ -313,8 +313,8 @@ public void ShouldFindElementsByClassWhenItsNameIsSurroundedByWhitespace() { driver.Url = xhtmlTestPage; ReadOnlyCollection elements = driver.FindElements(By.ClassName("spaceAround")); - Assert.AreEqual(1, elements.Count); - Assert.AreEqual("Spaced out", elements[0].Text); + Assert.That(elements, Has.Exactly(1).Items); + Assert.That(elements[0].Text, Is.EqualTo("Spaced out")); } // By.ClassName negative @@ -360,7 +360,7 @@ public void FindingASingleElementByAWeirdLookingClassName() driver.Url = xhtmlTestPage; String weird = "cls-!@#$%^&*"; IWebElement element = driver.FindElement(By.ClassName(weird)); - Assert.AreEqual(weird, element.GetAttribute("class")); + Assert.That(element.GetAttribute("class"), Is.EqualTo(weird)); } [Test] @@ -369,8 +369,8 @@ public void FindingMultipleElementsByAWeirdLookingClassName() driver.Url = xhtmlTestPage; String weird = "cls-!@#$%^&*"; ReadOnlyCollection elements = driver.FindElements(By.ClassName(weird)); - Assert.AreEqual(1, elements.Count); - Assert.AreEqual(weird, elements[0].GetAttribute("class")); + Assert.That(elements, Has.Count.EqualTo(1)); + Assert.That(elements[0].GetAttribute("class"), Is.EqualTo(weird)); } // By.XPath positive @@ -380,7 +380,7 @@ public void ShouldBeAbleToFindASingleElementByXPath() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.XPath("//h1")); - Assert.AreEqual("XHTML Might Be The Future", element.Text); + Assert.That(element.Text, Is.EqualTo("XHTML Might Be The Future")); } [Test] @@ -388,7 +388,7 @@ public void ShouldBeAbleToFindMultipleElementsByXPath() { driver.Url = xhtmlTestPage; ReadOnlyCollection elements = driver.FindElements(By.XPath("//div")); - Assert.AreEqual(13, elements.Count); + Assert.That(elements, Has.Count.EqualTo(13)); } [Test] @@ -396,10 +396,10 @@ public void ShouldBeAbleToFindManyElementsRepeatedlyByXPath() { driver.Url = xhtmlTestPage; String xpathString = "//node()[contains(@id,'id')]"; - Assert.AreEqual(3, driver.FindElements(By.XPath(xpathString)).Count); + Assert.That(driver.FindElements(By.XPath(xpathString)), Has.Exactly(3).Items); xpathString = "//node()[contains(@id,'nope')]"; - Assert.AreEqual(0, driver.FindElements(By.XPath(xpathString)).Count); + Assert.That(driver.FindElements(By.XPath(xpathString)), Is.Empty); } [Test] @@ -407,7 +407,7 @@ public void ShouldBeAbleToIdentifyElementsByClass() { driver.Url = xhtmlTestPage; IWebElement header = driver.FindElement(By.XPath("//h1[@class='header']")); - Assert.AreEqual("XHTML Might Be The Future", header.Text); + Assert.That(header.Text, Is.EqualTo("XHTML Might Be The Future")); } [Test] @@ -416,8 +416,8 @@ public void ShouldBeAbleToFindAnElementByXPathWithMultipleAttributes() driver.Url = formsPage; IWebElement element = driver.FindElement( By.XPath("//form[@name='optional']/input[@type='submit' and @value='Click!']")); - Assert.AreEqual("input", element.TagName.ToLower()); - Assert.AreEqual("Click!", element.GetAttribute("value")); + Assert.That(element.TagName.ToLower(), Is.EqualTo("input")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("Click!")); } [Test] @@ -425,7 +425,7 @@ public void FindingALinkByXpathShouldLocateAnElementWithTheGivenText() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.XPath("//a[text()='click me']")); - Assert.AreEqual("click me", element.Text); + Assert.That(element.Text, Is.EqualTo("click me")); } [Test] @@ -558,8 +558,8 @@ public void ShouldBeAbleToFindASingleElementByCssSelector() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.CssSelector("div.content")); - Assert.AreEqual("div", element.TagName.ToLower()); - Assert.AreEqual("content", element.GetAttribute("class")); + Assert.That(element.TagName.ToLower(), Is.EqualTo("div")); + Assert.That(element.GetAttribute("class"), Is.EqualTo("content")); } [Test] @@ -575,8 +575,8 @@ public void ShouldBeAbleToFindASingleElementByCompoundCssSelector() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.CssSelector("div.extraDiv, div.content")); - Assert.AreEqual("div", element.TagName.ToLower()); - Assert.AreEqual("content", element.GetAttribute("class")); + Assert.That(element.TagName.ToLower(), Is.EqualTo("div")); + Assert.That(element.GetAttribute("class"), Is.EqualTo("content")); } [Test] @@ -594,7 +594,7 @@ public void ShouldBeAbleToFindAnElementByBooleanAttributeUsingCssSelector() { driver.Url = (EnvironmentManager.Instance.UrlBuilder.WhereIs("locators_tests/boolean_attribute_selected.html")); IWebElement element = driver.FindElement(By.CssSelector("option[selected='selected']")); - Assert.AreEqual("two", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("two")); } [Test] @@ -602,7 +602,7 @@ public void ShouldBeAbleToFindAnElementByBooleanAttributeUsingShortCssSelector() { driver.Url = (EnvironmentManager.Instance.UrlBuilder.WhereIs("locators_tests/boolean_attribute_selected.html")); IWebElement element = driver.FindElement(By.CssSelector("option[selected]")); - Assert.AreEqual("two", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("two")); } [Test] @@ -610,7 +610,7 @@ public void ShouldBeAbleToFindAnElementByBooleanAttributeUsingShortCssSelectorOn { driver.Url = (EnvironmentManager.Instance.UrlBuilder.WhereIs("locators_tests/boolean_attribute_selected_html4.html")); IWebElement element = driver.FindElement(By.CssSelector("option[selected]")); - Assert.AreEqual("two", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("two")); } // By.CssSelector negative @@ -627,7 +627,7 @@ public void ShouldNotFindElementsByCssSelectorWhenThereIsNoSuchElement() { driver.Url = xhtmlTestPage; ReadOnlyCollection elements = driver.FindElements(By.CssSelector(".there-is-no-such-class")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } [Test] @@ -665,7 +665,7 @@ public void ShouldBeAbleToFindALinkByText() { driver.Url = xhtmlTestPage; IWebElement link = driver.FindElement(By.LinkText("click me")); - Assert.AreEqual("click me", link.Text); + Assert.That(link.Text, Is.EqualTo("click me")); } [Test] @@ -673,7 +673,7 @@ public void ShouldBeAbleToFindMultipleLinksByText() { driver.Url = xhtmlTestPage; ReadOnlyCollection elements = driver.FindElements(By.LinkText("click me")); - Assert.AreEqual(2, elements.Count, "Expected 2 links, got " + elements.Count); + Assert.That(elements, Has.Count.EqualTo(2), "Expected 2 links, got " + elements.Count); } [Test] @@ -681,7 +681,7 @@ public void ShouldFindElementByLinkTextContainingEqualsSign() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.LinkText("Link=equalssign")); - Assert.AreEqual("linkWithEqualsSign", element.GetAttribute("id")); + Assert.That(element.GetAttribute("id"), Is.EqualTo("linkWithEqualsSign")); } [Test] @@ -689,8 +689,8 @@ public void ShouldFindMultipleElementsByLinkTextContainingEqualsSign() { driver.Url = xhtmlTestPage; ReadOnlyCollection elements = driver.FindElements(By.LinkText("Link=equalssign")); - Assert.AreEqual(1, elements.Count); - Assert.AreEqual("linkWithEqualsSign", elements[0].GetAttribute("id")); + Assert.That(elements, Has.Count.EqualTo(1)); + Assert.That(elements[0].GetAttribute("id"), Is.EqualTo("linkWithEqualsSign")); } [Test] @@ -705,7 +705,7 @@ public void FindsByLinkTextOnXhtmlPage() driver.Url = (EnvironmentManager.Instance.UrlBuilder.WhereIs("actualXhtmlPage.xhtml")); string linkText = "Foo"; IWebElement element = driver.FindElement(By.LinkText(linkText)); - Assert.AreEqual(linkText, element.Text); + Assert.That(element.Text, Is.EqualTo(linkText)); } [Test] @@ -716,7 +716,7 @@ public void LinkWithFormattingTags() IWebElement elem = driver.FindElement(By.Id("links")); IWebElement res = elem.FindElement(By.PartialLinkText("link with formatting tags")); - Assert.AreEqual("link with formatting tags", res.Text); + Assert.That(res.Text, Is.EqualTo("link with formatting tags")); } [Test] @@ -724,8 +724,8 @@ public void DriverCanGetLinkByLinkTestIgnoringTrailingWhitespace() { driver.Url = simpleTestPage; IWebElement link = driver.FindElement(By.LinkText("link with trailing space")); - Assert.AreEqual("linkWithTrailingSpace", link.GetAttribute("id")); - Assert.AreEqual("link with trailing space", link.Text); + Assert.That(link.GetAttribute("id"), Is.EqualTo("linkWithTrailingSpace")); + Assert.That(link.Text, Is.EqualTo("link with trailing space")); } // By.linkText negative @@ -742,7 +742,7 @@ public void ShouldNotBeAbleToLocateByLinkTextMultipleElementsThatDoNotExist() { driver.Url = xhtmlTestPage; ReadOnlyCollection elements = driver.FindElements(By.LinkText("Not here either")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } // By.partialLinkText positive @@ -752,7 +752,7 @@ public void ShouldBeAbleToFindMultipleElementsByPartialLinkText() { driver.Url = xhtmlTestPage; ReadOnlyCollection elements = driver.FindElements(By.PartialLinkText("ick me")); - Assert.AreEqual(2, elements.Count); + Assert.That(elements, Has.Exactly(2).Items); } [Test] @@ -768,7 +768,7 @@ public void ShouldFindElementByPartialLinkTextContainingEqualsSign() { driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.PartialLinkText("Link=")); - Assert.AreEqual("linkWithEqualsSign", element.GetAttribute("id")); + Assert.That(element.GetAttribute("id"), Is.EqualTo("linkWithEqualsSign")); } [Test] @@ -776,8 +776,8 @@ public void ShouldFindMultipleElementsByPartialLinkTextContainingEqualsSign() { driver.Url = xhtmlTestPage; ReadOnlyCollection elements = driver.FindElements(By.PartialLinkText("Link=")); - Assert.AreEqual(1, elements.Count); - Assert.AreEqual("linkWithEqualsSign", elements[0].GetAttribute("id")); + Assert.That(elements, Has.Count.EqualTo(1)); + Assert.That(elements[0].GetAttribute("id"), Is.EqualTo("linkWithEqualsSign")); } // Misc tests @@ -788,7 +788,7 @@ public void DriverShouldBeAbleToFindElementsAfterLoadingMoreThanOnePageAtATime() driver.Url = formsPage; driver.Url = xhtmlTestPage; IWebElement link = driver.FindElement(By.LinkText("click me")); - Assert.AreEqual("click me", link.Text); + Assert.That(link.Text, Is.EqualTo("click me")); } // You don't want to ask why this is here @@ -798,16 +798,16 @@ public void WhenFindingByNameShouldNotReturnById() driver.Url = formsPage; IWebElement element = driver.FindElement(By.Name("id-name1")); - Assert.AreEqual("name", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("name")); element = driver.FindElement(By.Id("id-name1")); - Assert.AreEqual("id", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("id")); element = driver.FindElement(By.Name("id-name2")); - Assert.AreEqual("name", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("name")); element = driver.FindElement(By.Id("id-name2")); - Assert.AreEqual("id", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("id")); } [Test] @@ -815,7 +815,7 @@ public void ShouldBeAbleToFindAHiddenElementsByName() { driver.Url = formsPage; IWebElement element = driver.FindElement(By.Name("hidden")); - Assert.AreEqual("hidden", element.GetAttribute("name")); + Assert.That(element.GetAttribute("name"), Is.EqualTo("hidden")); } [Test] @@ -851,10 +851,10 @@ public void AnElementFoundInADifferentFrameIsStale() public void ShouldReturnTitleOfPageIfSet() { driver.Url = xhtmlTestPage; - Assert.AreEqual(driver.Title, "XHTML Test Page"); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); driver.Url = simpleTestPage; - Assert.AreEqual(driver.Title, "Hello WebDriver"); + Assert.That(driver.Title, Is.EqualTo("Hello WebDriver")); } [Test] @@ -863,7 +863,7 @@ public void ShouldBeAbleToClickOnLinkIdentifiedByText() driver.Url = xhtmlTestPage; driver.FindElement(By.LinkText("click me")).Click(); WaitFor(() => { return driver.Title == "We Arrive Here"; }, "Browser title is not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -872,7 +872,7 @@ public void ShouldBeAbleToClickOnLinkIdentifiedById() driver.Url = xhtmlTestPage; driver.FindElement(By.Id("linkId")).Click(); WaitFor(() => { return driver.Title == "We Arrive Here"; }, "Browser title is not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -892,7 +892,7 @@ public void ShouldBeAbleToFindChildrenOfANode() ReadOnlyCollection elements = driver.FindElements(By.XPath("/html/head")); IWebElement head = elements[0]; ReadOnlyCollection importedScripts = head.FindElements(By.TagName("script")); - Assert.AreEqual(importedScripts.Count, 3); + Assert.That(importedScripts, Has.Exactly(3).Items); } [Test] @@ -902,7 +902,7 @@ public void ReturnAnEmptyListWhenThereAreNoChildrenOfANode() IWebElement table = driver.FindElement(By.Id("table")); ReadOnlyCollection rows = table.FindElements(By.TagName("tr")); - Assert.AreEqual(rows.Count, 0); + Assert.That(rows, Is.Empty); } [Test] @@ -912,7 +912,7 @@ public void ShouldFindElementsByName() IWebElement element = driver.FindElement(By.Name("checky")); - Assert.AreEqual(element.GetAttribute("value"), "furrfu"); + Assert.That(element.GetAttribute("value"), Is.EqualTo("furrfu")); } [Test] @@ -921,7 +921,7 @@ public void ShouldFindElementsByClassWhenItIsTheFirstNameAmongMany() driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.ClassName("nameA")); - Assert.AreEqual(element.Text, "An H2 title"); + Assert.That(element.Text, Is.EqualTo("An H2 title")); } [Test] @@ -930,7 +930,7 @@ public void ShouldFindElementsByClassWhenItIsTheLastNameAmongMany() driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.ClassName("nameC")); - Assert.AreEqual(element.Text, "An H2 title"); + Assert.That(element.Text, Is.EqualTo("An H2 title")); } [Test] @@ -939,7 +939,7 @@ public void ShouldFindElementsByClassWhenItIsInTheMiddleAmongMany() driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.ClassName("nameBnoise")); - Assert.AreEqual(element.Text, "An H2 title"); + Assert.That(element.Text, Is.EqualTo("An H2 title")); } [Test] @@ -976,7 +976,7 @@ public void ShouldBeAbleToClickOnLinksWithNoHrefAttribute() element.Click(); // if any exception is thrown, we won't get this far. Sanity check - Assert.AreEqual("Changed", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Changed")); } [Test] @@ -985,8 +985,8 @@ public void FindingByTagNameShouldNotIncludeParentElementIfSameTagType() driver.Url = xhtmlTestPage; IWebElement parent = driver.FindElement(By.Id("my_span")); - Assert.AreEqual(2, parent.FindElements(By.TagName("div")).Count); - Assert.AreEqual(2, parent.FindElements(By.TagName("span")).Count); + Assert.That(parent.FindElements(By.TagName("div")), Has.Count.EqualTo(2)); + Assert.That(parent.FindElements(By.TagName("span")), Has.Count.EqualTo(2)); } [Test] @@ -996,7 +996,7 @@ public void FindingByCssShouldNotIncludeParentElementIfSameTagType() IWebElement parent = driver.FindElement(By.CssSelector("div#parent")); IWebElement child = parent.FindElement(By.CssSelector("div")); - Assert.AreEqual("child", child.GetAttribute("id")); + Assert.That(child.GetAttribute("id"), Is.EqualTo("child")); } [Test] @@ -1005,8 +1005,8 @@ public void FindingByXPathShouldNotIncludeParentElementIfSameTagType() driver.Url = xhtmlTestPage; IWebElement parent = driver.FindElement(By.Id("my_span")); - Assert.AreEqual(2, parent.FindElements(By.TagName("div")).Count); - Assert.AreEqual(2, parent.FindElements(By.TagName("span")).Count); + Assert.That(parent.FindElements(By.TagName("div")), Has.Count.EqualTo(2)); + Assert.That(parent.FindElements(By.TagName("span")), Has.Count.EqualTo(2)); } [Test] @@ -1025,7 +1025,7 @@ public void ShouldFindElementByLinkTextContainingDoubleQuote() { driver.Url = simpleTestPage; IWebElement element = driver.FindElement(By.LinkText("link with \" (double quote)")); - Assert.AreEqual("quote", element.GetAttribute("id")); + Assert.That(element.GetAttribute("id"), Is.EqualTo("quote")); } [Test] @@ -1033,7 +1033,7 @@ public void ShouldFindElementByLinkTextContainingBackslash() { driver.Url = simpleTestPage; IWebElement element = driver.FindElement(By.LinkText("link with \\ (backslash)")); - Assert.AreEqual("backslash", element.GetAttribute("id")); + Assert.That(element.GetAttribute("id"), Is.EqualTo("backslash")); } } } diff --git a/dotnet/test/common/ElementPropertyTest.cs b/dotnet/test/common/ElementPropertyTest.cs index fd93089262c2a..2f3b98c80bfe1 100644 --- a/dotnet/test/common/ElementPropertyTest.cs +++ b/dotnet/test/common/ElementPropertyTest.cs @@ -40,9 +40,10 @@ public void CanRetrieveTheCurrentValueOfAProperty() { driver.Url = formsPage; IWebElement element = driver.FindElement(By.Id("working")); - Assert.AreEqual(string.Empty, element.GetDomProperty("value")); + + Assert.That(element.GetDomProperty("value"), Is.Empty); element.SendKeys("hello world"); - Assert.AreEqual("hello world", element.GetDomProperty("value")); + Assert.That(element.GetDomProperty("value"), Is.EqualTo("hello world")); } } } diff --git a/dotnet/test/common/ElementSelectingTest.cs b/dotnet/test/common/ElementSelectingTest.cs index 0fc8013784878..6d9bb1a7125ac 100644 --- a/dotnet/test/common/ElementSelectingTest.cs +++ b/dotnet/test/common/ElementSelectingTest.cs @@ -204,14 +204,14 @@ private static void AssertSelected(IWebElement element) private static void AssertSelected(IWebElement element, bool isSelected) { - Assert.AreEqual(isSelected, element.Selected, string.Format("Expected element {0} to be {1} but was {2}", Describe(element), SelectedToString(isSelected), SelectedToString(!isSelected))); + Assert.That(element.Selected, Is.EqualTo(isSelected), string.Format("Expected element {0} to be {1} but was {2}", Describe(element), SelectedToString(isSelected), SelectedToString(!isSelected))); } private static void AssertCannotSelect(IWebElement element) { bool previous = element.Selected; element.Click(); - Assert.AreEqual(previous, element.Selected); + Assert.That(element.Selected, Is.EqualTo(previous)); } private static void AssertCanSelect(IWebElement element) @@ -261,7 +261,7 @@ private static void AssertTogglingSwapsSelectedStateFrom(IWebElement element, bo { element.Click(); bool isNowSelected = element.Selected; - Assert.AreNotEqual(isNowSelected, originalState, string.Format("Expected element {0} to have been toggled to {1} but was {2}", Describe(element), SelectedToString(!originalState), SelectedToString(originalState))); + Assert.That(originalState, Is.Not.EqualTo(isNowSelected), string.Format("Expected element {0} to have been toggled to {1} but was {2}", Describe(element), SelectedToString(!originalState), SelectedToString(originalState))); AssertSelected(element, !originalState); } diff --git a/dotnet/test/common/ErrorsTest.cs b/dotnet/test/common/ErrorsTest.cs index f01894020c3f3..ad5ea3a120833 100644 --- a/dotnet/test/common/ErrorsTest.cs +++ b/dotnet/test/common/ErrorsTest.cs @@ -35,7 +35,7 @@ public void ShouldNotGenerateErrorsWhenOpeningANewPage() { driver.Url = errorsPage; object result = ((IJavaScriptExecutor)driver).ExecuteScript("return window.ERRORS.join('\\n');"); - Assert.AreEqual("", result, "Should have no errors"); + Assert.That(result, Is.Empty, "Should have no errors"); } } diff --git a/dotnet/test/common/ExecutingAsyncJavascriptTest.cs b/dotnet/test/common/ExecutingAsyncJavascriptTest.cs index 077bcd721c0fa..161d26c463857 100644 --- a/dotnet/test/common/ExecutingAsyncJavascriptTest.cs +++ b/dotnet/test/common/ExecutingAsyncJavascriptTest.cs @@ -236,21 +236,21 @@ public void ShouldBeAbleToExecuteAsynchronousScripts() IWebElement typer = driver.FindElement(By.Name("typer")); typer.SendKeys("bob"); - Assert.AreEqual("bob", typer.GetAttribute("value")); + Assert.That(typer.GetAttribute("value"), Is.EqualTo("bob")); driver.FindElement(By.Id("red")).Click(); driver.FindElement(By.Name("submit")).Click(); - Assert.AreEqual(1, GetNumberOfDivElements(), "There should only be 1 DIV at this point, which is used for the butter message"); + Assert.That(GetNumberOfDivElements(), Is.EqualTo(1), "There should only be 1 DIV at this point, which is used for the butter message"); driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(10); string text = (string)executor.ExecuteAsyncScript( "var callback = arguments[arguments.length - 1];" + "window.registerListener(arguments[arguments.length - 1]);"); - Assert.AreEqual("bob", text); - Assert.AreEqual("", typer.GetAttribute("value")); + Assert.That(text, Is.EqualTo("bob")); + Assert.That(typer.GetAttribute("value"), Is.Empty); - Assert.AreEqual(2, GetNumberOfDivElements(), "There should be 1 DIV (for the butter message) + 1 DIV (for the new label)"); + Assert.That(GetNumberOfDivElements(), Is.EqualTo(2), "There should be 1 DIV (for the butter message) + 1 DIV (for the new label)"); } [Test] @@ -258,7 +258,7 @@ public void ShouldBeAbleToPassMultipleArgumentsToAsyncScripts() { driver.Url = ajaxyPage; long result = (long)executor.ExecuteAsyncScript("arguments[arguments.length - 1](arguments[0] + arguments[1]);", 1, 2); - Assert.AreEqual(3, result); + Assert.That(result, Is.EqualTo(3)); } [Test] @@ -290,7 +290,7 @@ public void ShouldBeAbleToMakeXMLHttpRequestsAndWaitForTheResponse() driver.Url = ajaxyPage; driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(3); string response = (string)executor.ExecuteAsyncScript(script, sleepingPage + "?time=2"); - Assert.AreEqual("DoneSlept for 2s", response.Trim()); + Assert.That(response.Trim(), Is.EqualTo("DoneSlept for 2s")); } [Test] diff --git a/dotnet/test/common/ExecutingJavascriptTest.cs b/dotnet/test/common/ExecutingJavascriptTest.cs index 34a567a7a92c2..64e26d5aea9b4 100644 --- a/dotnet/test/common/ExecutingJavascriptTest.cs +++ b/dotnet/test/common/ExecutingJavascriptTest.cs @@ -143,7 +143,7 @@ public void ShouldBeAbleToExecuteJavascriptAndReturnABasicObjectLiteral() expected.Add("abc", "123"); expected.Add("tired", false); - Assert.AreEqual(expected.Count, map.Count, "Expected:<" + expected.Count + ">, but was:<" + map.Count + ">"); + Assert.That(map, Has.Count.EqualTo(expected.Count), "Expected:<" + expected.Count + ">, but was:<" + map.Count + ">"); foreach (string expectedKey in expected.Keys) { Assert.That(map, Does.ContainKey(expectedKey)); @@ -200,8 +200,8 @@ public void ShouldBeAbleToExecuteSimpleJavascriptAndReturnAComplexObject() Assert.That(result, Is.InstanceOf>()); Dictionary map = (Dictionary)result; - Assert.AreEqual("http:", map["protocol"]); - Assert.AreEqual(javascriptPage, map["href"]); + Assert.That(map["protocol"], Is.EqualTo("http:")); + Assert.That(map["href"], Is.EqualTo(javascriptPage)); } [Test] @@ -258,8 +258,8 @@ public void ShouldThrowAnExceptionWithMessageAndStacktraceWhenTheJavascriptIsBad + "functionA();"; Exception ex = Assert.Catch(() => ExecuteScript(js)); Assert.That(ex, Is.InstanceOf()); - Assert.That(ex.Message.Contains("errormessage"), "Exception message does not contain 'errormessage'"); - Assert.That(ex.StackTrace.Contains("functionB"), "Exception message does not contain 'functionB'"); + Assert.That(ex.Message, Does.Contain("errormessage"), "Exception message does not contain 'errormessage'"); + Assert.That(ex.StackTrace, Does.Contain("functionB"), "Exception message does not contain 'functionB'"); } [Test] @@ -272,7 +272,7 @@ public void ShouldBeAbleToCallFunctionsDefinedOnThePage() ExecuteScript("displayMessage('I like cheese');"); string text = driver.FindElement(By.Id("result")).Text; - Assert.AreEqual("I like cheese", text.Trim()); + Assert.That(text.Trim(), Is.EqualTo("I like cheese")); } [Test] @@ -284,7 +284,7 @@ public void ShouldBeAbleToPassAStringAsAnArgument() driver.Url = javascriptPage; string text = (string)ExecuteScript("return arguments[0] == 'Hello!' ? 'Hello!' : 'Goodbye!';", "Hello!"); - Assert.AreEqual("Hello!", text); + Assert.That(text, Is.EqualTo("Hello!")); } [Test] @@ -317,19 +317,19 @@ public void ShouldBeAbleToPassANumberAsAnArgument() string function = string.Format(functionTemplate, 3); long result = (long)ExecuteScript(function, 3); - Assert.AreEqual(3, result); + Assert.That(result, Is.EqualTo(3)); function = string.Format(functionTemplate, -3); result = (long)ExecuteScript(function, -3); - Assert.AreEqual(-3, result); + Assert.That(result, Is.EqualTo(-3)); function = string.Format(functionTemplate, 2147483647); result = (long)ExecuteScript(function, 2147483647); - Assert.AreEqual(2147483647, result); + Assert.That(result, Is.EqualTo(2147483647)); function = string.Format(functionTemplate, -2147483647); result = (long)ExecuteScript(function, -2147483647); - Assert.AreEqual(-2147483647, result); + Assert.That(result, Is.EqualTo(-2147483647)); } [Test] @@ -343,7 +343,7 @@ public void ShouldBeAbleToPassAWebElementAsArgument() IWebElement button = driver.FindElement(By.Id("plainButton")); string value = (string)ExecuteScript("arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble'];", button); - Assert.AreEqual("plainButton", value); + Assert.That(value, Is.EqualTo("plainButton")); } [Test] @@ -357,7 +357,7 @@ public void PassingArrayAsOnlyArgumentShouldFlattenArray() driver.Url = javascriptPage; object[] array = new object[] { "zero", 1, true, 3.14159 }; long length = (long)ExecuteScript("return arguments[0].length", array); - Assert.AreEqual(array.Length, length); + Assert.That(length, Is.EqualTo(array.Length)); } [Test] @@ -371,7 +371,7 @@ public void ShouldBeAbleToPassAnArrayAsAdditionalArgument() driver.Url = javascriptPage; object[] array = new object[] { "zero", 1, true, 3.14159, false }; long length = (long)ExecuteScript("return arguments[1].length", "string", array); - Assert.AreEqual(array.Length, length); + Assert.That(length, Is.EqualTo(array.Length)); } [Test] @@ -388,7 +388,7 @@ public void ShouldBeAbleToPassACollectionAsArgument() collection.Add("Brie"); collection.Add(7); long length = (long)ExecuteScript("return arguments[0].length", collection); - Assert.AreEqual(collection.Count, length); + Assert.That(length, Is.EqualTo(collection.Count)); } [Test] @@ -415,7 +415,7 @@ public void ShouldBeAbleToPassInMoreThanOneArgument() driver.Url = javascriptPage; string result = (string)ExecuteScript("return arguments[0] + arguments[1];", "one", "two"); - Assert.AreEqual("onetwo", result); + Assert.That(result, Is.EqualTo("onetwo")); } [Test] @@ -426,7 +426,7 @@ public void ShouldBeAbleToGrabTheBodyOfFrameOnceSwitchedTo() driver.SwitchTo().Frame("editFrame"); IWebElement body = (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript("return document.body"); - Assert.AreEqual("", body.Text); + Assert.That(body.Text, Is.Empty); } // This is a duplicate test of ShouldBeAbleToExecuteScriptAndReturnElementsList. @@ -449,13 +449,13 @@ public void JavascriptStringHandlingShouldWorkAsExpected() driver.Url = javascriptPage; string value = (string)ExecuteScript("return '';"); - Assert.AreEqual("", value); + Assert.That(value, Is.Empty); value = (string)ExecuteScript("return undefined;"); Assert.That(value, Is.Null); value = (string)ExecuteScript("return ' '"); - Assert.AreEqual(" ", value); + Assert.That(value, Is.EqualTo(" ")); } [Test] @@ -508,7 +508,7 @@ public void ShouldBeAbleToExecuteScriptAndReturnElementsList() ReadOnlyCollection resultsList = (ReadOnlyCollection)resultObject; - Assert.That(resultsList.Count, Is.GreaterThan(0)); + Assert.That(resultsList, Is.Not.Empty); } [Test] @@ -520,7 +520,7 @@ public void ShouldBeAbleToCreateAPersistentValue() ExecuteScript("document.alerts.push('hello world');"); string text = (string)ExecuteScript("return document.alerts.shift()"); - Assert.AreEqual("hello world", text); + Assert.That(text, Is.EqualTo("hello world")); } [Test] @@ -533,7 +533,7 @@ public void ShouldBeAbleToHandleAnArrayOfElementsAsAnObjectArray() string name = (string)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0][0].tagName", args); - Assert.AreEqual("form", name.ToLower()); + Assert.That(name, Is.EqualTo("form").IgnoreCase); } [Test] @@ -548,7 +548,7 @@ public void ShouldBeAbleToPassADictionaryAsAParameter() object res = ((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0]['foo'][1]", args); - Assert.AreEqual(2, (long)res); + Assert.That((long)res, Is.EqualTo(2)); } [Test] @@ -713,7 +713,7 @@ public void ShouldBeAbleToPassMoreThanOneStringAsArguments() driver.Url = javascriptPage; string text = (string)ExecuteScript("return arguments[0] + arguments[1] + arguments[2] + arguments[3];", "Hello,", " ", "world", "!"); - Assert.AreEqual("Hello, world!", text); + Assert.That(text, Is.EqualTo("Hello, world!")); } [Test] @@ -728,16 +728,16 @@ public void ShouldBeAbleToPassMoreThanOneBooleanAsArguments() driver.Url = javascriptPage; string text = (string)ExecuteScript(function, true, true); - Assert.AreEqual("TrueTrue", text); + Assert.That(text, Is.EqualTo("TrueTrue")); text = (string)ExecuteScript(function, false, true); - Assert.AreEqual("FalseTrue", text); + Assert.That(text, Is.EqualTo("FalseTrue")); text = (string)ExecuteScript(function, true, false); - Assert.AreEqual("TrueFalse", text); + Assert.That(text, Is.EqualTo("TrueFalse")); text = (string)ExecuteScript(function, false, false); - Assert.AreEqual("FalseFalse", text); + Assert.That(text, Is.EqualTo("FalseFalse")); } [Test] @@ -751,16 +751,16 @@ public void ShouldBeAbleToPassMoreThanOneNumberAsArguments() driver.Url = javascriptPage; long result = (long)ExecuteScript(function, 30, 12); - Assert.AreEqual(42, result); + Assert.That(result, Is.EqualTo(42)); result = (long)ExecuteScript(function, -30, -12); - Assert.AreEqual(-42, result); + Assert.That(result, Is.EqualTo(-42)); result = (long)ExecuteScript(function, 2147483646, 1); - Assert.AreEqual(2147483647, result); + Assert.That(result, Is.EqualTo(2147483647)); result = (long)ExecuteScript(function, -2147483646, -1); - Assert.AreEqual(-2147483647, result); + Assert.That(result, Is.EqualTo(-2147483647)); } @@ -775,22 +775,22 @@ public void ShouldBeAbleToPassADoubleAsAnArgument() driver.Url = javascriptPage; double result = (double)ExecuteScript(function, (double)4.2); - Assert.AreEqual(4.2, result); + Assert.That(result, Is.EqualTo(4.2)); result = (double)ExecuteScript(function, (double)-4.2); - Assert.AreEqual(-4.2, result); + Assert.That(result, Is.EqualTo(-4.2)); result = (double)ExecuteScript(function, (float)4.2); - Assert.AreEqual(4.2, result); + Assert.That(result, Is.EqualTo(4.2)); result = (double)ExecuteScript(function, (float)-4.2); - Assert.AreEqual(-4.2, result); + Assert.That(result, Is.EqualTo(-4.2)); result = (long)ExecuteScript(function, (double)4.0); - Assert.AreEqual(4, result); + Assert.That(result, Is.EqualTo(4)); result = (long)ExecuteScript(function, (double)-4.0); - Assert.AreEqual(-4, result); + Assert.That(result, Is.EqualTo(-4)); } [Test] @@ -804,16 +804,16 @@ public void ShouldBeAbleToPassMoreThanOneDoubleAsArguments() driver.Url = javascriptPage; double result = (double)ExecuteScript(function, 30.1, 12.1); - Assert.AreEqual(42.2, result); + Assert.That(result, Is.EqualTo(42.2)); result = (double)ExecuteScript(function, -30.1, -12.1); - Assert.AreEqual(-42.2, result); + Assert.That(result, Is.EqualTo(-42.2)); result = (double)ExecuteScript(function, 2147483646.1, 1.0); - Assert.AreEqual(2147483647.1, result); + Assert.That(result, Is.EqualTo(2147483647.1)); result = (double)ExecuteScript(function, -2147483646.1, -1.0); - Assert.AreEqual(-2147483647.1, result); + Assert.That(result, Is.EqualTo(-2147483647.1)); } @@ -828,7 +828,7 @@ public void ShouldBeAbleToPassMoreThanOneWebElementAsArguments() IWebElement dynamo = driver.FindElement(By.Id("dynamo")); string value = (string)ExecuteScript("arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble'] + arguments[1].innerHTML;", button, dynamo); - Assert.AreEqual("plainButtonWhat's for dinner?", value); + Assert.That(value, Is.EqualTo("plainButtonWhat's for dinner?")); } [Test] @@ -847,7 +847,7 @@ public void ShouldBeAbleToPassInMixedArguments() "Hello, World!", true); - Assert.AreEqual("What's for dinner?424.2Hello, World!true", result); + Assert.That(result, Is.EqualTo("What's for dinner?424.2Hello, World!true")); } @@ -864,7 +864,7 @@ public void ShouldBeAbleToPassInAndRetrieveDates() ExecuteScript(function, "2014-05-20T20:00:00+08:00"); IWebElement element = driver.FindElement(By.Id("result")); string text = element.Text; - Assert.AreEqual("2014-05-20T20:00:00+08:00", text); + Assert.That(text, Is.EqualTo("2014-05-20T20:00:00+08:00")); } private object ExecuteScript(String script, params Object[] args) diff --git a/dotnet/test/common/FormHandlingTests.cs b/dotnet/test/common/FormHandlingTests.cs index 736b77a610f25..47382b7ebf8e1 100644 --- a/dotnet/test/common/FormHandlingTests.cs +++ b/dotnet/test/common/FormHandlingTests.cs @@ -32,7 +32,7 @@ public void ShouldClickOnSubmitInputElements() driver.Url = formsPage; driver.FindElement(By.Id("submitButton")).Click(); WaitFor(TitleToBe("We Arrive Here"), "Browser title is not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -48,7 +48,7 @@ public void ShouldBeAbleToClickImageButtons() driver.Url = formsPage; driver.FindElement(By.Id("imageButton")).Click(); WaitFor(TitleToBe("We Arrive Here"), "Browser title is not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -57,7 +57,7 @@ public void ShouldBeAbleToSubmitForms() driver.Url = formsPage; driver.FindElement(By.Name("login")).Submit(); WaitFor(TitleToBe("We Arrive Here"), "Browser title is not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -66,7 +66,7 @@ public void ShouldSubmitAFormWhenAnyInputElementWithinThatFormIsSubmitted() driver.Url = formsPage; driver.FindElement(By.Id("checky")).Submit(); WaitFor(TitleToBe("We Arrive Here"), "Browser title is not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -75,7 +75,7 @@ public void ShouldSubmitAFormWhenAnyElementWithinThatFormIsSubmitted() driver.Url = formsPage; driver.FindElement(By.XPath("//form/p")).Submit(); WaitFor(TitleToBe("We Arrive Here"), "Browser title is not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -84,7 +84,7 @@ public void ShouldSubmitAFormWithIdSubmit() driver.Url = formsPage; driver.FindElement(By.Id("submit")).Submit(); WaitFor(TitleToBe("We Arrive Here"), "Browser title is not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -94,7 +94,7 @@ public void ShouldSubmitAFormWithNameSubmit() driver.Url = formsPage; driver.FindElement(By.Name("submit")).Submit(); WaitFor(TitleToBe("We Arrive Here"), "Browser title is not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -111,7 +111,7 @@ public void ShouldBeAbleToEnterTextIntoATextAreaBySettingItsValue() IWebElement textarea = driver.FindElement(By.Id("keyUpArea")); string cheesey = "Brie and cheddar"; textarea.SendKeys(cheesey); - Assert.AreEqual(textarea.GetAttribute("value"), cheesey); + Assert.That(textarea.GetAttribute("value"), Is.EqualTo(cheesey)); } [Test] @@ -121,7 +121,7 @@ public void SendKeysKeepsCapitalization() IWebElement textarea = driver.FindElement(By.Id("keyUpArea")); string cheesey = "BrIe And CheDdar"; textarea.SendKeys(cheesey); - Assert.AreEqual(textarea.GetAttribute("value"), cheesey); + Assert.That(textarea.GetAttribute("value"), Is.EqualTo(cheesey)); } [Test] @@ -134,7 +134,7 @@ public void ShouldSubmitAFormUsingTheNewlineLiteral() input.SendKeys("\n"); WaitFor(TitleToBe("We Arrive Here"), "Browser title is not 'We Arrive Here'"); - Assert.AreEqual("We Arrive Here", driver.Title); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); Assert.That(driver.Url, Does.EndWith("?x=name")); } @@ -147,7 +147,7 @@ public void ShouldSubmitAFormUsingTheEnterKey() input.SendKeys(Keys.Enter); WaitFor(TitleToBe("We Arrive Here"), "Browser title is not 'We Arrive Here'"); - Assert.AreEqual("We Arrive Here", driver.Title); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); Assert.That(driver.Url, Does.EndWith("?x=name")); } @@ -157,14 +157,14 @@ public void ShouldEnterDataIntoFormFields() driver.Url = xhtmlTestPage; IWebElement element = driver.FindElement(By.XPath("//form[@name='someForm']/input[@id='username']")); String originalValue = element.GetAttribute("value"); - Assert.AreEqual(originalValue, "change"); + Assert.That(originalValue, Is.EqualTo("change")); element.Clear(); element.SendKeys("some text"); element = driver.FindElement(By.XPath("//form[@name='someForm']/input[@id='username']")); String newFormValue = element.GetAttribute("value"); - Assert.AreEqual(newFormValue, "some text"); + Assert.That(newFormValue, Is.EqualTo("some text")); } [Test] @@ -173,7 +173,7 @@ public void ShouldBeAbleToAlterTheContentsOfAFileUploadInputElement() string testFileName = string.Format("test-{0}.txt", Guid.NewGuid().ToString("D")); driver.Url = formsPage; IWebElement uploadElement = driver.FindElement(By.Id("upload")); - Assert.That(uploadElement.GetAttribute("value"), Is.Null.Or.EqualTo(string.Empty)); + Assert.That(uploadElement.GetAttribute("value"), Is.Null.Or.Empty); string filePath = System.IO.Path.Combine(EnvironmentManager.Instance.CurrentDirectory, testFileName); System.IO.FileInfo inputFile = new System.IO.FileInfo(filePath); @@ -201,7 +201,7 @@ public void ShouldBeAbleToSendKeysToAFileUploadInputElementInAnXhtmlDocument() driver.Url = xhtmlFormPage; IWebElement uploadElement = driver.FindElement(By.Id("file")); - Assert.AreEqual(string.Empty, uploadElement.GetAttribute("value")); + Assert.That(uploadElement.GetAttribute("value"), Is.Empty); string testFileName = string.Format("test-{0}.txt", Guid.NewGuid().ToString("D")); string filePath = System.IO.Path.Combine(EnvironmentManager.Instance.CurrentDirectory, testFileName); @@ -214,7 +214,7 @@ public void ShouldBeAbleToSendKeysToAFileUploadInputElementInAnXhtmlDocument() string uploadElementValue = uploadElement.GetAttribute("value"); System.IO.FileInfo outputFile = new System.IO.FileInfo(uploadElementValue.Replace('\\', System.IO.Path.DirectorySeparatorChar)); - Assert.AreEqual(inputFile.Name, outputFile.Name); + Assert.That(outputFile.Name, Is.EqualTo(inputFile.Name)); inputFile.Delete(); } @@ -253,11 +253,11 @@ public void SendingKeyboardEventsShouldAppendTextInInputs() IWebElement element = driver.FindElement(By.Id("working")); element.SendKeys("Some"); String value = element.GetAttribute("value"); - Assert.AreEqual(value, "Some"); + Assert.That(value, Is.EqualTo("Some")); element.SendKeys(" text"); value = element.GetAttribute("value"); - Assert.AreEqual(value, "Some text"); + Assert.That(value, Is.EqualTo("Some text")); } [Test] @@ -268,7 +268,7 @@ public void SendingKeyboardEventsShouldAppendTextInInputsWithExistingValue() element.SendKeys(". Some text"); string value = element.GetAttribute("value"); - Assert.AreEqual("Example text. Some text", value); + Assert.That(value, Is.EqualTo("Example text. Some text")); } [Test] @@ -280,7 +280,7 @@ public void SendingKeyboardEventsShouldAppendTextInTextAreas() element.SendKeys(". Some text"); String value = element.GetAttribute("value"); - Assert.AreEqual(value, "Example text. Some text"); + Assert.That(value, Is.EqualTo("Example text. Some text")); } [Test] @@ -288,10 +288,10 @@ public void EmptyTextBoxesShouldReturnAnEmptyStringNotNull() { driver.Url = formsPage; IWebElement emptyTextBox = driver.FindElement(By.Id("working")); - Assert.AreEqual(emptyTextBox.GetAttribute("value"), ""); + Assert.That(emptyTextBox.GetAttribute("value"), Is.Empty); IWebElement emptyTextArea = driver.FindElement(By.Id("emptyTextArea")); - Assert.AreEqual(emptyTextBox.GetAttribute("value"), ""); + Assert.That(emptyTextBox.GetAttribute("value"), Is.Empty); } [Test] @@ -316,7 +316,7 @@ public void HandleFormWithJavascriptAction() string text = alert.Text; alert.Dismiss(); - Assert.AreEqual("Tasty cheese", text); + Assert.That(text, Is.EqualTo("Tasty cheese")); } [Test] @@ -391,12 +391,12 @@ public void ShouldBeAbleToClearTextFromInputElements() IWebElement element = driver.FindElement(By.Id("working")); element.SendKeys("Some text"); String value = element.GetAttribute("value"); - Assert.That(value.Length, Is.GreaterThan(0)); + Assert.That(value, Is.Not.Empty); element.Clear(); value = element.GetAttribute("value"); - Assert.That(value.Length, Is.EqualTo(0)); + Assert.That(value, Is.Empty); } [Test] @@ -406,12 +406,12 @@ public void ShouldBeAbleToClearTextFromTextAreas() IWebElement element = driver.FindElement(By.Id("withText")); element.SendKeys("Some text"); String value = element.GetAttribute("value"); - Assert.That(value.Length, Is.GreaterThan(0)); + Assert.That(value, Is.Not.Empty); element.Clear(); value = element.GetAttribute("value"); - Assert.That(value.Length, Is.EqualTo(0)); + Assert.That(value, Is.Empty); } private void CheckSubmitButton(string buttonId) @@ -424,7 +424,7 @@ private void CheckSubmitButton(string buttonId) WaitFor(TitleToBe("Submitted Successfully!"), "Browser title is not 'Submitted Successfully!'"); - Assert.That(driver.Url.Contains("name=" + name), "URL does not contain 'name=" + name + "'. Actual URL:" + driver.Url); + Assert.That(driver.Url, Does.Contain("name=" + name), "URL does not contain 'name=" + name + "'. Actual URL:" + driver.Url); } private Func TitleToBe(string desiredTitle) diff --git a/dotnet/test/common/FrameSwitchingTest.cs b/dotnet/test/common/FrameSwitchingTest.cs index a5e9777e2f48a..cd23b0c0bbbed 100644 --- a/dotnet/test/common/FrameSwitchingTest.cs +++ b/dotnet/test/common/FrameSwitchingTest.cs @@ -84,7 +84,7 @@ public void ShouldBeAbleToSwitchToAFrameByItsIndex() driver.Url = framesetPage; driver.SwitchTo().Frame(1); - Assert.AreEqual("2", driver.FindElement(By.Id("pageNumber")).Text); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("2")); } [Test] @@ -93,7 +93,7 @@ public void ShouldBeAbleToSwitchToAnIframeByItsIndex() driver.Url = iframePage; driver.SwitchTo().Frame(0); - Assert.AreEqual("name", driver.FindElement(By.Name("id-name1")).GetAttribute("value")); + Assert.That(driver.FindElement(By.Name("id-name1")).GetAttribute("value"), Is.EqualTo("name")); } [Test] @@ -101,7 +101,7 @@ public void ShouldBeAbleToSwitchToAFrameByItsName() { driver.Url = framesetPage; driver.SwitchTo().Frame("fourth"); - Assert.AreEqual("child1", driver.FindElement(By.TagName("frame")).GetAttribute("name")); + Assert.That(driver.FindElement(By.TagName("frame")).GetAttribute("name"), Is.EqualTo("child1")); } @@ -110,7 +110,7 @@ public void ShouldBeAbleToSwitchToAnIframeByItsName() { driver.Url = iframePage; driver.SwitchTo().Frame("iframe1-name"); - Assert.AreEqual("name", driver.FindElement(By.Name("id-name1")).GetAttribute("value")); + Assert.That(driver.FindElement(By.Name("id-name1")).GetAttribute("value"), Is.EqualTo("name")); } @@ -119,7 +119,7 @@ public void ShouldBeAbleToSwitchToAFrameByItsID() { driver.Url = framesetPage; driver.SwitchTo().Frame("fifth"); - Assert.AreEqual("Open new window", driver.FindElement(By.Name("windowOne")).Text); + Assert.That(driver.FindElement(By.Name("windowOne")).Text, Is.EqualTo("Open new window")); } @@ -128,7 +128,7 @@ public void ShouldBeAbleToSwitchToAnIframeByItsID() { driver.Url = iframePage; driver.SwitchTo().Frame("iframe1"); - Assert.AreEqual("name", driver.FindElement(By.Name("id-name1")).GetAttribute("value")); + Assert.That(driver.FindElement(By.Name("id-name1")).GetAttribute("value"), Is.EqualTo("name")); } [Test] @@ -145,7 +145,7 @@ public void ShouldBeAbleToSwitchToAFrameUsingAPreviouslyLocatedWebElement() driver.Url = framesetPage; IWebElement frame = driver.FindElement(By.TagName("frame")); driver.SwitchTo().Frame(frame); - Assert.AreEqual("1", driver.FindElement(By.Id("pageNumber")).Text); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("1")); } [Test] @@ -154,7 +154,7 @@ public void ShouldBeAbleToSwitchToAnIFrameUsingAPreviouslyLocatedWebElement() driver.Url = iframePage; IWebElement frame = driver.FindElement(By.TagName("iframe")); driver.SwitchTo().Frame(frame); - Assert.AreEqual("name", driver.FindElement(By.Name("id-name1")).GetAttribute("value")); + Assert.That(driver.FindElement(By.Name("id-name1")).GetAttribute("value"), Is.EqualTo("name")); } @@ -173,7 +173,7 @@ public void FrameSearchesShouldBeRelativeToTheCurrentlySelectedFrame() IWebElement frameElement = WaitFor(() => driver.FindElement(By.Name("second")), "did not find frame"); driver.SwitchTo().Frame(frameElement); - Assert.AreEqual("2", driver.FindElement(By.Id("pageNumber")).Text); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("2")); Assert.That( () => driver.SwitchTo().Frame("third"), @@ -188,7 +188,7 @@ public void FrameSearchesShouldBeRelativeToTheCurrentlySelectedFrame() driver.SwitchTo().DefaultContent(); driver.SwitchTo().Frame("second"); - Assert.AreEqual("2", driver.FindElement(By.Id("pageNumber")).Text); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("2")); } [Test] @@ -196,7 +196,7 @@ public void ShouldSelectChildFramesByChainedCalls() { driver.Url = framesetPage; driver.SwitchTo().Frame("fourth").SwitchTo().Frame("child2"); - Assert.AreEqual("11", driver.FindElement(By.Id("pageNumber")).Text); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("11")); } [Test] @@ -235,7 +235,7 @@ public void ShouldBeAbleToSwitchToParentFrame() { driver.Url = framesetPage; driver.SwitchTo().Frame("fourth").SwitchTo().ParentFrame().SwitchTo().Frame("first"); - Assert.AreEqual("1", driver.FindElement(By.Id("pageNumber")).Text); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("1")); } [Test] @@ -244,7 +244,7 @@ public void ShouldBeAbleToSwitchToParentFrameFromASecondLevelFrame() driver.Url = framesetPage; driver.SwitchTo().Frame("fourth").SwitchTo().Frame("child1").SwitchTo().ParentFrame().SwitchTo().Frame("child2"); - Assert.AreEqual("11", driver.FindElement(By.Id("pageNumber")).Text); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("11")); } [Test] @@ -252,7 +252,7 @@ public void SwitchingToParentFrameFromDefaultContextIsNoOp() { driver.Url = xhtmlTestPage; driver.SwitchTo().ParentFrame(); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -291,7 +291,7 @@ public void ShouldFocusOnTheReplacementWhenAFrameFollowsALinkToA_TopTargettedPag driver.FindElement(By.LinkText("top")).Click(); WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -314,7 +314,7 @@ public void ShouldAllowTheUserToSwitchToAnIFrameAndRemainFocusedOnIt() driver.FindElement(By.Id("submitButton")).Click(); string hello = GetTextOfGreetingElement(); - Assert.AreEqual(hello, "Success!"); + Assert.That(hello, Is.EqualTo("Success!")); } [Test] @@ -327,11 +327,11 @@ public void ShouldBeAbleToClickInAFrame() driver.FindElement(By.Id("submitButton")).Click(); // driver should still be focused on frame "third" ... - Assert.AreEqual("Success!", GetTextOfGreetingElement()); + Assert.That(GetTextOfGreetingElement(), Is.EqualTo("Success!")); // Make sure it was really frame "third" which was replaced ... driver.SwitchTo().DefaultContent().SwitchTo().Frame("third"); - Assert.AreEqual("Success!", GetTextOfGreetingElement()); + Assert.That(GetTextOfGreetingElement(), Is.EqualTo("Success!")); } [Test] @@ -354,11 +354,11 @@ public void ShouldBeAbleToClickInASubFrame() driver.FindElement(By.Id("submitButton")).Click(); // driver should still be focused on frame "iframe1" inside frame "sixth" ... - Assert.AreEqual("Success!", GetTextOfGreetingElement()); + Assert.That(GetTextOfGreetingElement(), Is.EqualTo("Success!")); // Make sure it was really frame "iframe1" inside frame "sixth" which was replaced ... driver.SwitchTo().DefaultContent().SwitchTo().Frame("sixth").SwitchTo().Frame("iframe1"); - Assert.AreEqual("Success!", driver.FindElement(By.Id("greeting")).Text); + Assert.That(driver.FindElement(By.Id("greeting")).Text, Is.EqualTo("Success!")); } [Test] @@ -377,21 +377,21 @@ public void ShouldBeAbleToFindElementsInIframesByXPath() public void GetCurrentUrlShouldReturnTopLevelBrowsingContextUrl() { driver.Url = framesetPage; - Assert.AreEqual(framesetPage, driver.Url); + Assert.That(driver.Url, Is.EqualTo(framesetPage)); driver.SwitchTo().Frame("second"); - Assert.AreEqual(framesetPage, driver.Url); + Assert.That(driver.Url, Is.EqualTo(framesetPage)); } [Test] public void GetCurrentUrlShouldReturnTopLevelBrowsingContextUrlForIframes() { driver.Url = iframePage; - Assert.AreEqual(iframePage, driver.Url); + Assert.That(driver.Url, Is.EqualTo(iframePage)); driver.SwitchTo().Frame("iframe1"); - Assert.AreEqual(iframePage, driver.Url); + Assert.That(driver.Url, Is.EqualTo(iframePage)); } [Test] @@ -476,7 +476,7 @@ public void ShouldReturnWindowTitleInAFrameset() { driver.Url = framesetPage; driver.SwitchTo().Frame("third"); - Assert.AreEqual("Unique title", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Unique title")); } [Test] @@ -518,7 +518,7 @@ public void ShouldNotSwitchMagicallyToTheTopWindow() { url = url.Substring(0, url.Length - 1); } - Assert.AreEqual(baseUrl + "bug4876_iframe.html", url); + Assert.That(url, Is.EqualTo(baseUrl + "bug4876_iframe.html")); } } } @@ -557,13 +557,13 @@ public void ShouldBeAbleToSelectAFrameByName() driver.Url = framesetPage; driver.SwitchTo().Frame("second"); - Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "2"); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("2")); driver.SwitchTo().DefaultContent().SwitchTo().Frame("third"); driver.FindElement(By.Id("changeme")).Click(); driver.SwitchTo().DefaultContent().SwitchTo().Frame("second"); - Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "2"); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("2")); } [Test] diff --git a/dotnet/test/common/GetLogsTest.cs b/dotnet/test/common/GetLogsTest.cs index 59e28ba091aa3..79524819f2e7e 100644 --- a/dotnet/test/common/GetLogsTest.cs +++ b/dotnet/test/common/GetLogsTest.cs @@ -89,7 +89,7 @@ public void TurningOffLogShouldMeanNoLogMessages() { CreateWebDriverWithLogging(logType, LogLevel.Off); ReadOnlyCollection entries = localDriver.Manage().Logs.GetLog(logType); - Assert.AreEqual(0, entries.Count, string.Format("There should be no log entries for log type {0} when logging is turned off.", logType)); + Assert.That(entries, Is.Empty, string.Format("There should be no log entries for log type {0} when logging is turned off.", logType)); QuitDriver(); } } diff --git a/dotnet/test/common/GetMultipleAttributeTest.cs b/dotnet/test/common/GetMultipleAttributeTest.cs index 48e441b50d4e5..26cf57d4813c1 100644 --- a/dotnet/test/common/GetMultipleAttributeTest.cs +++ b/dotnet/test/common/GetMultipleAttributeTest.cs @@ -37,7 +37,7 @@ public void MultipleAttributeShouldBeTrueWhenSet() { driver.Url = selectPage; IWebElement element = driver.FindElement(By.Id("selectWithMultipleEqualsMultiple")); - Assert.AreEqual("true", element.GetAttribute("multiple")); + Assert.That(element.GetAttribute("multiple"), Is.EqualTo("true")); } [Test] @@ -45,7 +45,7 @@ public void MultipleAttributeShouldBeTrueWhenSelectHasMutilpeWithValueAsBlank() { driver.Url = selectPage; IWebElement element = driver.FindElement(By.Id("selectWithEmptyStringMultiple")); - Assert.AreEqual("true", element.GetAttribute("multiple")); + Assert.That(element.GetAttribute("multiple"), Is.EqualTo("true")); } [Test] @@ -53,7 +53,7 @@ public void MultipleAttributeShouldBeTrueWhenSelectHasMutilpeWithoutAValue() { driver.Url = selectPage; IWebElement element = driver.FindElement(By.Id("selectWithMultipleWithoutValue")); - Assert.AreEqual("true", element.GetAttribute("multiple")); + Assert.That(element.GetAttribute("multiple"), Is.EqualTo("true")); } [Test] @@ -61,7 +61,7 @@ public void MultipleAttributeShouldBeTrueWhenSelectHasMutilpeWithValueAsSomethin { driver.Url = selectPage; IWebElement element = driver.FindElement(By.Id("selectWithRandomMultipleValue")); - Assert.AreEqual("true", element.GetAttribute("multiple")); + Assert.That(element.GetAttribute("multiple"), Is.EqualTo("true")); } } } diff --git a/dotnet/test/common/I18Test.cs b/dotnet/test/common/I18Test.cs index 9c115b89b6dd9..eeed6e357e5c8 100644 --- a/dotnet/test/common/I18Test.cs +++ b/dotnet/test/common/I18Test.cs @@ -49,7 +49,7 @@ public void ShouldBeAbleToEnterHebrewTextFromLeftToRight() input.SendKeys(shalom); - Assert.AreEqual(shalom, input.GetAttribute("value")); + Assert.That(input.GetAttribute("value"), Is.EqualTo(shalom)); } [Test] @@ -60,7 +60,7 @@ public void ShouldBeAbleToEnterHebrewTextFromRightToLeft() input.SendKeys(tmunot); - Assert.AreEqual(tmunot, input.GetAttribute("value")); + Assert.That(input.GetAttribute("value"), Is.EqualTo(tmunot)); } [Test] @@ -86,7 +86,7 @@ public void ShouldBeAbleToEnterSupplementaryCharacters() IWebElement el = driver.FindElement(By.Name("i18n")); el.SendKeys(input); - Assert.AreEqual(input, el.GetAttribute("value")); + Assert.That(el.GetAttribute("value"), Is.EqualTo(input)); } [Test] @@ -98,7 +98,7 @@ public void ShouldBeAbleToReturnTheTextInAPage() string text = driver.FindElement(By.TagName("body")).Text; - Assert.AreEqual(shalom, text); + Assert.That(text, Is.EqualTo(shalom)); } } } diff --git a/dotnet/test/common/ImplicitWaitTest.cs b/dotnet/test/common/ImplicitWaitTest.cs index fc55cb7fbd153..4c6f6592abd54 100644 --- a/dotnet/test/common/ImplicitWaitTest.cs +++ b/dotnet/test/common/ImplicitWaitTest.cs @@ -86,7 +86,7 @@ public void ShouldStillFailToFindElementsWhenImplicitWaitsAreEnabled() driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500); ReadOnlyCollection elements = driver.FindElements(By.ClassName("redbox")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } [Test] @@ -99,7 +99,7 @@ public void ShouldReturnAfterFirstAttemptToFindManyAfterDisablingImplicitWaits() driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(0); add.Click(); ReadOnlyCollection elements = driver.FindElements(By.ClassName("redbox")); - Assert.AreEqual(0, elements.Count); + Assert.That(elements, Is.Empty); } [Test] diff --git a/dotnet/test/common/Interactions/ActionBuilderTest.cs b/dotnet/test/common/Interactions/ActionBuilderTest.cs index a762bc92639d2..fadf473ee7202 100644 --- a/dotnet/test/common/Interactions/ActionBuilderTest.cs +++ b/dotnet/test/common/Interactions/ActionBuilderTest.cs @@ -52,9 +52,9 @@ public void OutputsPointerEventsToDictionary() var dictionary = sequence[0].ToDictionary(); Console.WriteLine(dictionary); - Assert.AreEqual("pointer", dictionary["type"]); - Assert.NotNull(dictionary["id"]); - Assert.NotNull(dictionary["parameters"]); + Assert.That(dictionary, Does.ContainKey("type").WithValue("pointer")); + Assert.That(dictionary["id"], Is.Not.Null); + Assert.That(dictionary["parameters"], Is.Not.Null); var parameters = new Dictionary { { "pointerType", "pen" } }; CollectionAssert.AreEquivalent(parameters, (IEnumerable)dictionary["parameters"]); diff --git a/dotnet/test/common/Interactions/BasicKeyboardInterfaceTest.cs b/dotnet/test/common/Interactions/BasicKeyboardInterfaceTest.cs index 88f148ca1cf3d..88c235a5a19b8 100644 --- a/dotnet/test/common/Interactions/BasicKeyboardInterfaceTest.cs +++ b/dotnet/test/common/Interactions/BasicKeyboardInterfaceTest.cs @@ -58,7 +58,7 @@ public void ShouldSetActiveKeyboard() KeyInputDevice device = actionProvider.GetActiveKeyboard(); - Assert.AreEqual("test keyboard", device.DeviceName); + Assert.That(device.DeviceName, Is.EqualTo("test keyboard")); } [Test] @@ -77,7 +77,7 @@ public void ShouldAllowBasicKeyboardInput() sendLowercase.Perform(); - Assert.AreEqual("abc def", keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.EqualTo("abc def")); } @@ -154,7 +154,7 @@ public void ShouldAllowSendingKeysWithShiftPressed() AssertThatFormEventsFiredAreExactly("focus keydown keydown keypress keyup keydown keypress keyup keyup"); - Assert.AreEqual("AB", keysEventInput.GetAttribute("value")); + Assert.That(keysEventInput.GetAttribute("value"), Is.EqualTo("AB")); } [Test] @@ -333,12 +333,12 @@ public void ShouldAllowSendingKeysWithLeftShiftPressed() AssertThatFormEventsFiredAreExactly("focus keydown keydown keypress keyup keydown keypress keyup keyup"); - Assert.AreEqual("AB", keysEventInput.GetAttribute("value")); + Assert.That(keysEventInput.GetAttribute("value"), Is.EqualTo("AB")); } private void AssertThatFormEventsFiredAreExactly(string message, string expected) { - Assert.AreEqual(expected, driver.FindElement(By.Id("result")).Text.Trim(), message); + Assert.That(driver.FindElement(By.Id("result")).Text.Trim(), Is.EqualTo(expected), message); } private void AssertThatFormEventsFiredAreExactly(string expected) @@ -348,7 +348,7 @@ private void AssertThatFormEventsFiredAreExactly(string expected) private void AssertThatBodyEventsFiredAreExactly(string expected) { - Assert.AreEqual(expected, driver.FindElement(By.Id("body_result")).Text.Trim()); + Assert.That(driver.FindElement(By.Id("body_result")).Text.Trim(), Is.EqualTo(expected)); } private Func BackgroundColorToChangeFrom(IWebElement element, Color currentColor) diff --git a/dotnet/test/common/Interactions/BasicMouseInterfaceTest.cs b/dotnet/test/common/Interactions/BasicMouseInterfaceTest.cs index f88252cc4d1a9..41ffa4812164f 100644 --- a/dotnet/test/common/Interactions/BasicMouseInterfaceTest.cs +++ b/dotnet/test/common/Interactions/BasicMouseInterfaceTest.cs @@ -45,7 +45,7 @@ public void ShouldSetActivePointer() PointerInputDevice device = actionProvider.GetActivePointer(); - Assert.AreEqual("test mouse", device.DeviceName); + Assert.That(device.DeviceName, Is.EqualTo("test mouse")); } [Test] @@ -53,7 +53,7 @@ public void ShouldAllowDraggingElementWithMouseMovesItToAnotherList() { PerformDragAndDropWithMouse(); IWebElement dragInto = driver.FindElement(By.Id("sortable1")); - Assert.AreEqual(6, dragInto.FindElements(By.TagName("li")).Count); + Assert.That(dragInto.FindElements(By.TagName("li")), Has.Exactly(6).Items); } // This test is very similar to DraggingElementWithMouse. The only @@ -116,7 +116,7 @@ public void ShouldAllowDragAndDrop() dropInto = driver.FindElement(By.Id("droppable")); string text = dropInto.FindElement(By.TagName("p")).Text; - Assert.AreEqual("Dropped!", text); + Assert.That(text, Is.EqualTo("Dropped!")); } [Test] @@ -130,7 +130,7 @@ public void ShouldAllowDoubleClick() IAction dblClick = actionProvider.DoubleClick(toDoubleClick).Build(); dblClick.Perform(); - Assert.AreEqual("DoubleClicked", toDoubleClick.GetAttribute("value")); + Assert.That(toDoubleClick.GetAttribute("value"), Is.EqualTo("DoubleClicked")); } [Test] @@ -144,7 +144,7 @@ public void ShouldAllowContextClick() IAction contextClick = actionProvider.ContextClick(toContextClick).Build(); contextClick.Perform(); - Assert.AreEqual("ContextClicked", toContextClick.GetAttribute("value")); + Assert.That(toContextClick.GetAttribute("value"), Is.EqualTo("ContextClicked")); } [Test] @@ -159,7 +159,7 @@ public void ShouldAllowMoveAndClick() IAction contextClick = actionProvider.MoveToElement(toClick).Click().Build(); contextClick.Perform(); - Assert.AreEqual("Clicked", toClick.GetAttribute("value"), "Value should change to Clicked."); + Assert.That(toClick.GetAttribute("value"), Is.EqualTo("Clicked"), "Value should change to Clicked."); } [Test] @@ -175,8 +175,8 @@ public void ShouldMoveToLocation() IWebElement location = driver.FindElement(By.Id("absolute-location")); var coordinates = location.Text.Split(','); - Assert.AreEqual("100", coordinates[0].Trim()); - Assert.AreEqual("200", coordinates[1].Trim()); + Assert.That(coordinates[0].Trim(), Is.EqualTo("100")); + Assert.That(coordinates[1].Trim(), Is.EqualTo("200")); } [Test] @@ -286,14 +286,14 @@ public void ShouldAllowUsersToHoverOverElements() } IWebElement item = driver.FindElement(By.Id("item1")); - Assert.AreEqual("", item.Text); + Assert.That(item.Text, Is.EqualTo("")); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].style.background = 'green'", element); Actions actionBuilder = new Actions(driver); actionBuilder.MoveToElement(element).Perform(); item = driver.FindElement(By.Id("item1")); - Assert.AreEqual("Item 1", item.Text); + Assert.That(item.Text, Is.EqualTo("Item 1")); } [Test] @@ -307,7 +307,7 @@ public void HoverPersists() IWebElement element = driver.FindElement(By.Id("menu1")); IWebElement item = driver.FindElement(By.Id("item1")); - Assert.AreEqual(string.Empty, item.Text); + Assert.That(item.Text, Is.Empty); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].style.background = 'green'", element); new Actions(driver).MoveToElement(element).Perform(); @@ -317,7 +317,7 @@ public void HoverPersists() WaitFor(ElementTextToNotEqual(item, ""), "Element text was empty after timeout"); - Assert.AreEqual("Item 1", item.Text); + Assert.That(item.Text, Is.EqualTo("Item 1")); } [Test] @@ -462,7 +462,7 @@ private void PerformDragAndDropWithMouse() IAction drop = new Actions(driver).Release(dragInto).Build(); - Assert.AreEqual("Nothing happened.", dragReporter.Text); + Assert.That(dragReporter.Text, Is.EqualTo("Nothing happened.")); holdItem.Perform(); moveToSpecificItem.Perform(); diff --git a/dotnet/test/common/Interactions/BasicWheelInterfaceTest.cs b/dotnet/test/common/Interactions/BasicWheelInterfaceTest.cs index f46cb647dc510..38ef28a7a8fcd 100644 --- a/dotnet/test/common/Interactions/BasicWheelInterfaceTest.cs +++ b/dotnet/test/common/Interactions/BasicWheelInterfaceTest.cs @@ -46,7 +46,7 @@ public void ShouldSetActiveWheel() WheelInputDevice device = actionProvider.GetActiveWheel(); - Assert.AreEqual("test wheel", device.DeviceName); + Assert.That(device.DeviceName, Is.EqualTo("test wheel")); } [Test] @@ -56,11 +56,11 @@ public void ShouldAllowScrollingToAnElement() driver.Url = scrollFrameOutOfViewport; IWebElement iframe = driver.FindElement(By.TagName("iframe")); - Assert.IsFalse(IsInViewport(iframe)); + Assert.That(IsInViewport(iframe), Is.False); new Actions(driver).ScrollToElement(iframe).Build().Perform(); - Assert.IsTrue(IsInViewport(iframe)); + Assert.That(IsInViewport(iframe), Is.True); } [Test] @@ -78,7 +78,7 @@ public void ShouldScrollFromElementByGivenAmount() driver.SwitchTo().Frame(iframe); IWebElement checkbox = driver.FindElement(By.Name("scroll_checkbox")); - Assert.IsTrue(IsInViewport(checkbox)); + Assert.That(IsInViewport(checkbox), Is.True); } [Test] @@ -99,7 +99,7 @@ public void ShouldAllowScrollingFromElementByGivenAmountWithOffset() IWebElement iframe = driver.FindElement(By.TagName("iframe")); driver.SwitchTo().Frame(iframe); IWebElement checkbox = driver.FindElement(By.Name("scroll_checkbox")); - Assert.IsTrue(IsInViewport(checkbox)); + Assert.That(IsInViewport(checkbox), Is.True); } [Test] @@ -128,7 +128,7 @@ public void ShouldAllowScrollingFromViewportByGivenAmount() new Actions(driver).ScrollByAmount(0, deltaY).Build().Perform(); - Assert.IsTrue(IsInViewport(footer)); + Assert.That(IsInViewport(footer), Is.True); } [Test] @@ -147,7 +147,7 @@ public void ShouldAllowScrollingFromViewportByGivenAmountFromOrigin() IWebElement iframe = driver.FindElement(By.TagName("iframe")); driver.SwitchTo().Frame(iframe); IWebElement checkbox = driver.FindElement(By.Name("scroll_checkbox")); - Assert.IsTrue(IsInViewport(checkbox)); + Assert.That(IsInViewport(checkbox), Is.True); } [Test] diff --git a/dotnet/test/common/Interactions/CombinedInputActionsTest.cs b/dotnet/test/common/Interactions/CombinedInputActionsTest.cs index 9133254c209c5..9fcb0d42422c7 100644 --- a/dotnet/test/common/Interactions/CombinedInputActionsTest.cs +++ b/dotnet/test/common/Interactions/CombinedInputActionsTest.cs @@ -70,7 +70,7 @@ public void PlainClickingOnMultiSelectionList() showButton.Click(); IWebElement resultElement = driver.FindElement(By.Id("result")); - Assert.AreEqual("cheddar", resultElement.Text, "Should have picked the third option only."); + Assert.That(resultElement.Text, Is.EqualTo("cheddar"), "Should have picked the third option only."); } [Test] @@ -94,7 +94,7 @@ public void ShouldAllowSettingActivePointerWithKeyBoardActions() loginAction.Perform(); IAlert alert = driver.SwitchTo().Alert(); - Assert.AreEqual("You have successfully logged in.", alert.Text); + Assert.That(alert.Text, Is.EqualTo("You have successfully logged in.")); alert.Accept(); } @@ -120,7 +120,7 @@ public void ShiftClickingOnMultiSelectionList() showButton.Click(); IWebElement resultElement = driver.FindElement(By.Id("result")); - Assert.AreEqual("roquefort parmigiano cheddar", resultElement.Text, "Should have picked the last three options."); + Assert.That(resultElement.Text, Is.EqualTo("roquefort parmigiano cheddar"), "Should have picked the last three options."); } [Test] @@ -149,7 +149,7 @@ public void ControlClickingOnMultiSelectionList() showButton.Click(); IWebElement resultElement = driver.FindElement(By.Id("result")); - Assert.AreEqual("roquefort cheddar", resultElement.Text, "Should have picked the first and third options."); + Assert.That(resultElement.Text, Is.EqualTo("roquefort cheddar"), "Should have picked the first and third options."); } [Test] @@ -165,7 +165,7 @@ public void ControlClickingOnCustomMultiSelectionList() IWebElement reportingElement = driver.FindElement(By.Id("infodiv")); - Assert.AreEqual("no info", reportingElement.Text); + Assert.That(reportingElement.Text, Is.EqualTo("no info")); ReadOnlyCollection listItems = driver.FindElements(By.TagName("li")); @@ -177,11 +177,11 @@ public void ControlClickingOnCustomMultiSelectionList() selectThreeItems.Perform(); - Assert.AreEqual("#item2 #item4 #item6", reportingElement.Text); + Assert.That(reportingElement.Text, Is.EqualTo("#item2 #item4 #item6")); // Now click on another element, make sure that's the only one selected. new Actions(driver).Click(listItems[6]).Build().Perform(); - Assert.AreEqual("#item7", reportingElement.Text); + Assert.That(reportingElement.Text, Is.EqualTo("#item7")); } [Test] @@ -292,7 +292,7 @@ public void ChordControlCutAndPaste() .SendKeys(element, "abc def") .Perform(); - Assert.AreEqual("abc def", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("abc def")); //TODO: Figure out why calling sendKey(Key.CONTROL + "a") and then //sendKeys("x") does not work on Linux. @@ -303,7 +303,7 @@ public void ChordControlCutAndPaste() // Release keys before next step. new Actions(driver).SendKeys(Keys.Null).Perform(); - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); new Actions(driver).KeyDown(controlModifier) .SendKeys("v") @@ -312,7 +312,7 @@ public void ChordControlCutAndPaste() new Actions(driver).SendKeys(Keys.Null).Perform(); - Assert.AreEqual("abc defabc def", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("abc defabc def")); } [Test] @@ -331,8 +331,8 @@ public void CombiningShiftAndClickResultsInANewWindow() .KeyUp(Keys.Shift) .Perform(); WaitFor(() => { return driver.WindowHandles.Count > 1; }, "Did not receive new window"); - Assert.AreEqual(2, driver.WindowHandles.Count, "Should have opened a new window."); - Assert.AreEqual(originalTitle, driver.Title, "Should not have navigated away."); + Assert.That(driver.WindowHandles, Has.Exactly(2).Items, "Should have opened a new window."); + Assert.That(driver.Title, Is.EqualTo(originalTitle), "Should not have navigated away."); string originalHandle = driver.CurrentWindowHandle; foreach (string newHandle in driver.WindowHandles) @@ -358,7 +358,7 @@ public void HoldingDownShiftKeyWhileClicking() new Actions(driver).MoveToElement(toClick).KeyDown(Keys.Shift).Click().KeyUp(Keys.Shift).Perform(); IWebElement shiftInfo = WaitFor(() => { return driver.FindElement(By.Id("shiftKey")); }, "Could not find element with id 'shiftKey'"); - Assert.AreEqual("true", shiftInfo.Text); + Assert.That(shiftInfo.Text, Is.EqualTo("true")); } [Test] @@ -373,7 +373,7 @@ public void CanClickOnSuckerFishStyleMenu() IWebElement element = driver.FindElement(By.Id("menu1")); IWebElement target = driver.FindElement(By.Id("item1")); - Assert.AreEqual(string.Empty, target.Text); + Assert.That(target.Text, Is.Empty); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].style.background = 'green'", element); new Actions(driver).MoveToElement(element).Build().Perform(); @@ -413,7 +413,7 @@ public void PerformsPause() { DateTime start = DateTime.Now; new Actions(driver).Pause(TimeSpan.FromMilliseconds(1200)).Build().Perform(); - Assert.IsTrue(DateTime.Now - start > TimeSpan.FromMilliseconds(1200)); + Assert.That(DateTime.Now - start > TimeSpan.FromMilliseconds(1200), Is.True); } [Test] diff --git a/dotnet/test/common/Interactions/DragAndDropTest.cs b/dotnet/test/common/Interactions/DragAndDropTest.cs index 87a900aefa86b..0eb0f98c03d5d 100644 --- a/dotnet/test/common/Interactions/DragAndDropTest.cs +++ b/dotnet/test/common/Interactions/DragAndDropTest.cs @@ -44,13 +44,13 @@ public void DragAndDropRelative() driver.Url = dragAndDropPage; IWebElement img = driver.FindElement(By.Id("test1")); Point expectedLocation = Drag(img, img.Location, 150, 200); - Assert.AreEqual(expectedLocation, img.Location); + Assert.That(img.Location, Is.EqualTo(expectedLocation)); expectedLocation = Drag(img, img.Location, -50, -25); - Assert.AreEqual(expectedLocation, img.Location); + Assert.That(img.Location, Is.EqualTo(expectedLocation)); expectedLocation = Drag(img, img.Location, 0, 0); - Assert.AreEqual(expectedLocation, img.Location); + Assert.That(img.Location, Is.EqualTo(expectedLocation)); expectedLocation = Drag(img, img.Location, 1, -1); - Assert.AreEqual(expectedLocation, img.Location); + Assert.That(img.Location, Is.EqualTo(expectedLocation)); } [Test] @@ -61,7 +61,7 @@ public void DragAndDropToElement() IWebElement img2 = driver.FindElement(By.Id("test2")); Actions actionProvider = new Actions(driver); actionProvider.DragAndDrop(img2, img1).Perform(); - Assert.AreEqual(img1.Location, img2.Location); + Assert.That(img2.Location, Is.EqualTo(img1.Location)); } [Test] @@ -87,7 +87,7 @@ public void DragAndDropToElementInIframe() IWebElement img2 = driver.FindElement(By.Id("test2")); new Actions(driver).DragAndDrop(img2, img1).Perform(); - Assert.AreEqual(img1.Location, img2.Location); + Assert.That(img2.Location, Is.EqualTo(img1.Location)); } [Test] @@ -103,7 +103,7 @@ public void DragAndDropElementWithOffsetInIframeAtBottom() new Actions(driver).DragAndDropToOffset(img1, 20, 20).Perform(); initial.Offset(20, 20); - Assert.AreEqual(initial, img1.Location); + Assert.That(img1.Location, Is.EqualTo(initial)); } [Test] @@ -126,7 +126,7 @@ public void DragAndDropElementWithOffsetInScrolledDiv() new Actions(driver).DragAndDropToOffset(el, 3700, 3700).Perform(); initial.Offset(3700, 3700); - Assert.AreEqual(initial, el.Location); + Assert.That(el.Location, Is.EqualTo(initial)); } [Test] @@ -137,7 +137,7 @@ public void ElementInDiv() Point startLocation = img.Location; Point expectedLocation = Drag(img, startLocation, 100, 100); Point endLocation = img.Location; - Assert.AreEqual(expectedLocation, endLocation); + Assert.That(endLocation, Is.EqualTo(expectedLocation)); } [Test] @@ -172,7 +172,7 @@ public void ShouldAllowUsersToDragAndDropToElementsOffTheCurrentViewPort() driver.Url = dragAndDropPage; IWebElement img = driver.FindElement(By.Id("test3")); Point expectedLocation = Drag(img, img.Location, 100, 100); - Assert.AreEqual(expectedLocation, img.Location); + Assert.That(img.Location, Is.EqualTo(expectedLocation)); } finally { @@ -204,15 +204,15 @@ public void DragAndDropOnJQueryItems() text = dropInto.FindElement(By.TagName("p")).Text; } - Assert.AreEqual("Dropped!", text); + Assert.That(text, Is.EqualTo("Dropped!")); IWebElement reporter = driver.FindElement(By.Id("drop_reports")); // Assert that only one mouse click took place and the mouse was moved // during it. string reporterText = reporter.Text; Assert.That(reporterText, Does.Match("start( move)* down( move)+ up")); - Assert.AreEqual(1, Regex.Matches(reporterText, "down").Count, "Reporter text:" + reporterText); - Assert.AreEqual(1, Regex.Matches(reporterText, "up").Count, "Reporter text:" + reporterText); + Assert.That(Regex.Matches(reporterText, "down"), Has.Count.EqualTo(1), "Reporter text:" + reporterText); + Assert.That(Regex.Matches(reporterText, "up"), Has.Count.EqualTo(1), "Reporter text:" + reporterText); Assert.That(reporterText, Does.Contain("move")); } @@ -230,11 +230,11 @@ public void CanDragAnElementNotVisibleInTheCurrentViewportDueToAParentOverflow() Point targetLocation = dragTo.Location; int yOffset = targetLocation.Y - srcLocation.Y; - Assert.AreNotEqual(0, yOffset); + Assert.That(yOffset, Is.Not.Zero); new Actions(driver).DragAndDropToOffset(toDrag, 0, yOffset).Perform(); - Assert.AreEqual(dragTo.Location, toDrag.Location); + Assert.That(toDrag.Location, Is.EqualTo(dragTo.Location)); } //------------------------------------------------------------------ @@ -250,7 +250,7 @@ public void DragAndDropRelativeAndToElement() actionProvider.DragAndDropToOffset(img1, 100, 100).Perform(); actionProvider.Reset(); actionProvider.DragAndDrop(img2, img1).Perform(); - Assert.AreEqual(img1.Location, img2.Location); + Assert.That(img2.Location, Is.EqualTo(img1.Location)); } private Point Drag(IWebElement elem, Point initialLocation, int moveRightBy, int moveDownBy) diff --git a/dotnet/test/common/JavascriptEnabledBrowserTest.cs b/dotnet/test/common/JavascriptEnabledBrowserTest.cs index 2c87086c89703..ea9d267db29d8 100644 --- a/dotnet/test/common/JavascriptEnabledBrowserTest.cs +++ b/dotnet/test/common/JavascriptEnabledBrowserTest.cs @@ -32,9 +32,9 @@ public void DocumentShouldReflectLatestTitle() { driver.Url = javascriptPage; - Assert.AreEqual("Testing Javascript", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Testing Javascript")); driver.FindElement(By.LinkText("Change the page title!")).Click(); - Assert.AreEqual("Changed", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Changed")); } [Test] @@ -42,13 +42,13 @@ public void DocumentShouldReflectLatestDom() { driver.Url = javascriptPage; String currentText = driver.FindElement(By.XPath("//div[@id='dynamo']")).Text; - Assert.AreEqual("What's for dinner?", currentText); + Assert.That(currentText, Is.EqualTo("What's for dinner?")); IWebElement element = driver.FindElement(By.LinkText("Update a div")); element.Click(); String newText = driver.FindElement(By.XPath("//div[@id='dynamo']")).Text; - Assert.AreEqual("Fish and chips!", newText); + Assert.That(newText, Is.EqualTo("Fish and chips!")); } [Test] @@ -60,7 +60,7 @@ public void ShouldWaitForLoadsToCompleteAfterJavascriptCausesANewPageToLoad() driver.FindElement(By.Id("changeme")).Click(); WaitFor(() => { return driver.Title == "Page3"; }, "Browser title was not 'Page3'"); - Assert.AreEqual("Page3", driver.Title); + Assert.That(driver.Title, Is.EqualTo("Page3")); } [Test] @@ -73,7 +73,7 @@ public void ShouldBeAbleToFindElementAfterJavascriptCausesANewPageToLoad() driver.FindElement(By.Id("changeme")).Click(); WaitFor(() => { return driver.Title == "Page3"; }, "Browser title was not 'Page3'"); - Assert.AreEqual("3", driver.FindElement(By.Id("pageNumber")).Text); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("3")); } [Test] @@ -83,7 +83,7 @@ public void ShouldFireOnChangeEventWhenSettingAnElementsValue() driver.FindElement(By.Id("change")).SendKeys("foo"); String result = driver.FindElement(By.Id("result")).Text; - Assert.AreEqual("change", result); + Assert.That(result, Is.EqualTo("change")); } [Test] @@ -94,7 +94,7 @@ public void ShouldBeAbleToSubmitFormsByCausingTheOnClickEventToFire() element.Click(); WaitFor(() => { return driver.Title == "We Arrive Here"; }, "Browser title was not 'We Arrive Here'"); - Assert.AreEqual("We Arrive Here", driver.Title); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -105,7 +105,7 @@ public void ShouldBeAbleToClickOnSubmitButtons() element.Click(); WaitFor(() => { return driver.Title == "We Arrive Here"; }, "Browser title was not 'We Arrive Here'"); - Assert.AreEqual("We Arrive Here", driver.Title); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -113,11 +113,11 @@ public void Issue80ClickShouldGenerateClickEvent() { driver.Url = javascriptPage; IWebElement element = driver.FindElement(By.Id("clickField")); - Assert.AreEqual("Hello", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("Hello")); element.Click(); - Assert.AreEqual("Clicked", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("Clicked")); } [Test] @@ -128,7 +128,7 @@ public void ShouldBeAbleToSwitchToFocusedElement() driver.FindElement(By.Id("switchFocus")).Click(); IWebElement element = driver.SwitchTo().ActiveElement(); - Assert.AreEqual("theworks", element.GetAttribute("id")); + Assert.That(element.GetAttribute("id"), Is.EqualTo("theworks")); } [Test] @@ -138,7 +138,7 @@ public void IfNoElementHasFocusTheActiveElementIsTheBody() IWebElement element = driver.SwitchTo().ActiveElement(); - Assert.AreEqual("body", element.GetAttribute("name")); + Assert.That(element.GetAttribute("name"), Is.EqualTo("body")); } [Test] diff --git a/dotnet/test/common/MiscTest.cs b/dotnet/test/common/MiscTest.cs index a979bd1071d60..dbccd948ed371 100644 --- a/dotnet/test/common/MiscTest.cs +++ b/dotnet/test/common/MiscTest.cs @@ -40,13 +40,13 @@ public void ShouldReturnTitleOfPageIfSet() public void ShouldReportTheCurrentUrlCorrectly() { driver.Url = macbethPage; - Assert.AreEqual(macbethPage, driver.Url); + Assert.That(driver.Url, Is.EqualTo(macbethPage)); driver.Url = simpleTestPage; - Assert.AreEqual(simpleTestPage, driver.Url); + Assert.That(driver.Url, Is.EqualTo(simpleTestPage)); driver.Url = javascriptPage; - Assert.AreEqual(javascriptPage, driver.Url); + Assert.That(driver.Url, Is.EqualTo(javascriptPage)); } [Test] @@ -82,7 +82,7 @@ public void ShouldBeAbleToGetTheSourceOfAnXmlDocument() driver.Url = simpleXmlDocument; string source = driver.PageSource.ToLower(); source = System.Text.RegularExpressions.Regex.Replace(source, "\\s", string.Empty); - Assert.AreEqual("baz", source); + Assert.That(source, Is.EqualTo("baz")); } // Test is ignored for all browsers, but is kept here in the source code for @@ -108,14 +108,14 @@ public void ClickingShouldNotTrampleWOrHInGlobalScope() foreach (string val in values) { - Assert.AreEqual(val, GetGlobalVar(driver, val)); + Assert.That(GetGlobalVar(driver, val), Is.EqualTo(val)); } driver.FindElement(By.Id("toclick")).Click(); foreach (string val in values) { - Assert.AreEqual(val, GetGlobalVar(driver, val)); + Assert.That(GetGlobalVar(driver, val), Is.EqualTo(val)); } } diff --git a/dotnet/test/common/NavigationTest.cs b/dotnet/test/common/NavigationTest.cs index 32a660f7cd57f..40f4d53bed1ec 100644 --- a/dotnet/test/common/NavigationTest.cs +++ b/dotnet/test/common/NavigationTest.cs @@ -48,10 +48,10 @@ public void ShouldGoBackAndForward() driver.Url = simpleTestPage; navigation.Back(); - Assert.AreEqual(macbethTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(macbethTitle)); navigation.Forward(); - Assert.AreEqual(simpleTestTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(simpleTestTitle)); } [Test] @@ -71,12 +71,12 @@ public void ShouldGoToUrlUsingString() navigation = driver.Navigate(); navigation.GoToUrl(macbethPage); - Assert.AreEqual(macbethTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(macbethTitle)); // We go to two pages to ensure that the browser wasn't // already at the desired page through a previous test. navigation.GoToUrl(simpleTestPage); - Assert.AreEqual(simpleTestTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(simpleTestTitle)); } [Test] @@ -88,12 +88,12 @@ public void ShouldGoToUrlUsingUri() navigation = driver.Navigate(); navigation.GoToUrl(macBeth); - Assert.AreEqual(driver.Title, macbethTitle); + Assert.That(macbethTitle, Is.EqualTo(driver.Title)); // We go to two pages to ensure that the browser wasn't // already at the desired page through a previous test. navigation.GoToUrl(simpleTest); - Assert.AreEqual(simpleTestTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(simpleTestTitle)); } [Test] @@ -103,11 +103,11 @@ public void ShouldRefreshPage() IWebElement changedDiv = driver.FindElement(By.Id("dynamo")); driver.FindElement(By.Id("updatediv")).Click(); - Assert.AreEqual("Fish and chips!", changedDiv.Text); + Assert.That(changedDiv.Text, Is.EqualTo("Fish and chips!")); driver.Navigate().Refresh(); changedDiv = driver.FindElement(By.Id("dynamo")); - Assert.AreEqual("What's for dinner?", changedDiv.Text); + Assert.That(changedDiv.Text, Is.EqualTo("What's for dinner?")); } [Test] @@ -129,10 +129,10 @@ public async Task ShouldGoBackAndForwardAsync() await navigation.GoToUrlAsync(simpleTestPage); await navigation.BackAsync(); - Assert.AreEqual(macbethTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(macbethTitle)); await navigation.ForwardAsync(); - Assert.AreEqual(simpleTestTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(simpleTestTitle)); } [Test] @@ -148,10 +148,10 @@ public async Task ShouldGoToUrlUsingStringAsync() var navigation = driver.Navigate(); await navigation.GoToUrlAsync(macbethPage); - Assert.AreEqual(macbethTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(macbethTitle)); await navigation.GoToUrlAsync(simpleTestPage); - Assert.AreEqual(simpleTestTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(simpleTestTitle)); } [Test] @@ -160,9 +160,9 @@ public void ShouldGoToUrlUsingUriAsync() var navigation = driver.Navigate(); navigation.GoToUrlAsync(new Uri(macbethPage)); - Assert.AreEqual(driver.Title, macbethTitle); + Assert.That(macbethTitle, Is.EqualTo(driver.Title)); navigation.GoToUrl(new Uri(simpleTestPage)); - Assert.AreEqual(simpleTestTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(simpleTestTitle)); } [Test] @@ -172,11 +172,11 @@ public async Task ShouldRefreshPageAsync() IWebElement changedDiv = driver.FindElement(By.Id("dynamo")); driver.FindElement(By.Id("updatediv")).Click(); - Assert.AreEqual("Fish and chips!", changedDiv.Text); + Assert.That(changedDiv.Text, Is.EqualTo("Fish and chips!")); await driver.Navigate().RefreshAsync(); changedDiv = driver.FindElement(By.Id("dynamo")); - Assert.AreEqual("What's for dinner?", changedDiv.Text); + Assert.That(changedDiv.Text, Is.EqualTo("What's for dinner?")); } } } diff --git a/dotnet/test/common/NetworkInterceptionTests.cs b/dotnet/test/common/NetworkInterceptionTests.cs index 10234945895d0..59434fb563e86 100644 --- a/dotnet/test/common/NetworkInterceptionTests.cs +++ b/dotnet/test/common/NetworkInterceptionTests.cs @@ -57,7 +57,7 @@ public async Task TestCanInterceptNetworkCalls() driver.Url = simpleTestPage; string text = driver.FindElement(By.CssSelector("p")).Text; await network.StopMonitoring(); - Assert.AreEqual("I intercepted you", text); + Assert.That(text, Is.EqualTo("I intercepted you")); } } @@ -78,7 +78,7 @@ public async Task TestCanUseAuthorizationHandler() driver.Url = authenticationPage; string text = driver.FindElement(By.CssSelector("h1")).Text; await network.StopMonitoring(); - Assert.AreEqual("authorized", text); + Assert.That(text, Is.EqualTo("authorized")); } } } diff --git a/dotnet/test/common/PageLoadingTest.cs b/dotnet/test/common/PageLoadingTest.cs index 9cbb86c06bcb4..0b231c94746e1 100644 --- a/dotnet/test/common/PageLoadingTest.cs +++ b/dotnet/test/common/PageLoadingTest.cs @@ -145,7 +145,7 @@ public void NormalStrategyShouldWaitForDocumentToBeLoaded() { driver.Url = simpleTestPage; - Assert.AreEqual(driver.Title, "Hello WebDriver"); + Assert.That(driver.Title, Is.EqualTo("Hello WebDriver")); } [Test] @@ -153,7 +153,7 @@ public void NormalStrategyShouldWaitForDocumentToBeLoaded() public void ShouldFollowRedirectsSentInTheHttpResponseHeaders() { driver.Url = redirectPage; - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -161,7 +161,7 @@ public void ShouldFollowMetaRedirects() { driver.Url = metaRedirectPage; WaitFor(() => { return driver.Title == "We Arrive Here"; }, "Browser title was not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -192,7 +192,7 @@ public void ShouldReturnUrlOnNotExistedPage() { string url = EnvironmentManager.Instance.UrlBuilder.WhereIs("not_existed_page.html"); driver.Url = url; - Assert.AreEqual(url, driver.Url); + Assert.That(driver.Url, Is.EqualTo(url)); } [Test] @@ -202,11 +202,11 @@ public void ShouldBeAbleToLoadAPageWithFramesetsAndWaitUntilAllFramesAreLoaded() driver.SwitchTo().Frame(0); IWebElement pageNumber = driver.FindElement(By.XPath("//span[@id='pageNumber']")); - Assert.AreEqual(pageNumber.Text.Trim(), "1"); + Assert.That(pageNumber.Text.Trim(), Is.EqualTo("1")); driver.SwitchTo().DefaultContent().SwitchTo().Frame(1); pageNumber = driver.FindElement(By.XPath("//span[@id='pageNumber']")); - Assert.AreEqual(pageNumber.Text.Trim(), "2"); + Assert.That(pageNumber.Text.Trim(), Is.EqualTo("2")); } [Test] @@ -223,7 +223,7 @@ public void ShouldDoNothingIfThereIsNothingToGoBackTo() if (driver.Title == originalTitle) { driver.Navigate().Back(); - Assert.AreEqual(originalTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(originalTitle)); } } @@ -234,11 +234,11 @@ public void ShouldBeAbleToNavigateBackInTheBrowserHistory() driver.FindElement(By.Id("imageButton")).Submit(); WaitFor(TitleToBeEqualTo("We Arrive Here"), "Browser title was not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); driver.Navigate().Back(); WaitFor(TitleToBeEqualTo("We Leave From Here"), "Browser title was not 'We Leave From Here'"); - Assert.AreEqual(driver.Title, "We Leave From Here"); + Assert.That(driver.Title, Is.EqualTo("We Leave From Here")); } [Test] @@ -248,11 +248,11 @@ public void ShouldBeAbleToNavigateBackInTheBrowserHistoryInPresenceOfIframes() driver.FindElement(By.Name("sameWindow")).Click(); WaitFor(TitleToBeEqualTo("This page has iframes"), "Browser title was not 'This page has iframes'"); - Assert.AreEqual(driver.Title, "This page has iframes"); + Assert.That(driver.Title, Is.EqualTo("This page has iframes")); driver.Navigate().Back(); WaitFor(TitleToBeEqualTo("XHTML Test Page"), "Browser title was not 'XHTML Test Page'"); - Assert.AreEqual(driver.Title, "XHTML Test Page"); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } [Test] @@ -262,15 +262,15 @@ public void ShouldBeAbleToNavigateForwardsInTheBrowserHistory() driver.FindElement(By.Id("imageButton")).Submit(); WaitFor(TitleToBeEqualTo("We Arrive Here"), "Browser title was not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); driver.Navigate().Back(); WaitFor(TitleToBeEqualTo("We Leave From Here"), "Browser title was not 'We Leave From Here'"); - Assert.AreEqual(driver.Title, "We Leave From Here"); + Assert.That(driver.Title, Is.EqualTo("We Leave From Here")); driver.Navigate().Forward(); WaitFor(TitleToBeEqualTo("We Arrive Here"), "Browser title was not 'We Arrive Here'"); - Assert.AreEqual(driver.Title, "We Arrive Here"); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } [Test] @@ -283,7 +283,7 @@ public void ShouldBeAbleToAccessPagesWithAnInsecureSslCertificate() driver.Url = url; // This should work - Assert.AreEqual(driver.Title, "Hello WebDriver"); + Assert.That(driver.Title, Is.EqualTo("Hello WebDriver")); } [Test] @@ -293,7 +293,7 @@ public void ShouldBeAbleToRefreshAPage() driver.Navigate().Refresh(); - Assert.AreEqual(driver.Title, "XHTML Test Page"); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); } /// diff --git a/dotnet/test/common/PartialLinkTextMatchTest.cs b/dotnet/test/common/PartialLinkTextMatchTest.cs index 111c7e301702a..1d69fe0b7aea7 100644 --- a/dotnet/test/common/PartialLinkTextMatchTest.cs +++ b/dotnet/test/common/PartialLinkTextMatchTest.cs @@ -33,7 +33,7 @@ public void LinkWithFormattingTags() IWebElement res = elem.FindElement(By.PartialLinkText("link with formatting tags")); Assert.That(res, Is.Not.Null); - Assert.AreEqual("link with formatting tags", res.Text); + Assert.That(res.Text, Is.EqualTo("link with formatting tags")); } [Test] @@ -44,7 +44,7 @@ public void LinkWithLeadingSpaces() IWebElement res = elem.FindElement(By.PartialLinkText("link with leading space")); Assert.That(res, Is.Not.Null); - Assert.AreEqual("link with leading space", res.Text); + Assert.That(res.Text, Is.EqualTo("link with leading space")); } [Test] @@ -56,7 +56,7 @@ public void LinkWithTrailingSpace() IWebElement res = elem.FindElement(By.PartialLinkText("link with trailing space")); Assert.That(res, Is.Not.Null); - Assert.AreEqual("link with trailing space", res.Text); + Assert.That(res.Text, Is.EqualTo("link with trailing space")); } [Test] @@ -67,7 +67,7 @@ public void FindMultipleElements() ReadOnlyCollection elements = elem.FindElements(By.PartialLinkText("link")); Assert.That(elements, Is.Not.Null); - Assert.AreEqual(6, elements.Count); + Assert.That(elements, Has.Count.EqualTo(6)); } [Test] @@ -76,7 +76,7 @@ public void DriverCanGetLinkByLinkTestIgnoringTrailingWhitespace() driver.Url = simpleTestPage; IWebElement link = null; link = driver.FindElement(By.LinkText("link with trailing space")); - Assert.AreEqual("linkWithTrailingSpace", link.GetAttribute("id")); + Assert.That(link.GetAttribute("id"), Is.EqualTo("linkWithTrailingSpace")); } [Test] @@ -87,7 +87,7 @@ public void ElementCanGetLinkByLinkTestIgnoringTrailingWhitespace() IWebElement link = null; link = elem.FindElement(By.LinkText("link with trailing space")); - Assert.AreEqual("linkWithTrailingSpace", link.GetAttribute("id")); + Assert.That(link.GetAttribute("id"), Is.EqualTo("linkWithTrailingSpace")); } } } diff --git a/dotnet/test/common/PositionAndSizeTest.cs b/dotnet/test/common/PositionAndSizeTest.cs index 8b8f225148ec7..0a9d700ad1a8b 100644 --- a/dotnet/test/common/PositionAndSizeTest.cs +++ b/dotnet/test/common/PositionAndSizeTest.cs @@ -43,40 +43,40 @@ public void ShouldBeAbleToDetermineTheLocationOfAnElement() public void ShouldGetCoordinatesOfAnElement() { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("coordinates_tests/simple_page.html"); - Assert.AreEqual(new Point(10, 10), GetLocationInViewPort(By.Id("box"))); - Assert.AreEqual(new Point(10, 10), GetLocationOnPage(By.Id("box"))); + Assert.That(GetLocationInViewPort(By.Id("box")), Is.EqualTo(new Point(10, 10))); + Assert.That(GetLocationOnPage(By.Id("box")), Is.EqualTo(new Point(10, 10))); } [Test] public void ShouldGetCoordinatesOfAnEmptyElement() { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("coordinates_tests/page_with_empty_element.html"); - Assert.AreEqual(new Point(10, 10), GetLocationInViewPort(By.Id("box"))); - Assert.AreEqual(new Point(10, 10), GetLocationOnPage(By.Id("box"))); + Assert.That(GetLocationInViewPort(By.Id("box")), Is.EqualTo(new Point(10, 10))); + Assert.That(GetLocationOnPage(By.Id("box")), Is.EqualTo(new Point(10, 10))); } [Test] public void ShouldGetCoordinatesOfATransparentElement() { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("coordinates_tests/page_with_transparent_element.html"); - Assert.AreEqual(new Point(10, 10), GetLocationInViewPort(By.Id("box"))); - Assert.AreEqual(new Point(10, 10), GetLocationOnPage(By.Id("box"))); + Assert.That(GetLocationInViewPort(By.Id("box")), Is.EqualTo(new Point(10, 10))); + Assert.That(GetLocationOnPage(By.Id("box")), Is.EqualTo(new Point(10, 10))); } [Test] public void ShouldGetCoordinatesOfAHiddenElement() { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("coordinates_tests/page_with_hidden_element.html"); - Assert.AreEqual(new Point(10, 10), GetLocationInViewPort(By.Id("box"))); - Assert.AreEqual(new Point(10, 10), GetLocationOnPage(By.Id("box"))); + Assert.That(GetLocationInViewPort(By.Id("box")), Is.EqualTo(new Point(10, 10))); + Assert.That(GetLocationOnPage(By.Id("box")), Is.EqualTo(new Point(10, 10))); } [Test] public void ShouldGetCoordinatesOfAnInvisibleElement() { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("coordinates_tests/page_with_invisible_element.html"); - Assert.AreEqual(new Point(0, 0), GetLocationInViewPort(By.Id("box"))); - Assert.AreEqual(new Point(0, 0), GetLocationOnPage(By.Id("box"))); + Assert.That(GetLocationInViewPort(By.Id("box")), Is.EqualTo(new Point(0, 0))); + Assert.That(GetLocationOnPage(By.Id("box")), Is.EqualTo(new Point(0, 0))); } [Test] @@ -99,8 +99,8 @@ public void ShouldGetCoordinatesOfAnElementInAFrame() driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("coordinates_tests/element_in_frame.html"); driver.SwitchTo().Frame("ifr"); IWebElement box = driver.FindElement(By.Id("box")); - Assert.AreEqual(new Point(10, 10), box.Location); - Assert.AreEqual(new Point(10, 10), GetLocationOnPage(By.Id("box"))); + Assert.That(box.Location, Is.EqualTo(new Point(10, 10))); + Assert.That(GetLocationOnPage(By.Id("box")), Is.EqualTo(new Point(10, 10))); } [Test] @@ -108,7 +108,7 @@ public void ShouldGetCoordinatesInViewPortOfAnElementInAFrame() { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("coordinates_tests/element_in_frame.html"); driver.SwitchTo().Frame("ifr"); - Assert.AreEqual(new Point(10, 10), GetLocationOnPage(By.Id("box"))); + Assert.That(GetLocationOnPage(By.Id("box")), Is.EqualTo(new Point(10, 10))); // GetLocationInViewPort only works within the context of a single frame // for W3C-spec compliant remote ends. // Assert.AreEqual(new Point(25, 25), GetLocationInViewPort(By.Id("box"))); @@ -120,7 +120,7 @@ public void ShouldGetCoordinatesInViewPortOfAnElementInANestedFrame() driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("coordinates_tests/element_in_nested_frame.html"); driver.SwitchTo().Frame("ifr"); driver.SwitchTo().Frame("ifr"); - Assert.AreEqual(new Point(10, 10), GetLocationOnPage(By.Id("box"))); + Assert.That(GetLocationOnPage(By.Id("box")), Is.EqualTo(new Point(10, 10))); // GetLocationInViewPort only works within the context of a single frame // for W3C-spec compliant remote ends. // Assert.AreEqual(new Point(40, 40), GetLocationInViewPort(By.Id("box"))); @@ -156,15 +156,15 @@ public void ShouldHandleNonIntegerPositionAndSize() IWebElement r2 = driver.FindElement(By.Id("r2")); string left = r2.GetCssValue("left"); - Assert.AreEqual(10.9, Math.Round(Convert.ToDecimal(left.Replace("px", "")), 1)); + Assert.That(Math.Round(Convert.ToDecimal(left.Replace("px", "")), 1), Is.EqualTo(10.9)); string top = r2.GetCssValue("top"); - Assert.AreEqual(10.1, Math.Round(Convert.ToDecimal(top.Replace("px", "")), 1)); - Assert.AreEqual(new Point(11, 10), r2.Location); + Assert.That(Math.Round(Convert.ToDecimal(top.Replace("px", "")), 1), Is.EqualTo(10.1)); + Assert.That(r2.Location, Is.EqualTo(new Point(11, 10))); string width = r2.GetCssValue("width"); - Assert.AreEqual(48.7, Math.Round(Convert.ToDecimal(width.Replace("px", "")), 1)); + Assert.That(Math.Round(Convert.ToDecimal(width.Replace("px", "")), 1), Is.EqualTo(48.7)); string height = r2.GetCssValue("height"); - Assert.AreEqual(49.3, Math.Round(Convert.ToDecimal(height.Replace("px", "")), 1)); - Assert.AreEqual(new Size(49, 49), r2.Size); + Assert.That(Math.Round(Convert.ToDecimal(height.Replace("px", "")), 1), Is.EqualTo(49.3)); + Assert.That(r2.Size, Is.EqualTo(new Size(49, 49))); } //------------------------------------------------------------------ diff --git a/dotnet/test/common/SessionHandlingTest.cs b/dotnet/test/common/SessionHandlingTest.cs index f0c50c329a691..8b9c1db2f5504 100644 --- a/dotnet/test/common/SessionHandlingTest.cs +++ b/dotnet/test/common/SessionHandlingTest.cs @@ -49,7 +49,7 @@ public void CallingQuitAfterClosingTheLastWindowIsANoOp() testDriver.Quit(); testDriver = EnvironmentManager.Instance.CreateDriverInstance(); testDriver.Url = xhtmlTestPage; - Assert.AreEqual("XHTML Test Page", testDriver.Title); + Assert.That(testDriver.Title, Is.EqualTo("XHTML Test Page")); testDriver.Quit(); } @@ -106,7 +106,7 @@ public void ShouldBeAbleToStartNewDriverAfterCallingCloseOnOnlyOpenWindow() testDriver.Dispose(); testDriver = EnvironmentManager.Instance.CreateDriverInstance(); testDriver.Url = xhtmlTestPage; - Assert.AreEqual("XHTML Test Page", testDriver.Title); + Assert.That(testDriver.Title, Is.EqualTo("XHTML Test Page")); testDriver.Close(); testDriver.Dispose(); } @@ -143,7 +143,7 @@ public void ShouldBeAbleToCallDisposeAfterQuit() testDriver.Dispose(); testDriver = EnvironmentManager.Instance.CreateDriverInstance(); testDriver.Url = xhtmlTestPage; - Assert.AreEqual("XHTML Test Page", testDriver.Title); + Assert.That(testDriver.Title, Is.EqualTo("XHTML Test Page")); testDriver.Quit(); } @@ -155,7 +155,7 @@ public void ShouldOpenAndCloseBrowserRepeatedly() EnvironmentManager.Instance.CloseCurrentDriver(); CreateFreshDriver(); driver.Url = simpleTestPage; - Assert.AreEqual(simpleTestTitle, driver.Title); + Assert.That(driver.Title, Is.EqualTo(simpleTestTitle)); } } } diff --git a/dotnet/test/common/SvgDocumentTest.cs b/dotnet/test/common/SvgDocumentTest.cs index 5eb5483667c79..5a777d920492a 100644 --- a/dotnet/test/common/SvgDocumentTest.cs +++ b/dotnet/test/common/SvgDocumentTest.cs @@ -38,9 +38,9 @@ public void ClickOnSvgElement() driver.Url = svgTestPage; IWebElement rect = driver.FindElement(By.Id("rect")); - Assert.AreEqual("blue", rect.GetAttribute("fill")); + Assert.That(rect.GetAttribute("fill"), Is.EqualTo("blue")); rect.Click(); - Assert.AreEqual("green", rect.GetAttribute("fill")); + Assert.That(rect.GetAttribute("fill"), Is.EqualTo("green")); } [Test] @@ -54,9 +54,9 @@ public void ExecuteScriptInSvgDocument() driver.Url = svgTestPage; IWebElement rect = driver.FindElement(By.Id("rect")); - Assert.AreEqual("blue", rect.GetAttribute("fill")); + Assert.That(rect.GetAttribute("fill"), Is.EqualTo("blue")); ((IJavaScriptExecutor)driver).ExecuteScript("document.getElementById('rect').setAttribute('fill', 'yellow');"); - Assert.AreEqual("yellow", rect.GetAttribute("fill")); + Assert.That(rect.GetAttribute("fill"), Is.EqualTo("yellow")); } } } diff --git a/dotnet/test/common/SvgElementTest.cs b/dotnet/test/common/SvgElementTest.cs index fbefdea76a6ea..554b860edbc18 100644 --- a/dotnet/test/common/SvgElementTest.cs +++ b/dotnet/test/common/SvgElementTest.cs @@ -39,17 +39,17 @@ public void ShouldClickOnGraphVisualElements() IWebElement svg = driver.FindElement(By.CssSelector("svg")); ReadOnlyCollection groupElements = svg.FindElements(By.CssSelector("g")); - Assert.AreEqual(5, groupElements.Count); + Assert.That(groupElements, Has.Count.EqualTo(5)); groupElements[1].Click(); IWebElement resultElement = driver.FindElement(By.Id("result")); WaitFor(() => { return resultElement.Text == "slice_red"; }, "Element text was not 'slice_red'"); - Assert.AreEqual("slice_red", resultElement.Text); + Assert.That(resultElement.Text, Is.EqualTo("slice_red")); groupElements[2].Click(); resultElement = driver.FindElement(By.Id("result")); WaitFor(() => { return resultElement.Text == "slice_green"; }, "Element text was not 'slice_green'"); - Assert.AreEqual("slice_green", resultElement.Text); + Assert.That(resultElement.Text, Is.EqualTo("slice_green")); } [Test] @@ -70,7 +70,7 @@ public void ShouldClickOnGraphTextElements() appleElement.Click(); IWebElement resultElement = driver.FindElement(By.Id("result")); WaitFor(() => { return resultElement.Text == "text_apple"; }, "Element text was not 'text_apple'"); - Assert.AreEqual("text_apple", resultElement.Text); + Assert.That(resultElement.Text, Is.EqualTo("text_apple")); } private IWebElement FindAppleElement(IEnumerable textElements) diff --git a/dotnet/test/common/TagNameTest.cs b/dotnet/test/common/TagNameTest.cs index fec7d75d2cc0d..77b64af111de8 100644 --- a/dotnet/test/common/TagNameTest.cs +++ b/dotnet/test/common/TagNameTest.cs @@ -29,7 +29,7 @@ public void ShouldReturnInput() { driver.Url = formsPage; IWebElement selectBox = driver.FindElement(By.Id("cheese")); - Assert.AreEqual(selectBox.TagName.ToLower(), "input"); + Assert.That(selectBox.TagName, Is.EqualTo("input").IgnoreCase); } } } diff --git a/dotnet/test/common/TakesScreenshotTest.cs b/dotnet/test/common/TakesScreenshotTest.cs index 6c09b0acfde93..74fcad3463f42 100644 --- a/dotnet/test/common/TakesScreenshotTest.cs +++ b/dotnet/test/common/TakesScreenshotTest.cs @@ -141,7 +141,7 @@ public void ShouldTakeScreenshotsOfAnElement() Color pixelColor = GetPixelColor(screenImage, 1, 1); string pixelColorString = FormatColorToHex(pixelColor.ToArgb()); - Assert.AreEqual("#0f12f7", pixelColorString); + Assert.That(pixelColorString, Is.EqualTo("#0f12f7")); } [Test] diff --git a/dotnet/test/common/TargetLocatorTest.cs b/dotnet/test/common/TargetLocatorTest.cs index 19a23cb1dd086..de1cd4a70816a 100644 --- a/dotnet/test/common/TargetLocatorTest.cs +++ b/dotnet/test/common/TargetLocatorTest.cs @@ -89,7 +89,7 @@ public void ShouldSwitchToFrameByNameAndBackToDefaultContent() driver.Url = framesPage; driver.SwitchTo().Frame("first"); - Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "1"); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("1")); driver.SwitchTo().DefaultContent(); @@ -99,7 +99,7 @@ public void ShouldSwitchToFrameByNameAndBackToDefaultContent() Throws.TypeOf()); driver.SwitchTo().Frame("second"); - Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "2"); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("2")); driver.SwitchTo().DefaultContent(); @@ -115,7 +115,7 @@ public void ShouldSwitchToFrameByIndexAndBackToDefaultContent() driver.Url = framesPage; driver.SwitchTo().Frame(0); - Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "1"); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("1")); driver.SwitchTo().DefaultContent(); @@ -126,7 +126,7 @@ public void ShouldSwitchToFrameByIndexAndBackToDefaultContent() driver.SwitchTo().Frame(1); - Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "2"); + Assert.That(driver.FindElement(By.Id("pageNumber")).Text, Is.EqualTo("2")); driver.SwitchTo().DefaultContent(); diff --git a/dotnet/test/common/TextHandlingTest.cs b/dotnet/test/common/TextHandlingTest.cs index f087f1fbd2346..3b66fe86dd2c4 100644 --- a/dotnet/test/common/TextHandlingTest.cs +++ b/dotnet/test/common/TextHandlingTest.cs @@ -34,10 +34,10 @@ public void ShouldReturnTheTextContentOfASingleElementWithNoChildren() { driver.Url = simpleTestPage; string selectText = driver.FindElement(By.Id("oneline")).Text; - Assert.AreEqual(selectText, "A single line of text"); + Assert.That(selectText, Is.EqualTo("A single line of text")); string getText = driver.FindElement(By.Id("oneline")).Text; - Assert.AreEqual(getText, "A single line of text"); + Assert.That(getText, Is.EqualTo("A single line of text")); } [Test] @@ -58,9 +58,9 @@ public void ShouldIgnoreScriptElements() IWebElement labelForUsername = driver.FindElement(By.Id("labelforusername")); string text = labelForUsername.Text; - Assert.AreEqual(labelForUsername.FindElements(By.TagName("script")).Count, 1); + Assert.That(labelForUsername.FindElements(By.TagName("script")).Count, Is.EqualTo(1)); Assert.That(text, Does.Not.Contain("document.getElementById")); - Assert.AreEqual(text, "Username:"); + Assert.That(text, Is.EqualTo("Username:")); } [Test] @@ -80,7 +80,7 @@ public void ShouldCollapseMultipleWhitespaceCharactersIntoASingleSpace() driver.Url = (simpleTestPage); string text = driver.FindElement(By.Id("lotsofspaces")).Text; - Assert.AreEqual(text, "This line has lots of spaces."); + Assert.That(text, Is.EqualTo("This line has lots of spaces.")); } [Test] @@ -99,7 +99,7 @@ public void ShouldConvertANonBreakingSpaceIntoANormalSpaceCharacter() driver.Url = (simpleTestPage); string text = driver.FindElement(By.Id("nbsp")).Text; - Assert.AreEqual(text, "This line has a non-breaking space"); + Assert.That(text, Is.EqualTo("This line has a non-breaking space")); } [Test] @@ -109,7 +109,7 @@ public void ShouldNotCollapseANonBreakingSpaces() IWebElement element = driver.FindElement(By.Id("nbspandspaces")); string text = element.Text; - Assert.AreEqual(text, "This line has a non-breaking space and spaces"); + Assert.That(text, Is.EqualTo("This line has a non-breaking space and spaces")); } [Test] @@ -147,7 +147,7 @@ public void HavingInlineElementsShouldNotAffectHowTextIsReturned() { driver.Url = (simpleTestPage); string text = driver.FindElement(By.Id("inline")).Text; - Assert.AreEqual(text, "This line has text within elements that are meant to be displayed inline"); + Assert.That(text, Is.EqualTo("This line has text within elements that are meant to be displayed inline")); } [Test] @@ -156,7 +156,7 @@ public void ShouldReturnTheEntireTextOfInlineElements() driver.Url = (simpleTestPage); string text = driver.FindElement(By.Id("span")).Text; - Assert.AreEqual(text, "An inline element"); + Assert.That(text, Is.EqualTo("An inline element")); } [Test] @@ -195,7 +195,7 @@ public void ShouldBeAbleToSetMoreThanOneLineOfTextInATextArea() textarea.SendKeys(expectedText); string seenText = textarea.GetAttribute("value"); - Assert.AreEqual(expectedText, seenText); + Assert.That(seenText, Is.EqualTo(expectedText)); } [Test] @@ -207,7 +207,7 @@ public void ShouldBeAbleToEnterDatesAfterFillingInOtherValuesFirst() input.SendKeys(expectedValue); string seenValue = input.GetAttribute("value"); - Assert.AreEqual(seenValue, expectedValue); + Assert.That(expectedValue, Is.EqualTo(seenValue)); } [Test] @@ -216,7 +216,7 @@ public void ShouldReturnEmptyStringWhenTextIsOnlySpaces() driver.Url = (xhtmlTestPage); string text = driver.FindElement(By.Id("spaces")).Text; - Assert.AreEqual(text, string.Empty); + Assert.That(text, Is.Empty); } [Test] @@ -225,7 +225,7 @@ public void ShouldReturnEmptyStringWhenTextIsEmpty() driver.Url = (xhtmlTestPage); string text = driver.FindElement(By.Id("empty")).Text; - Assert.AreEqual(text, string.Empty); + Assert.That(text, Is.Empty); } [Test] @@ -234,7 +234,7 @@ public void ShouldReturnEmptyStringWhenTagIsSelfClosing() driver.Url = (xhtmlFormPage); string text = driver.FindElement(By.Id("self-closed")).Text; - Assert.AreEqual(text, string.Empty); + Assert.That(text, Is.Empty); } [Test] @@ -243,7 +243,7 @@ public void ShouldNotTrimSpacesWhenLineWraps() driver.Url = simpleTestPage; string text = driver.FindElement(By.XPath("//table/tbody/tr[1]/td[1]")).Text; - Assert.AreEqual("beforeSpace afterSpace", text); + Assert.That(text, Is.EqualTo("beforeSpace afterSpace")); } [Test] @@ -253,7 +253,7 @@ public void ShouldHandleSiblingBlockLevelElements() string text = driver.FindElement(By.Id("twoblocks")).Text; - Assert.AreEqual("Some text" + NewLine + "Some more text", text); + Assert.That(text, Is.EqualTo("Some text" + NewLine + "Some more text")); } [Test] @@ -263,8 +263,8 @@ public void ShouldHandleNestedBlockLevelElements() string text = driver.FindElement(By.Id("nestedblocks")).Text; - Assert.AreEqual("Cheese" + NewLine + "Some text" + NewLine + "Some more text" + NewLine - + "and also" + NewLine + "Brie", text); + Assert.That(text, Is.EqualTo("Cheese" + NewLine + "Some text" + NewLine + "Some more text" + NewLine + + "and also" + NewLine + "Brie")); } [Test] @@ -274,7 +274,7 @@ public void ShouldHandleWhitespaceInInlineElements() string text = driver.FindElement(By.Id("inlinespan")).Text; - Assert.AreEqual(text, "line has text"); + Assert.That(text, Is.EqualTo("line has text")); } [Test] @@ -305,8 +305,8 @@ public void ShouldOnlyIncludeVisibleText() string empty = driver.FindElement(By.Id("suppressedParagraph")).Text; string explicitText = driver.FindElement(By.Id("outer")).Text; - Assert.AreEqual(string.Empty, empty); - Assert.AreEqual("sub-element that is explicitly visible", explicitText); + Assert.That(empty, Is.Empty); + Assert.That(explicitText, Is.EqualTo("sub-element that is explicitly visible")); } [Test] @@ -326,7 +326,7 @@ public void TextOfAnInputFieldShouldBeEmpty() { driver.Url = formsPage; IWebElement input = driver.FindElement(By.Id("inputWithText")); - Assert.AreEqual(string.Empty, input.Text); + Assert.That(input.Text, Is.Empty); } [Test] @@ -334,7 +334,7 @@ public void TextOfATextAreaShouldBeEqualToItsDefaultText() { driver.Url = formsPage; IWebElement area = driver.FindElement(By.Id("withText")); - Assert.AreEqual("Example text", area.Text); + Assert.That(area.Text, Is.EqualTo("Example text")); } [Test] @@ -345,7 +345,7 @@ public void TextOfATextAreaShouldBeEqualToItsDefaultTextEvenAfterTyping() IWebElement area = driver.FindElement(By.Id("withText")); string oldText = area.Text; area.SendKeys("New Text"); - Assert.AreEqual(oldText, area.Text); + Assert.That(area.Text, Is.EqualTo(oldText)); } [Test] @@ -356,7 +356,7 @@ public void TextOfATextAreaShouldBeEqualToItsDefaultTextEvenAfterChangingTheValu IWebElement area = driver.FindElement(By.Id("withText")); string oldText = area.GetAttribute("value"); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].value = arguments[1]", area, "New Text"); - Assert.AreEqual(oldText, area.Text); + Assert.That(area.Text, Is.EqualTo(oldText)); } [Test] @@ -364,7 +364,7 @@ public void ShouldGetTextWhichIsAValidJSONObject() { driver.Url = simpleTestPage; IWebElement element = driver.FindElement(By.Id("simpleJsonText")); - Assert.AreEqual("{a=\"b\", c=1, d=true}", element.Text); + Assert.That(element.Text, Is.EqualTo("{a=\"b\", c=1, d=true}")); //assertEquals("{a=\"b\", \"c\"=d, e=true, f=\\123\\\\g\\\\\"\"\"\\\'}", element.getText()); } @@ -373,7 +373,7 @@ public void ShouldGetTextWhichIsAValidComplexJSONObject() { driver.Url = simpleTestPage; IWebElement element = driver.FindElement(By.Id("complexJsonText")); - Assert.AreEqual("{a=\"\\\\b\\\\\\\"\'\\\'\"}", element.Text); + Assert.That(element.Text, Is.EqualTo("{a=\"\\\\b\\\\\\\"\'\\\'\"}")); } [Test] @@ -384,11 +384,11 @@ public void ShouldNotReturnLtrMarks() IWebElement element = driver.FindElement(By.Id("EH")).FindElement(By.TagName("nobr")); string text = element.Text; String expected = "Some notes"; - Assert.AreNotSame(8206, (int)text[0], "RTL mark should not be present"); + Assert.That((int)text[0], Is.Not.EqualTo(8206), "RTL mark should not be present"); // Note: If this assertion fails but the content of the strings *looks* the same // it may be because of hidden unicode LTR character being included in the string. // That's the reason for the previous assert. - Assert.Equals(expected, element.Text); + Assert.That(element.Text, Is.EqualTo(expected)); } [Test] @@ -398,7 +398,7 @@ public void ShouldTrimTextWithMultiByteWhitespaces() driver.Url = simpleTestPage; String text = driver.FindElement(By.Id("trimmedSpace")).Text; - Assert.AreEqual("test", text); + Assert.That(text, Is.EqualTo("test")); } [Test] diff --git a/dotnet/test/common/TypingTest.cs b/dotnet/test/common/TypingTest.cs index d2290a210fdc7..55caf6f76cfe0 100644 --- a/dotnet/test/common/TypingTest.cs +++ b/dotnet/test/common/TypingTest.cs @@ -74,7 +74,7 @@ public void ShouldTypeLowerCaseLetters() IWebElement keyReporter = driver.FindElement(By.Id("keyReporter")); keyReporter.SendKeys("abc def"); - Assert.AreEqual("abc def", keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.EqualTo("abc def")); } [Test] @@ -85,7 +85,7 @@ public void ShouldBeAbleToTypeCapitalLetters() IWebElement keyReporter = driver.FindElement(By.Id("keyReporter")); keyReporter.SendKeys("ABC DEF"); - Assert.AreEqual("ABC DEF", keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.EqualTo("ABC DEF")); } [Test] @@ -96,7 +96,7 @@ public void ShouldBeAbleToTypeQuoteMarks() IWebElement keyReporter = driver.FindElement(By.Id("keyReporter")); keyReporter.SendKeys("\""); - Assert.AreEqual("\"", keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.EqualTo("\"")); } [Test] @@ -113,7 +113,7 @@ public void ShouldBeAbleToTypeTheAtCharacter() IWebElement keyReporter = driver.FindElement(By.Id("keyReporter")); keyReporter.SendKeys("@"); - Assert.AreEqual("@", keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.EqualTo("@")); } [Test] @@ -124,7 +124,7 @@ public void ShouldBeAbleToMixUpperAndLowerCaseLetters() IWebElement keyReporter = driver.FindElement(By.Id("keyReporter")); keyReporter.SendKeys("me@eXample.com"); - Assert.AreEqual("me@eXample.com", keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.EqualTo("me@eXample.com")); } [Test] @@ -135,7 +135,7 @@ public void ArrowKeysShouldNotBePrintable() IWebElement keyReporter = driver.FindElement(By.Id("keyReporter")); keyReporter.SendKeys(Keys.ArrowLeft); - Assert.AreEqual(string.Empty, keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.Empty); } [Test] @@ -146,7 +146,7 @@ public void ShouldBeAbleToUseArrowKeys() IWebElement keyReporter = driver.FindElement(By.Id("keyReporter")); keyReporter.SendKeys("Tet" + Keys.ArrowLeft + "s"); - Assert.AreEqual("Test", keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.EqualTo("Test")); } [Test] @@ -158,7 +158,7 @@ public void WillSimulateAKeyUpWhenEnteringTextIntoInputElements() element.SendKeys("I like cheese"); IWebElement result = driver.FindElement(By.Id("result")); - Assert.AreEqual("I like cheese", result.Text); + Assert.That(result.Text, Is.EqualTo("I like cheese")); } [Test] @@ -172,7 +172,7 @@ public void WillSimulateAKeyDownWhenEnteringTextIntoInputElements() IWebElement result = driver.FindElement(By.Id("result")); // Because the key down gets the result before the input element is // filled, we're a letter short here - Assert.AreEqual("I like chees", result.Text); + Assert.That(result.Text, Is.EqualTo("I like chees")); } [Test] @@ -186,7 +186,7 @@ public void WillSimulateAKeyPressWhenEnteringTextIntoInputElements() IWebElement result = driver.FindElement(By.Id("result")); // Because the key down gets the result before the input element is // filled, we're a letter short here - Assert.AreEqual("I like chees", result.Text); + Assert.That(result.Text, Is.EqualTo("I like chees")); } [Test] @@ -198,7 +198,7 @@ public void WillSimulateAKeyUpWhenEnteringTextIntoTextAreas() element.SendKeys("I like cheese"); IWebElement result = driver.FindElement(By.Id("result")); - Assert.AreEqual("I like cheese", result.Text); + Assert.That(result.Text, Is.EqualTo("I like cheese")); } [Test] @@ -212,7 +212,7 @@ public void WillSimulateAKeyDownWhenEnteringTextIntoTextAreas() IWebElement result = driver.FindElement(By.Id("result")); // Because the key down gets the result before the input element is // filled, we're a letter short here - Assert.AreEqual("I like chees", result.Text); + Assert.That(result.Text, Is.EqualTo("I like chees")); } [Test] @@ -226,7 +226,7 @@ public void WillSimulateAKeyPressWhenEnteringTextIntoTextAreas() IWebElement result = driver.FindElement(By.Id("result")); // Because the key down gets the result before the input element is // filled, we're a letter short here - Assert.AreEqual("I like chees", result.Text); + Assert.That(result.Text, Is.EqualTo("I like chees")); } [Test] @@ -238,7 +238,7 @@ public void ShouldFireFocusKeyEventsInTheRightOrder() IWebElement element = driver.FindElement(By.Id("theworks")); element.SendKeys("a"); - Assert.AreEqual("focus keydown keypress keyup", result.Text.Trim()); + Assert.That(result.Text.Trim(), Is.EqualTo("focus keydown keypress keyup")); } [Test] @@ -262,7 +262,7 @@ public void ShouldReportKeyCodeOfArrowKeys() CheckRecordedKeySequence(result, 39); // And leave no rubbish/printable keys in the "keyReporter" - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); } [Test] @@ -294,7 +294,7 @@ public void ShouldReportKeyCodeOfArrowKeysUpDownEvents() Assert.That(text, Does.Contain("up: 39")); // And leave no rubbish/printable keys in the "keyReporter" - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); } [Test] @@ -307,7 +307,7 @@ public void NumericNonShiftKeys() string numericLineCharsNonShifted = "`1234567890-=[]\\;,.'/42"; element.SendKeys(numericLineCharsNonShifted); - Assert.AreEqual(numericLineCharsNonShifted, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo(numericLineCharsNonShifted)); } [Test] @@ -322,7 +322,7 @@ public void NumericShiftKeys() string numericShiftsEtc = "~!@#$%^&*()_+{}:\"<>?|END~"; element.SendKeys(numericShiftsEtc); - Assert.AreEqual(numericShiftsEtc, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo(numericShiftsEtc)); string text = result.Text.Trim(); Assert.That(text, Does.Contain(" up: 16")); } @@ -337,7 +337,7 @@ public void LowerCaseAlphaKeys() String lowerAlphas = "abcdefghijklmnopqrstuvwxyz"; element.SendKeys(lowerAlphas); - Assert.AreEqual(lowerAlphas, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo(lowerAlphas)); } [Test] @@ -352,7 +352,7 @@ public void UppercaseAlphaKeys() String upperAlphas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; element.SendKeys(upperAlphas); - Assert.AreEqual(upperAlphas, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo(upperAlphas)); string text = result.Text.Trim(); Assert.That(text, Does.Contain(" up: 16")); } @@ -371,7 +371,7 @@ public void AllPrintableKeys() "PQRSTUVWXYZ [\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; element.SendKeys(allPrintable); - Assert.AreEqual(allPrintable, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo(allPrintable)); string text = result.Text.Trim(); Assert.That(text, Does.Contain(" up: 16")); } @@ -385,7 +385,7 @@ public void ArrowKeysAndPageUpAndDown() element.SendKeys("a" + Keys.Left + "b" + Keys.Right + Keys.Up + Keys.Down + Keys.PageUp + Keys.PageDown + "1"); - Assert.AreEqual("ba1", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("ba1")); } [Test] @@ -399,7 +399,7 @@ public void HomeAndEndAndPageUpAndPageDownKeys() element.SendKeys("abc" + HomeKey() + "0" + Keys.Left + Keys.Right + Keys.PageUp + Keys.PageDown + EndKey() + "1" + HomeKey() + "0" + Keys.PageUp + EndKey() + "111" + HomeKey() + "00"); - Assert.AreEqual("0000abc1111", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("0000abc1111")); } [Test] @@ -410,13 +410,13 @@ public void DeleteAndBackspaceKeys() IWebElement element = driver.FindElement(By.Id("keyReporter")); element.SendKeys("abcdefghi"); - Assert.AreEqual("abcdefghi", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("abcdefghi")); element.SendKeys(Keys.Left + Keys.Left + Keys.Delete); - Assert.AreEqual("abcdefgi", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("abcdefgi")); element.SendKeys(Keys.Left + Keys.Left + Keys.Backspace); - Assert.AreEqual("abcdfgi", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("abcdfgi")); } [Test] @@ -427,7 +427,7 @@ public void SpecialSpaceKeys() IWebElement element = driver.FindElement(By.Id("keyReporter")); element.SendKeys("abcd" + Keys.Space + "fgh" + Keys.Space + "ij"); - Assert.AreEqual("abcd fgh ij", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("abcd fgh ij")); } [Test] @@ -441,7 +441,7 @@ public void NumberpadKeys() Keys.Decimal + Keys.Separator + Keys.NumberPad0 + Keys.NumberPad9 + Keys.Add + Keys.Semicolon + Keys.Equal + Keys.Divide + Keys.NumberPad3 + "abcd"); - Assert.AreEqual("abcd*-+.,09+;=/3abcd", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("abcd*-+.,09+;=/3abcd")); } [Test] @@ -453,7 +453,7 @@ public void FunctionKeys() element.SendKeys("FUNCTION" + Keys.F8 + "-KEYS" + Keys.F8); element.SendKeys("" + Keys.F8 + "-TOO" + Keys.F8); - Assert.AreEqual("FUNCTION-KEYS-TOO", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("FUNCTION-KEYS-TOO")); } [Test] @@ -464,12 +464,12 @@ public void ShiftSelectionDeletes() IWebElement element = driver.FindElement(By.Id("keyReporter")); element.SendKeys("abcd efgh"); - Assert.AreEqual(element.GetAttribute("value"), "abcd efgh"); + Assert.That(element.GetAttribute("value"), Is.EqualTo("abcd efgh")); //Could be chord problem element.SendKeys(Keys.Shift + Keys.Left + Keys.Left + Keys.Left); element.SendKeys(Keys.Delete); - Assert.AreEqual("abcd e", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("abcd e")); } [Test] @@ -486,7 +486,7 @@ public void ChordControlHomeShiftEndDelete() element.SendKeys(HomeKey()); element.SendKeys("" + Keys.Shift + EndKey() + Keys.Delete); - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); string text = result.Text.Trim(); Assert.That(text, Does.Contain(" up: 16")); } @@ -501,22 +501,22 @@ public void ChordReverseShiftHomeSelectionDeletes() IWebElement element = driver.FindElement(By.Id("keyReporter")); element.SendKeys("done" + HomeKey()); - Assert.AreEqual("done", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("done")); //Sending chords element.SendKeys("" + Keys.Shift + "ALL " + HomeKey()); - Assert.AreEqual("ALL done", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("ALL done")); element.SendKeys(Keys.Delete); - Assert.AreEqual("done", element.GetAttribute("value"), "done"); + Assert.That(element.GetAttribute("value"), Is.EqualTo("done"), "done"); element.SendKeys("" + EndKey() + Keys.Shift + HomeKey()); - Assert.AreEqual("done", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("done")); // Note: trailing SHIFT up here string text = result.Text.Trim(); element.SendKeys("" + Keys.Delete); - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); } [Test] @@ -529,31 +529,31 @@ public void ChordControlCutAndPaste() String paste = "!\"#$%&'()*+,-./0123456789:;<=>?@ ABCDEFG"; element.SendKeys(paste); - Assert.AreEqual(paste, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo(paste)); //Chords element.SendKeys("" + HomeKey() + Keys.Shift + EndKey()); element.SendKeys(PrimaryModifier() + "x"); - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); element.SendKeys(PrimaryModifier() + "v"); - Assert.AreEqual(paste, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo(paste)); element.SendKeys("" + Keys.Left + Keys.Left + Keys.Left + Keys.Shift + EndKey()); element.SendKeys(PrimaryModifier() + "x" + "v"); - Assert.AreEqual(paste, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo(paste)); element.SendKeys(HomeKey()); element.SendKeys(PrimaryModifier() + "v"); element.SendKeys(PrimaryModifier() + "v" + "v"); element.SendKeys(PrimaryModifier() + "v" + "v" + "v"); - Assert.AreEqual("EFGEFGEFGEFGEFGEFG" + paste, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("EFGEFGEFGEFGEFGEFG" + paste)); element.SendKeys("" + EndKey() + Keys.Shift + HomeKey() + Keys.Null + Keys.Delete); - Assert.AreEqual(element.GetAttribute("value"), string.Empty); + Assert.That(element.GetAttribute("value"), Is.Empty); } [Test] @@ -564,7 +564,7 @@ public void ShouldTypeIntoInputElementsThatHaveNoTypeAttribute() IWebElement element = driver.FindElement(By.Id("no-type")); element.SendKeys("Should Say Cheese"); - Assert.AreEqual("Should Say Cheese", element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.EqualTo("Should Say Cheese")); } [Test] @@ -575,7 +575,7 @@ public void ShouldNotTypeIntoElementsThatPreventKeyDownEvents() IWebElement silent = driver.FindElement(By.Name("suppress")); silent.SendKeys("s"); - Assert.AreEqual(string.Empty, silent.GetAttribute("value")); + Assert.That(silent.GetAttribute("value"), Is.Empty); } [Test] @@ -596,7 +596,7 @@ public void ShouldBeAbleToTypeOnAnEmailInputField() driver.Url = formsPage; IWebElement email = driver.FindElement(By.Id("email")); email.SendKeys("foobar"); - Assert.AreEqual("foobar", email.GetAttribute("value")); + Assert.That(email.GetAttribute("value"), Is.EqualTo("foobar")); } [Test] @@ -605,7 +605,7 @@ public void ShouldBeAbleToTypeOnANumberInputField() driver.Url = formsPage; IWebElement numberElement = driver.FindElement(By.Id("age")); numberElement.SendKeys("33"); - Assert.AreEqual("33", numberElement.GetAttribute("value")); + Assert.That(numberElement.GetAttribute("value"), Is.EqualTo("33")); } [Test] @@ -624,11 +624,11 @@ public void CanSafelyTypeOnElementThatIsRemovedFromTheDomOnKeyPress() IWebElement input = driver.FindElement(By.Id("target")); IWebElement log = driver.FindElement(By.Id("log")); - Assert.AreEqual("", log.GetAttribute("value")); + Assert.That(log.GetAttribute("value"), Is.EqualTo("")); input.SendKeys("b"); string expected = "keydown (target)\nkeyup (target)\nkeyup (body)"; - Assert.AreEqual(expected, GetValueText(log)); + Assert.That(GetValueText(log), Is.EqualTo(expected)); input.SendKeys("a"); @@ -647,7 +647,7 @@ public void CanClearNumberInputAfterTypingInvalidInput() input.SendKeys("e"); input.Clear(); input.SendKeys("3"); - Assert.AreEqual("3", input.GetAttribute("value")); + Assert.That(input.GetAttribute("value"), Is.EqualTo("3")); } //------------------------------------------------------------------ @@ -684,7 +684,7 @@ public void NonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet() element.SendKeys("Dishy" + Keys.Backspace + Keys.Left + Keys.Left); element.SendKeys(Keys.Left + Keys.Left + "F" + Keys.Delete + EndKey() + "ee!"); - Assert.AreEqual(element.Text, "Fishee!"); + Assert.That(element.Text, Is.EqualTo("Fishee!")); } [Test] @@ -696,7 +696,7 @@ public void ShouldBeAbleToTypeIntoEmptyContentEditableElement() editable.Clear(); editable.SendKeys("cheese"); // requires focus on OS X - Assert.AreEqual("cheese", editable.Text); + Assert.That(editable.Text, Is.EqualTo("cheese")); } [Test] @@ -711,7 +711,7 @@ public void ShouldBeAbleToTypeIntoContentEditableElementWithExistingValue() string initialText = editable.Text; editable.SendKeys(", edited"); - Assert.AreEqual(initialText + ", edited", editable.Text); + Assert.That(editable.Text, Is.EqualTo(initialText + ", edited")); } [Test] @@ -726,7 +726,7 @@ public void ShouldBeAbleToTypeIntoTinyMCE() editable.Clear(); editable.SendKeys("cheese"); // requires focus on OS X - Assert.AreEqual("cheese", editable.Text); + Assert.That(editable.Text, Is.EqualTo("cheese")); } private string GetValueText(IWebElement el) diff --git a/dotnet/test/common/UploadTest.cs b/dotnet/test/common/UploadTest.cs index c83363c2a7b98..5608e1e5d2747 100644 --- a/dotnet/test/common/UploadTest.cs +++ b/dotnet/test/common/UploadTest.cs @@ -69,7 +69,7 @@ public void CleanFileInput() IWebElement element = driver.FindElement(By.Id("upload")); element.SendKeys(testFile.FullName); element.Clear(); - Assert.AreEqual(string.Empty, element.GetAttribute("value")); + Assert.That(element.GetAttribute("value"), Is.Empty); } [Test] diff --git a/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs b/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs index c46d541dcb548..fdfa743d4a51f 100644 --- a/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs +++ b/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs @@ -170,12 +170,12 @@ public void ShouldCreateAuthenticator() object response = jsDriver.ExecuteAsyncScript( "registerCredential().then(arguments[arguments.length - 1]);"); - Assert.AreEqual("OK", ((Dictionary)response)["status"]); + Assert.That((Dictionary)response, Does.ContainKey("status").WithValue("OK")); object assertionResponse = GetAssertionFor(ExtractRawIdFrom(response)); // Attempt to use the credential to get an assertion. - Assert.AreEqual("OK", ((Dictionary)assertionResponse)["status"]); + Assert.That((Dictionary)assertionResponse, Does.ContainKey("status").WithValue("OK")); } [Test] @@ -191,7 +191,7 @@ public void ShouldRemoveAuthenticator() webDriver.RemoveVirtualAuthenticator(authenticatorId); - Assert.IsNull(webDriver.AuthenticatorId); + Assert.That(webDriver.AuthenticatorId, Is.Null); } [Test] @@ -211,7 +211,7 @@ public void ShouldSupportMultipleVirtualAuthenticatorsAtOnce() webDriver.RemoveVirtualAuthenticator(authenticatorId1); webDriver.RemoveVirtualAuthenticator(authenticatorId2); - Assert.IsNull(webDriver.AuthenticatorId); + Assert.That(webDriver.AuthenticatorId, Is.Null); } [Test] @@ -236,7 +236,7 @@ public void ShouldAddNonResidentCredential() // Attempt to use the credential to generate an assertion. object response = GetAssertionFor(id); - Assert.AreEqual("OK", ((Dictionary)response)["status"]); + Assert.That((Dictionary)response, Does.ContainKey("status").WithValue("OK")); } [Test] @@ -268,7 +268,7 @@ public void ShouldAddNonResidentCredentialWhenAuthenticatorUsesU2FProtocol() // Attempt to use the credential to generate an assertion. object response = GetAssertionFor(id); - Assert.AreEqual("OK", ((Dictionary)response)["status"]); + Assert.That((Dictionary)response, Does.ContainKey("status").WithValue("OK")); } [Test] @@ -292,14 +292,14 @@ public void ShouldAddResidentCredential() // empty allowCredentials array. object response = jsDriver.ExecuteAsyncScript( "getCredential([]).then(arguments[arguments.length - 1]);"); - Assert.AreEqual("OK", ((Dictionary)response)["status"]); + Assert.That(((Dictionary)response)["status"], Is.EqualTo("OK")); Dictionary attestation = (Dictionary)((Dictionary)response)["attestation"]; ReadOnlyCollection returnedUserHandle = (ReadOnlyCollection)attestation["userHandle"]; - Assert.AreEqual(1, returnedUserHandle.Count); - Assert.AreEqual(0, returnedUserHandle.IndexOf(1L)); + Assert.That(returnedUserHandle, Has.One.Items); + Assert.That(returnedUserHandle.IndexOf(1L), Is.Zero); } [Test] @@ -341,21 +341,21 @@ public void ShouldGetCredential() object response1 = jsDriver.ExecuteAsyncScript( "registerCredential({authenticatorSelection: {requireResidentKey: true}})" + " .then(arguments[arguments.length - 1]);"); - Assert.AreEqual("OK", ((Dictionary)response1)["status"]); + Assert.That((Dictionary)response1, Does.ContainKey("status").WithValue("OK")); // Register a non resident credential. object response2 = jsDriver.ExecuteAsyncScript( "registerCredential().then(arguments[arguments.length - 1]);"); - Assert.AreEqual("OK", ((Dictionary)response2)["status"]); + Assert.That((Dictionary)response2, Does.ContainKey("status").WithValue("OK")); byte[] credential1Id = ConvertListIntoArrayOfBytes(ExtractRawIdFrom(response1)); byte[] credential2Id = ConvertListIntoArrayOfBytes(ExtractRawIdFrom(response2)); - Assert.AreNotEqual(credential1Id, credential2Id); + Assert.That(credential2Id, Is.Not.EqualTo(credential1Id)); // Retrieve the two credentials. List credentials = webDriver.GetCredentials(); - Assert.AreEqual(2, credentials.Count); + Assert.That(credentials, Has.Exactly(2).Items); Credential credential1 = null; Credential credential2 = null; @@ -375,11 +375,11 @@ public void ShouldGetCredential() } } - Assert.True(credential1.IsResidentCredential); - Assert.NotNull(credential1.PrivateKey); + Assert.That(credential1.IsResidentCredential, Is.True); + Assert.That(credential1.PrivateKey, Is.Not.Null); - Assert.False(credential2.IsResidentCredential); - Assert.NotNull(credential2.PrivateKey); + Assert.That(credential2.IsResidentCredential, Is.False); + Assert.That(credential2.PrivateKey, Is.Not.Null); } [Test] @@ -395,7 +395,7 @@ public void ShouldRemoveCredentialByRawId() object response = jsDriver.ExecuteAsyncScript( "registerCredential().then(arguments[arguments.length - 1]);"); - Assert.AreEqual("OK", ((Dictionary)response)["status"]); + Assert.That((Dictionary)response, Does.ContainKey("status").WithValue("OK")); // Remove a credential by its ID as an array of bytes. List rawId = ExtractRawIdFrom(response); @@ -406,7 +406,7 @@ public void ShouldRemoveCredentialByRawId() object assertionResponse = GetAssertionFor(rawId); string error = (string)((Dictionary)assertionResponse)["status"]; - Assert.True(error.StartsWith("NotAllowedError")); + Assert.That(error, Does.StartWith("NotAllowedError")); } [Test] @@ -422,7 +422,7 @@ public void ShouldRemoveCredentialByBase64UrlId() object response = jsDriver.ExecuteAsyncScript( "registerCredential().then(arguments[arguments.length - 1]);"); - Assert.AreEqual("OK", ((Dictionary)response)["status"]); + Assert.That((Dictionary)response, Does.ContainKey("status").WithValue("OK")); // Remove a credential by its base64url ID. String credentialId = ExtractIdFrom(response); @@ -432,7 +432,7 @@ public void ShouldRemoveCredentialByBase64UrlId() object assertionResponse = GetAssertionFor(credentialId); string error = (string)((Dictionary)assertionResponse)["status"]; - Assert.True(error.StartsWith("NotAllowedError")); + Assert.That(error, Does.StartWith("NotAllowedError")); } [Test] @@ -447,12 +447,12 @@ public void ShouldRemoveAllCredentials() // Register two credentials. object response1 = jsDriver.ExecuteAsyncScript( "registerCredential().then(arguments[arguments.length - 1]);"); - Assert.AreEqual("OK", ((Dictionary)response1)["status"]); + Assert.That((Dictionary)response1, Does.ContainKey("status").WithValue("OK")); List rawId1 = ExtractRawIdFrom(response1); object response2 = jsDriver.ExecuteAsyncScript( "registerCredential().then(arguments[arguments.length - 1]);"); - Assert.AreEqual("OK", ((Dictionary)response2)["status"]); + Assert.That((Dictionary)response2, Does.ContainKey("status").WithValue("OK")); List rawId2 = ExtractRawIdFrom(response1); // Remove all credentials. @@ -471,7 +471,7 @@ public void ShouldRemoveAllCredentials() string error = (string)((Dictionary)response)["status"]; - Assert.True(error.StartsWith("NotAllowedError")); + Assert.That(error, Does.StartWith("NotAllowedError")); } [Test] @@ -487,7 +487,7 @@ public void testSetUserVerified() Object response = jsDriver.ExecuteAsyncScript( "registerCredential({authenticatorSelection: {userVerification: 'required'}})" + " .then(arguments[arguments.length - 1]);"); - Assert.AreEqual("OK", ((Dictionary)response)["status"]); + Assert.That((Dictionary)response, Does.ContainKey("status").WithValue("OK")); List rawId = ExtractRawIdFrom(response); // Getting an assertion requiring user verification should succeed. @@ -497,7 +497,7 @@ public void testSetUserVerified() + " \"id\": Int8Array.from(arguments[0])," + "}], {userVerification: 'required'}).then(arguments[arguments.length - 1]);", rawId); - Assert.AreEqual("OK", ((Dictionary)response)["status"]); + Assert.That((Dictionary)response, Does.ContainKey("status").WithValue("OK")); // Disable user verification. webDriver.SetUserVerified(false); @@ -512,7 +512,7 @@ public void testSetUserVerified() string error = (string)((Dictionary)response)["status"]; - Assert.True(error.StartsWith("NotAllowedError")); + Assert.That(error, Does.StartWith("NotAllowedError")); } [Test] diff --git a/dotnet/test/common/VisibilityTest.cs b/dotnet/test/common/VisibilityTest.cs index a48e785e95f8b..527699e6d8f88 100644 --- a/dotnet/test/common/VisibilityTest.cs +++ b/dotnet/test/common/VisibilityTest.cs @@ -111,8 +111,8 @@ public void ZeroSizedDivIsShownIfDescendantHasSize() IWebElement element = driver.FindElement(By.Id("zero")); Size size = element.Size; - Assert.AreEqual(0, size.Width, "Should have 0 width"); - Assert.AreEqual(0, size.Height, "Should have 0 height"); + Assert.That(size.Width, Is.Zero, "Should have 0 width"); + Assert.That(size.Height, Is.Zero, "Should have 0 height"); Assert.That(element.Displayed, Is.True); } @@ -268,9 +268,9 @@ public void ShouldBeAbleToClickOnElementsWithOpacityZero() driver.Url = clickJackerPage; IWebElement element = driver.FindElement(By.Id("clickJacker")); - Assert.AreEqual("0", element.GetCssValue("opacity"), "Precondition failed: clickJacker should be transparent"); + Assert.That(element.GetCssValue("opacity"), Is.EqualTo("0"), "Precondition failed: clickJacker should be transparent"); element.Click(); - Assert.AreEqual("1", element.GetCssValue("opacity")); + Assert.That(element.GetCssValue("opacity"), Is.EqualTo("1")); } [Test] diff --git a/dotnet/test/common/WebElementTest.cs b/dotnet/test/common/WebElementTest.cs index 5da1ec406f1be..9fcf68ee1b0f4 100644 --- a/dotnet/test/common/WebElementTest.cs +++ b/dotnet/test/common/WebElementTest.cs @@ -68,7 +68,7 @@ public void ShouldGetElementName() driver.Url = simpleTestPage; IWebElement oneliner = driver.FindElement(By.Id("oneline")); - Assert.AreEqual("p", oneliner.TagName.ToLower()); + Assert.That(oneliner.TagName, Is.EqualTo("p").IgnoreCase); } @@ -78,12 +78,12 @@ public void ShouldGetElementText() driver.Url = simpleTestPage; IWebElement oneliner = driver.FindElement(By.Id("oneline")); - Assert.AreEqual("A single line of text", oneliner.Text); + Assert.That(oneliner.Text, Is.EqualTo("A single line of text")); IWebElement twoblocks = driver.FindElement(By.Id("twoblocks")); - Assert.AreEqual("Some text" + + Assert.That(twoblocks.Text, Is.EqualTo("Some text" + System.Environment.NewLine + - "Some more text", twoblocks.Text); + "Some more text")); } @@ -110,7 +110,7 @@ public void ShouldClearElement() IWebElement textbox = driver.FindElement(By.Id("keyUp")); textbox.SendKeys("a@#$ç.ó"); textbox.Clear(); - Assert.AreEqual("", textbox.GetAttribute("value")); + Assert.That(textbox.GetAttribute("value"), Is.Empty); } [Test] @@ -121,7 +121,7 @@ public void ShouldClearRenderedElement() IWebElement textbox = driver.FindElement(By.Id("keyUp")); textbox.SendKeys("a@#$ç.ó"); textbox.Clear(); - Assert.AreEqual("", textbox.GetAttribute("value")); + Assert.That(textbox.GetAttribute("value"), Is.Empty); } [Test] @@ -131,7 +131,7 @@ public void ShouldSendKeysToElement() IWebElement textbox = driver.FindElement(By.Id("keyUp")); textbox.SendKeys("a@#$ç.ó"); - Assert.AreEqual("a@#$ç.ó", textbox.GetAttribute("value")); + Assert.That(textbox.GetAttribute("value"), Is.EqualTo("a@#$ç.ó")); } [Test] @@ -152,7 +152,7 @@ public void ShouldClickLinkElement() IWebElement changedDiv = driver.FindElement(By.Id("dynamo")); IWebElement link = driver.FindElement(By.LinkText("Update a div")); link.Click(); - Assert.AreEqual("Fish and chips!", changedDiv.Text); + Assert.That(changedDiv.Text, Is.EqualTo("Fish and chips!")); } [Test] @@ -162,8 +162,8 @@ public void ShouldGetAttributesFromElement() IWebElement dynamo = driver.FindElement(By.Id("dynamo")); IWebElement mousedown = driver.FindElement(By.Id("mousedown")); - Assert.AreEqual("mousedown", mousedown.GetAttribute("id")); - Assert.AreEqual("dynamo", dynamo.GetAttribute("id")); + Assert.That(mousedown.GetAttribute("id"), Is.EqualTo("mousedown")); + Assert.That(dynamo.GetAttribute("id"), Is.EqualTo("dynamo")); } } diff --git a/dotnet/test/common/WindowSwitchingTest.cs b/dotnet/test/common/WindowSwitchingTest.cs index ab153b8377a50..9128351111f67 100644 --- a/dotnet/test/common/WindowSwitchingTest.cs +++ b/dotnet/test/common/WindowSwitchingTest.cs @@ -36,23 +36,23 @@ public void ShouldSwitchFocusToANewWindowWhenItIsOpenedAndNotStopFutureOperation String current = driver.CurrentWindowHandle; driver.FindElement(By.LinkText("Open new window")).Click(); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); WaitFor(WindowCountToBe(2), "Window count was not 2"); WaitFor(WindowWithName("result"), "Could not find window with name 'result'"); WaitFor(() => { return driver.Title == "We Arrive Here"; }, "Browser title was not 'We Arrive Here'"); - Assert.AreEqual("We Arrive Here", driver.Title); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); driver.Url = iframesPage; string handle = driver.CurrentWindowHandle; driver.FindElement(By.Id("iframe_page_heading")); driver.SwitchTo().Frame("iframe1"); - Assert.AreEqual(driver.CurrentWindowHandle, handle); + Assert.That(handle, Is.EqualTo(driver.CurrentWindowHandle)); driver.SwitchTo().DefaultContent(); driver.Close(); driver.SwitchTo().Window(current); - //Assert.AreEqual("XHTML Test Page", driver.Title); + //Assert.That(driver.Title, Is.EqualTo("TML Test Page")); } [Test] @@ -79,7 +79,7 @@ public void ShouldThrowNoSuchWindowExceptionOnAnAttemptToGetItsHandle() driver.FindElement(By.LinkText("Open new window")).Click(); WaitFor(WindowCountToBe(2), "Window count was not 2"); - Assert.AreEqual(2, driver.WindowHandles.Count); + Assert.That(driver.WindowHandles, Has.Exactly(2).Items); WaitFor(WindowWithName("result"), "Could not find window with name 'result'"); driver.SwitchTo().Window("result"); @@ -108,7 +108,7 @@ public void ShouldThrowNoSuchWindowExceptionOnAnyOperationIfAWindowIsClosed() driver.FindElement(By.LinkText("Open new window")).Click(); WaitFor(WindowCountToBe(2), "Window count was not 2"); - Assert.AreEqual(2, driver.WindowHandles.Count); + Assert.That(driver.WindowHandles, Has.Exactly(2).Items); WaitFor(WindowWithName("result"), "Could not find window with name 'result'"); driver.SwitchTo().Window("result"); @@ -141,7 +141,7 @@ public void ShouldThrowNoSuchWindowExceptionOnAnyElementOperationIfAWindowIsClos driver.FindElement(By.LinkText("Open new window")).Click(); WaitFor(WindowCountToBe(2), "Window count was not 2"); - Assert.AreEqual(2, driver.WindowHandles.Count); + Assert.That(driver.WindowHandles, Has.Exactly(2).Items); WaitFor(WindowWithName("result"), "Could not find window with name 'result'"); driver.SwitchTo().Window("result"); @@ -182,7 +182,7 @@ public void ShouldBeAbleToIterateOverAllOpenWindows() seenHandles.Add(handle); } - Assert.AreEqual(3, allWindowHandles.Count); + Assert.That(allWindowHandles, Has.Exactly(3).Items); } [Test] @@ -265,7 +265,7 @@ public void FailingToSwitchToAWindowLeavesTheCurrentWindowAsIs() String newHandle = driver.CurrentWindowHandle; - Assert.AreEqual(current, newHandle); + Assert.That(newHandle, Is.EqualTo(current)); } [Test] @@ -281,7 +281,7 @@ public void CanCloseWindowWhenMultipleWindowsAreOpen() ReadOnlyCollection allWindowHandles = driver.WindowHandles; // There should be two windows. We should also see each of the window titles at least once. - Assert.AreEqual(2, allWindowHandles.Count); + Assert.That(allWindowHandles, Has.Exactly(2).Items); string handle1 = allWindowHandles[1]; driver.SwitchTo().Window(handle1); driver.Close(); @@ -289,7 +289,7 @@ public void CanCloseWindowWhenMultipleWindowsAreOpen() WaitFor(WindowCountToBe(1), "Window count was not 1"); allWindowHandles = driver.WindowHandles; - Assert.AreEqual(1, allWindowHandles.Count); + Assert.That(allWindowHandles, Has.One.Items); } [Test] @@ -309,7 +309,7 @@ public void CanCloseWindowAndSwitchBackToMainWindow() ReadOnlyCollection allWindowHandles = driver.WindowHandles; // There should be two windows. We should also see each of the window titles at least once. - Assert.AreEqual(2, allWindowHandles.Count); + Assert.That(allWindowHandles, Has.Exactly(2).Items); foreach (string handle in allWindowHandles) { @@ -323,9 +323,9 @@ public void CanCloseWindowAndSwitchBackToMainWindow() driver.SwitchTo().Window(mainHandle); string newHandle = driver.CurrentWindowHandle; - Assert.AreEqual(mainHandle, newHandle); + Assert.That(newHandle, Is.EqualTo(mainHandle)); - Assert.AreEqual(1, driver.WindowHandles.Count); + Assert.That(driver.WindowHandles, Has.One.Items); } [Test] @@ -381,8 +381,8 @@ public void ShouldGetBrowserHandles() ReadOnlyCollection handles = driver.WindowHandles; // At least the two handles we want should be there. - Assert.Contains(handle1, handles, "Should have contained current handle"); - Assert.Contains(handle2, handles, "Should have contained result handle"); + Assert.That(handles, Does.Contain(handle1), "Should have contained current handle"); + Assert.That(handles, Does.Contain(handle2), "Should have contained result handle"); // Some (semi-)clean up.. driver.SwitchTo().Window(handle2); diff --git a/dotnet/test/common/WindowTest.cs b/dotnet/test/common/WindowTest.cs index ac8fd10128444..29110bc0439d7 100644 --- a/dotnet/test/common/WindowTest.cs +++ b/dotnet/test/common/WindowTest.cs @@ -60,8 +60,8 @@ public void ShouldBeAbleToSetTheSizeOfTheCurrentWindow() ChangeSizeBy(-20, -20); Size newSize = window.Size; - Assert.AreEqual(targetSize.Width, newSize.Width); - Assert.AreEqual(targetSize.Height, newSize.Height); + Assert.That(newSize.Width, Is.EqualTo(targetSize.Width)); + Assert.That(newSize.Height, Is.EqualTo(targetSize.Height)); } [Test] @@ -80,8 +80,8 @@ public void ShouldBeAbleToSetTheSizeOfTheCurrentWindowFromFrame() Size newSize = window.Size; - Assert.AreEqual(targetSize.Width, newSize.Width); - Assert.AreEqual(targetSize.Height, newSize.Height); + Assert.That(newSize.Width, Is.EqualTo(targetSize.Width)); + Assert.That(newSize.Height, Is.EqualTo(targetSize.Height)); } finally { @@ -105,8 +105,8 @@ public void ShouldBeAbleToSetTheSizeOfTheCurrentWindowFromIFrame() Size newSize = window.Size; - Assert.AreEqual(targetSize.Width, newSize.Width); - Assert.AreEqual(targetSize.Height, newSize.Height); + Assert.That(newSize.Width, Is.EqualTo(targetSize.Width)); + Assert.That(newSize.Height, Is.EqualTo(targetSize.Height)); } finally { @@ -134,8 +134,8 @@ public void ShouldBeAbleToSetThePositionOfTheCurrentWindow() Point newLocation = window.Position; - Assert.AreEqual(targetPosition.X, newLocation.X); - Assert.AreEqual(targetPosition.Y, newLocation.Y); + Assert.That(newLocation.X, Is.EqualTo(targetPosition.X)); + Assert.That(newLocation.Y, Is.EqualTo(targetPosition.Y)); } [Test] diff --git a/dotnet/test/firefox/FirefoxDriverTest.cs b/dotnet/test/firefox/FirefoxDriverTest.cs index 0ea48610a235a..bf897c5ac49d6 100644 --- a/dotnet/test/firefox/FirefoxDriverTest.cs +++ b/dotnet/test/firefox/FirefoxDriverTest.cs @@ -64,7 +64,7 @@ public void ShouldWaitUntilBrowserHasClosedProperly() textarea.SendKeys(expectedText); string seenText = textarea.GetAttribute("value"); - Assert.AreEqual(expectedText, seenText); + Assert.That(seenText, Is.EqualTo(expectedText)); } //[Test] @@ -75,8 +75,8 @@ public void ShouldBeAbleToStartMoreThanOneInstanceOfTheFirefoxDriverSimultaneous driver.Url = xhtmlTestPage; secondDriver.Url = formsPage; - Assert.AreEqual("XHTML Test Page", driver.Title); - Assert.AreEqual("We Leave From Here", secondDriver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); + Assert.That(secondDriver.Title, Is.EqualTo("We Leave From Here")); // We only need to quit the second driver if the test passes secondDriver.Quit(); @@ -109,7 +109,7 @@ public void ShouldRemoveProfileAfterExit() string profileLocation = profile.ProfileDirectory; firefox.Quit(); - Assert.IsFalse(Directory.Exists(profileLocation)); + Assert.That(profileLocation, Does.Not.Exist); } //[Test] @@ -133,7 +133,7 @@ public void FocusRemainsInOriginalWindowWhenOpeningNewWindow() IWebElement keyReporter = driver.FindElement(By.Id("keyReporter")); keyReporter.SendKeys("ABC DEF"); - Assert.AreEqual("ABC DEF", keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.EqualTo("ABC DEF")); } //[Test] @@ -157,7 +157,7 @@ public void SwitchingWindowShouldSwitchFocus() List allWindowHandles = new List(driver.WindowHandles); // There should be two windows. We should also see each of the window titles at least once. - Assert.AreEqual(2, allWindowHandles.Count); + Assert.That(allWindowHandles, Has.Exactly(2).Items); allWindowHandles.Remove(originalWinHandle); string newWinHandle = (string)allWindowHandles[0]; @@ -169,7 +169,7 @@ public void SwitchingWindowShouldSwitchFocus() IWebElement keyReporter = driver.FindElement(By.Id("keyReporter")); keyReporter.SendKeys("ABC DEF"); - Assert.AreEqual("ABC DEF", keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.EqualTo("ABC DEF")); // Key events in original window. driver.SwitchTo().Window(originalWinHandle); @@ -178,7 +178,7 @@ public void SwitchingWindowShouldSwitchFocus() IWebElement keyReporter2 = driver.FindElement(By.Id("keyReporter")); keyReporter2.SendKeys("QWERTY"); - Assert.AreEqual("QWERTY", keyReporter2.GetAttribute("value")); + Assert.That(keyReporter2.GetAttribute("value"), Is.EqualTo("QWERTY")); } //[Test] @@ -199,7 +199,7 @@ public void ClosingWindowAndSwitchingToOriginalSwitchesFocus() SleepBecauseWindowsTakeTimeToOpen(); List allWindowHandles = new List(driver.WindowHandles); // There should be two windows. We should also see each of the window titles at least once. - Assert.AreEqual(2, allWindowHandles.Count); + Assert.That(allWindowHandles, Has.Exactly(2).Items); allWindowHandles.Remove(originalWinHandle); string newWinHandle = (string)allWindowHandles[0]; @@ -217,7 +217,7 @@ public void ClosingWindowAndSwitchingToOriginalSwitchesFocus() driver.Url = javascriptPage; IWebElement keyReporter = driver.FindElement(By.Id("keyReporter")); keyReporter.SendKeys("ABC DEF"); - Assert.AreEqual("ABC DEF", keyReporter.GetAttribute("value")); + Assert.That(keyReporter.GetAttribute("value"), Is.EqualTo("ABC DEF")); } //[Test] @@ -234,7 +234,7 @@ public void CanBlockInvalidSslCertificates() secondDriver = new FirefoxDriver(options); secondDriver.Url = url; string gotTitle = secondDriver.Title; - Assert.AreNotEqual("Hello IWebDriver", gotTitle); + Assert.That(gotTitle, Is.EqualTo("Hello IWebDriver")); } catch (Exception) { @@ -263,7 +263,7 @@ public void ShouldAllowUserToSuccessfullyOverrideTheHomePage() try { - Assert.AreEqual(javascriptPage, driver2.Url); + Assert.That(driver2.Url, Is.EqualTo(javascriptPage)); } finally { diff --git a/dotnet/test/firefox/FirefoxProfileManagerTest.cs b/dotnet/test/firefox/FirefoxProfileManagerTest.cs index 82833b3e7c035..649241074440f 100644 --- a/dotnet/test/firefox/FirefoxProfileManagerTest.cs +++ b/dotnet/test/firefox/FirefoxProfileManagerTest.cs @@ -36,28 +36,28 @@ public void SetUp() public void ShouldGetNamedProfile() { FirefoxProfile profile = manager.GetProfile("default"); - Assert.IsNotNull(profile); + Assert.That(profile, Is.Not.Null); } //[Test] public void ShouldReturnNullForInvalidProfileName() { FirefoxProfile profile = manager.GetProfile("ThisIsMyBogusProfileName"); - Assert.IsNull(profile); + Assert.That(profile, Is.Null); } //[Test] public void ShouldReturnNullForNullProfileName() { FirefoxProfile profile = manager.GetProfile(null); - Assert.IsNull(profile); + Assert.That(profile, Is.Null); } //[Test] public void ShouldReturnNullForEmptyProfileName() { FirefoxProfile profile = manager.GetProfile(string.Empty); - Assert.IsNull(profile); + Assert.That(profile, Is.Null); } } } diff --git a/dotnet/test/firefox/FirefoxProfileTests.cs b/dotnet/test/firefox/FirefoxProfileTests.cs index 3cc64fd2220fc..3b1b89cdbd5b8 100644 --- a/dotnet/test/firefox/FirefoxProfileTests.cs +++ b/dotnet/test/firefox/FirefoxProfileTests.cs @@ -54,7 +54,7 @@ public void ShouldQuoteStringsWhenSettingStringProperties() break; } } - Assert.IsTrue(seenCheese); + Assert.That(seenCheese, Is.True); } //[Test] @@ -72,7 +72,7 @@ public void ShouldSetIntegerPreferences() break; } } - Assert.IsTrue(seenCheese, "Did not see integer value being set correctly"); + Assert.That(seenCheese, Is.True, "Did not see integer value being set correctly"); } //[Test] @@ -90,7 +90,7 @@ public void testShouldSetBooleanPreferences() } } - Assert.IsTrue(seenCheese, "Did not see boolean value being set correctly"); + Assert.That(seenCheese, Is.True, "Did not see boolean value being set correctly"); } private List ReadGeneratedProperties() diff --git a/dotnet/test/ie/IeSpecificTests.cs b/dotnet/test/ie/IeSpecificTests.cs index 444bf96096765..0158c19158f98 100644 --- a/dotnet/test/ie/IeSpecificTests.cs +++ b/dotnet/test/ie/IeSpecificTests.cs @@ -118,7 +118,7 @@ public void KeysTest() } } - Assert.IsTrue(passed, errors); + Assert.That(passed, errors); } //[Test] @@ -140,7 +140,7 @@ public void ScrollingFrameTest() WaitFor(FrameToExistAndBeSwitchedTo("scrolling_frame"), "No frame with name or id 'scrolling_frame' found"); IWebElement element = driver.FindElement(By.Name("scroll_checkbox")); element.Click(); - Assert.IsTrue(element.Selected); + Assert.That(element.Selected); driver.SwitchTo().DefaultContent(); @@ -148,7 +148,7 @@ public void ScrollingFrameTest() WaitFor(FrameToExistAndBeSwitchedTo("scrolling_frame"), "No frame with name or id 'scrolling_frame' found"); element = driver.FindElement(By.Name("scroll_checkbox")); element.Click(); - Assert.IsTrue(element.Selected); + Assert.That(element.Selected); } finally { @@ -176,11 +176,11 @@ public void ShouldBeAbleToBrowseTransformedXml() driver.FindElement(By.Id("x")).Click(); // Sleep is required; driver may not be fast enough after this Click(). System.Threading.Thread.Sleep(2000); - Assert.AreEqual("XHTML Test Page", driver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); // Act on the result page to make sure the window handling is still valid. driver.FindElement(By.Id("linkId")).Click(); - Assert.AreEqual("We Arrive Here", driver.Title); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); } //[Test] @@ -191,8 +191,8 @@ public void ShouldBeAbleToStartMoreThanOneInstanceOfTheIEDriverSimultaneously() driver.Url = xhtmlTestPage; secondDriver.Url = formsPage; - Assert.AreEqual("XHTML Test Page", driver.Title); - Assert.AreEqual("We Leave From Here", secondDriver.Title); + Assert.That(driver.Title, Is.EqualTo("XHTML Test Page")); + Assert.That(secondDriver.Title, Is.EqualTo("We Arrive Here")); // We only need to quit the second driver if the test passes secondDriver.Quit(); @@ -212,7 +212,7 @@ public void ShouldPropagateSessionCookies() string bodyStyle = driver.FindElement(By.TagName("body")).GetAttribute("style"); driver.Close(); driver.SwitchTo().Window(startWindow); - Assert.IsTrue(bodyStyle.Contains("BACKGROUND-COLOR: #80ffff") || bodyStyle.Contains("background-color: rgb(128, 255, 255)")); + Assert.That(bodyStyle, Does.Contain("BACKGROUND-COLOR: #80ffff").Or.Contain("background-color: rgb(128, 255, 255)")); } //[Test] @@ -226,7 +226,7 @@ public void ShouldHandleShowModalDialogWindows() WaitFor(() => { return driver.WindowHandles.Count > 1; }, "Window count was not greater than 1"); ReadOnlyCollection windowHandles = driver.WindowHandles; - Assert.AreEqual(2, windowHandles.Count); + Assert.That(windowHandles, Has.Exactly(2).Items); string dialogHandle = string.Empty; foreach (string handle in windowHandles) @@ -238,7 +238,7 @@ public void ShouldHandleShowModalDialogWindows() } } - Assert.AreNotEqual(string.Empty, dialogHandle); + Assert.That(dialogHandle, Is.Not.Empty); driver.SwitchTo().Window(dialogHandle); IWebElement closeElement = driver.FindElement(By.Id("close")); @@ -247,7 +247,7 @@ public void ShouldHandleShowModalDialogWindows() WaitFor(() => { return driver.WindowHandles.Count == 1; }, "Window count was not 1"); windowHandles = driver.WindowHandles; - Assert.AreEqual(1, windowHandles.Count); + Assert.That(windowHandles, Has.One.Items); driver.SwitchTo().Window(originalWindowHandle); } @@ -256,9 +256,9 @@ public void ScrollTest() { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("scroll.html"); driver.FindElement(By.Id("line8")).Click(); - Assert.AreEqual("line8", driver.FindElement(By.Id("clicked")).Text); + Assert.That(driver.FindElement(By.Id("clicked")).Text, Is.EqualTo("line8")); driver.FindElement(By.Id("line1")).Click(); - Assert.AreEqual("line1", driver.FindElement(By.Id("clicked")).Text); + Assert.That(driver.FindElement(By.Id("clicked")).Text, Is.EqualTo("line1")); } //[Test] @@ -268,7 +268,7 @@ public void ShouldNotScrollOverflowElementsWhichAreVisible() var list = driver.FindElement(By.TagName("ul")); var item = list.FindElement(By.Id("desired")); item.Click(); - Assert.AreEqual(0, ((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].scrollTop;", list), "Should not have scrolled"); + Assert.That(((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].scrollTop;", list), Is.Zero, "Should not have scrolled"); } //[Test] @@ -278,7 +278,7 @@ public void ShouldNotScrollIfAlreadyScrolledAndElementIsInView() driver.FindElement(By.Id("button1")).Click(); var scrollTop = GetScrollTop(); driver.FindElement(By.Id("button2")).Click(); - Assert.AreEqual(scrollTop, GetScrollTop()); + Assert.That(GetScrollTop(), Is.EqualTo(scrollTop)); } //[Test] @@ -293,7 +293,7 @@ public void ShouldBeAbleToHandleCascadingModalDialogs() ReadOnlyCollection windows = driver.WindowHandles; string firstWindowHandle = windows.Except(new List() { parentHandle }).First(); driver.SwitchTo().Window(firstWindowHandle); - Assert.AreEqual(2, windows.Count); + Assert.That(windows, Has.Exactly(2).Items); // Launch second modal driver.FindElement(By.CssSelector("input[type='button'][value='btn2']")).Click(); @@ -301,14 +301,14 @@ public void ShouldBeAbleToHandleCascadingModalDialogs() ReadOnlyCollection windows_1 = driver.WindowHandles; string secondWindowHandle = windows_1.Except(windows).First(); driver.SwitchTo().Window(secondWindowHandle); - Assert.AreEqual(3, windows_1.Count); + Assert.That(windows_1, Has.Exactly(3).Items); // Launch third modal driver.FindElement(By.CssSelector("input[type='button'][value='btn3']")).Click(); WaitFor(() => { return driver.WindowHandles.Count > 3; }, "Window count was not greater than 3"); ReadOnlyCollection windows_2 = driver.WindowHandles; string finalWindowHandle = windows_2.Except(windows_1).First(); - Assert.AreEqual(4, windows_2.Count); + Assert.That(windows_2, Has.Exactly(4).Items); driver.SwitchTo().Window(finalWindowHandle).Close(); driver.SwitchTo().Window(secondWindowHandle).Close(); @@ -328,7 +328,7 @@ public void ShouldBeAbleToHandleCascadingModalDialogsLaunchedWithJavaScriptLinks ReadOnlyCollection windows = driver.WindowHandles; string firstWindowHandle = windows.Except(new List() { parentHandle }).First(); driver.SwitchTo().Window(firstWindowHandle); - Assert.AreEqual(2, windows.Count); + Assert.That(windows, Has.Exactly(2).Items); // Launch second modal driver.FindElement(By.CssSelector("a[id='lnk2']")).Click(); @@ -337,14 +337,14 @@ public void ShouldBeAbleToHandleCascadingModalDialogsLaunchedWithJavaScriptLinks ReadOnlyCollection windows_1 = driver.WindowHandles; string secondWindowHandle = windows_1.Except(windows).First(); driver.SwitchTo().Window(secondWindowHandle); - Assert.AreEqual(3, windows_1.Count); + Assert.That(windows_1, Has.Exactly(3).Items); // Launch third modal driver.FindElement(By.CssSelector("a[id='lnk3']")).Click(); WaitFor(() => { return driver.WindowHandles.Count > 3; }, "Window count was not greater than 3"); ReadOnlyCollection windows_2 = driver.WindowHandles; string finalWindowHandle = windows_2.Except(windows_1).First(); - Assert.AreEqual(4, windows_2.Count); + Assert.That(windows_2, Has.Exactly(4).Items); driver.SwitchTo().Window(finalWindowHandle).Close(); driver.SwitchTo().Window(secondWindowHandle).Close(); diff --git a/dotnet/test/remote/RemoteSessionCreationTests.cs b/dotnet/test/remote/RemoteSessionCreationTests.cs index 685b234cd1b57..a194c3e96d5ad 100644 --- a/dotnet/test/remote/RemoteSessionCreationTests.cs +++ b/dotnet/test/remote/RemoteSessionCreationTests.cs @@ -34,7 +34,7 @@ public void CreateChromeRemoteSession() chrome.Url = xhtmlTestPage; try { - Assert.AreEqual("XHTML Test Page", chrome.Title); + Assert.That(chrome.Title, Is.EqualTo("XHTML Test Page")); } finally { @@ -49,7 +49,7 @@ public void CreateFirefoxRemoteSession() firefox.Url = xhtmlTestPage; try { - Assert.AreEqual("XHTML Test Page", firefox.Title); + Assert.That(firefox.Title, Is.EqualTo("XHTML Test Page")); } finally { @@ -64,7 +64,7 @@ public void CreateEdgeRemoteSession() edge.Url = xhtmlTestPage; try { - Assert.AreEqual("XHTML Test Page", edge.Title); + Assert.That(edge.Title, Is.EqualTo("XHTML Test Page")); } finally { diff --git a/dotnet/test/remote/RemoteWebDriverSpecificTests.cs b/dotnet/test/remote/RemoteWebDriverSpecificTests.cs index 1462f4cbc8a9e..cb23945359c36 100644 --- a/dotnet/test/remote/RemoteWebDriverSpecificTests.cs +++ b/dotnet/test/remote/RemoteWebDriverSpecificTests.cs @@ -75,7 +75,7 @@ public void ShouldBeAbleToSendFileToRemoteServer() driver.SwitchTo().Frame("upload_target"); IWebElement body = driver.FindElement(By.XPath("//body")); - Assert.IsTrue(LoremIpsumText == body.Text, "Page source is: " + driver.PageSource); + Assert.That(body.Text, Is.EqualTo(LoremIpsumText), "Page source is: " + driver.PageSource); driver.SwitchTo().DefaultContent(); uploadElement = driver.FindElement(By.Id("upload")); Console.WriteLine(uploadElement.Text); diff --git a/dotnet/test/support/Events/EventFiringWebDriverElementTest.cs b/dotnet/test/support/Events/EventFiringWebDriverElementTest.cs index fd668df43d92b..5ed36b705700c 100644 --- a/dotnet/test/support/Events/EventFiringWebDriverElementTest.cs +++ b/dotnet/test/support/Events/EventFiringWebDriverElementTest.cs @@ -37,7 +37,7 @@ public void CanTakeEventFiringWebElementScreenshot() IWebElement element = firingDriver.FindElement(By.Name("checky")); Screenshot screenshot = ((ITakesScreenshot)element).GetScreenshot(); - Assert.IsNotNull(screenshot); + Assert.That(screenshot, Is.Not.Null); } } } diff --git a/dotnet/test/support/Events/EventFiringWebDriverTest.cs b/dotnet/test/support/Events/EventFiringWebDriverTest.cs index 8623c02b5f07a..a062163d83156 100644 --- a/dotnet/test/support/Events/EventFiringWebDriverTest.cs +++ b/dotnet/test/support/Events/EventFiringWebDriverTest.cs @@ -85,7 +85,7 @@ Navigated forward mockNavigation.Verify(x => x.ForwardAsync(), Times.Once); string normalizedActualLog = log.ToString().Replace("\r\n", "\n").Replace("\r", "\n"); - Assert.AreEqual(normalizedExpectedLog, normalizedActualLog); + Assert.That(normalizedActualLog, Is.EqualTo(normalizedExpectedLog)); } [Test] @@ -103,7 +103,7 @@ public void ShouldFireClickEvent() string expectedLog = @"Clicking Clicked "; - Assert.AreEqual(expectedLog, log.ToString()); + Assert.That(log.ToString(), Is.EqualTo(expectedLog)); } [Test] @@ -126,7 +126,7 @@ public void ShouldFireValueChangedEvent() ValueChanging 'Dummy Text' ValueChanged 'Dummy Text' "; - Assert.AreEqual(expectedLog, log.ToString()); + Assert.That(log.ToString(), Is.EqualTo(expectedLog)); } [Test] @@ -138,7 +138,7 @@ public void ElementsCanEqual() var element1 = firingDriver.FindElement(By.Id("foo")); var element2 = firingDriver.FindElement(By.Id("foo")); - Assert.AreEqual(element1, element2); + Assert.That(element2, Is.EqualTo(element1)); } [Test] @@ -172,7 +172,7 @@ public void ShouldFireFindByEvent() FindElementCompleted from IWebDriver By.XPath: //link[@type = 'text/css'] "; - Assert.AreEqual(expectedLog, log.ToString()); + Assert.That(log.ToString(), Is.EqualTo(expectedLog)); } [Test] @@ -194,7 +194,7 @@ public void ShouldCallListenerOnException() // Fine } - Assert.IsTrue(log.ToString().Contains(exception.Message)); + Assert.That(log.ToString(), Does.Contain(exception.Message)); } [Test] @@ -231,7 +231,7 @@ public void ShouldBeAbleToAccessWrappedInstanceFromEventCalls() stubDriver = new StubDriver(); EventFiringWebDriver testDriver = new EventFiringWebDriver(stubDriver); StubDriver wrapped = ((IWrapsDriver)testDriver).WrappedDriver as StubDriver; - Assert.AreEqual(stubDriver, wrapped); + Assert.That(wrapped, Is.EqualTo(stubDriver)); testDriver.Navigating += new EventHandler(testDriver_Navigating); testDriver.Url = "http://example.org"; @@ -253,13 +253,13 @@ public void ShouldFireGetShadowRootEvents() // act abcElement.GetShadowRoot(); - Assert.IsNotNull(gettingShadowRootArgs); - Assert.AreEqual(mockDriver.Object, gettingShadowRootArgs.Driver); - Assert.AreEqual(mockElement.Object, gettingShadowRootArgs.SearchContext); + Assert.That(gettingShadowRootArgs, Is.Not.Null); + Assert.That(gettingShadowRootArgs.Driver, Is.EqualTo(mockDriver.Object)); + Assert.That(gettingShadowRootArgs.SearchContext, Is.EqualTo(mockElement.Object)); - Assert.IsNotNull(getShadowRootCompletedArgs); - Assert.AreEqual(mockDriver.Object, getShadowRootCompletedArgs.Driver); - Assert.AreEqual(mockElement.Object, getShadowRootCompletedArgs.SearchContext); + Assert.That(getShadowRootCompletedArgs, Is.Not.Null); + Assert.That(getShadowRootCompletedArgs.Driver, Is.EqualTo(mockDriver.Object)); + Assert.That(getShadowRootCompletedArgs.SearchContext, Is.EqualTo(mockElement.Object)); } [Test] @@ -281,18 +281,18 @@ public void ShouldFireFindEventsInShadowRoot() // act var element = shadowRoot.FindElement(By.CssSelector(".abc")); - Assert.IsNotNull(findingElementArgs); - Assert.AreEqual(mockDriver.Object, findingElementArgs.Driver); - Assert.AreEqual(null, findingElementArgs.Element); + Assert.That(findingElementArgs, Is.Not.Null); + Assert.That(findingElementArgs.Driver, Is.EqualTo(mockDriver.Object)); + Assert.That(findingElementArgs.Element, Is.Null); - Assert.IsNotNull(findElementCompletedArgs); - Assert.AreEqual(mockDriver.Object, findElementCompletedArgs.Driver); - Assert.AreEqual(null, findElementCompletedArgs.Element); + Assert.That(findElementCompletedArgs, Is.Not.Null); + Assert.That(findElementCompletedArgs.Driver, Is.EqualTo(mockDriver.Object)); + Assert.That(findElementCompletedArgs.Element, Is.Null); } void testDriver_Navigating(object sender, WebDriverNavigationEventArgs e) { - Assert.AreEqual(e.Driver, stubDriver); + Assert.That(stubDriver, Is.EqualTo(e.Driver)); } void firingDriver_ExceptionThrown(object sender, WebDriverExceptionEventArgs e) diff --git a/dotnet/test/support/UI/DefaultWaitTest.cs b/dotnet/test/support/UI/DefaultWaitTest.cs index 311123a2032eb..6da08aa208ce9 100644 --- a/dotnet/test/support/UI/DefaultWaitTest.cs +++ b/dotnet/test/support/UI/DefaultWaitTest.cs @@ -55,7 +55,7 @@ public void ShouldWaitUntilReturnValueOfConditionIsNotNull() wait.PollingInterval = TimeSpan.FromSeconds(2); wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(NoSuchFrameException)); - Assert.AreEqual(defaultReturnValue, wait.Until(condition)); + Assert.That(wait.Until(condition), Is.EqualTo(defaultReturnValue)); } [Test] @@ -71,7 +71,7 @@ public void ShouldWaitUntilABooleanResultIsTrue() wait.PollingInterval = TimeSpan.FromSeconds(2); wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(NoSuchFrameException)); - Assert.IsTrue(wait.Until(condition)); + Assert.That(wait.Until(condition), Is.True); } [Test] @@ -102,7 +102,7 @@ public void CanIgnoreMultipleExceptions() wait.PollingInterval = TimeSpan.FromSeconds(2); wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(NoSuchFrameException)); - Assert.AreEqual(defaultReturnValue, wait.Until(condition)); + Assert.That(wait.Until(condition), Is.EqualTo(defaultReturnValue)); } [Test] @@ -119,10 +119,10 @@ public void PropagatesUnIgnoredExceptions() wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(NoSuchFrameException)); var caughtException = Assert.Throws(() => wait.Until(condition)); - Assert.AreSame(ex, caughtException); + Assert.That(caughtException, Is.SameAs(ex)); // Regression test for issue #6343 - StringAssert.Contains("NonInlineableThrow", caughtException.StackTrace, "the stack trace must include the call to NonInlineableThrow()"); + Assert.That(caughtException.StackTrace, Does.Contain("NonInlineableThrow"), "the stack trace must include the call to NonInlineableThrow()"); } [Test] @@ -139,7 +139,7 @@ public void TimeoutMessageIncludesLastIgnoredException() wait.IgnoreExceptionTypes(typeof(NoSuchWindowException)); var caughtException = Assert.Throws(() => wait.Until(condition)); - Assert.AreSame(ex, caughtException.InnerException); + Assert.That(caughtException.InnerException, Is.SameAs(ex)); } [Test] diff --git a/dotnet/test/support/UI/LoadableComponentTests.cs b/dotnet/test/support/UI/LoadableComponentTests.cs index cd86498113cbd..3416532ad6638 100644 --- a/dotnet/test/support/UI/LoadableComponentTests.cs +++ b/dotnet/test/support/UI/LoadableComponentTests.cs @@ -45,7 +45,7 @@ public void ShouldCauseTheLoadMethodToBeCalledIfTheComponentIsNotAlreadyLoaded() ok.Load(); - Assert.True(ok.WasLoadCalled()); + Assert.That(ok.WasLoadCalled(), Is.True); } [Test] @@ -60,7 +60,7 @@ public void ShouldThrowAnErrorIfCallingLoadDoesNotCauseTheComponentToLoad() } catch (LoadableComponentException e) { - Assert.AreEqual("Expected failure", e.Message); + Assert.That(e.Message, Is.EqualTo("Expected failure")); } } @@ -75,8 +75,8 @@ public void ShouldCallHandleLoadErrorWhenWebDriverExceptionOccursDuringExecuteLo } catch (Exception e) { - Assert.AreEqual("HandleLoadError called", e.Message); - Assert.AreEqual("Excpected failure in ExecuteLoad", e.InnerException.Message); + Assert.That(e.Message, Is.EqualTo("HandleLoadError called")); + Assert.That(e.InnerException.Message, Is.EqualTo("Excpected failure in ExecuteLoad")); } } diff --git a/dotnet/test/support/UI/PopupWindowFinderTest.cs b/dotnet/test/support/UI/PopupWindowFinderTest.cs index 692fa8d19e1bb..ac9f805083fd0 100644 --- a/dotnet/test/support/UI/PopupWindowFinderTest.cs +++ b/dotnet/test/support/UI/PopupWindowFinderTest.cs @@ -49,11 +49,11 @@ public void ShouldFindPopupWindowUsingAction() PopupWindowFinder finder = new PopupWindowFinder(driver); string newHandle = finder.Invoke(() => { driver.FindElement(By.LinkText("Open new window")).Click(); }); - Assert.That(newHandle, Is.Not.Null.Or.Empty); - Assert.AreNotEqual(current, newHandle); + Assert.That(newHandle, Is.Not.Null.And.Not.Empty); + Assert.That(newHandle, Is.Not.EqualTo(current)); driver.SwitchTo().Window(newHandle); - Assert.AreEqual("We Arrive Here", driver.Title); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); driver.Close(); driver.SwitchTo().Window(current); @@ -68,11 +68,11 @@ public void ShouldFindPopupWindowUsingElementClick() PopupWindowFinder finder = new PopupWindowFinder(driver); string newHandle = finder.Click(driver.FindElement(By.LinkText("Open new window"))); - Assert.That(newHandle, Is.Not.Null.Or.Empty); - Assert.AreNotEqual(current, newHandle); + Assert.That(newHandle, Is.Not.Null.And.Not.Empty); + Assert.That(newHandle, Is.Not.EqualTo(current)); driver.SwitchTo().Window(newHandle); - Assert.AreEqual("We Arrive Here", driver.Title); + Assert.That(driver.Title, Is.EqualTo("We Arrive Here")); driver.Close(); driver.SwitchTo().Window(current); @@ -86,14 +86,14 @@ public void ShouldFindMultiplePopupWindowsInSuccession() PopupWindowFinder finder = new PopupWindowFinder(driver); string second = finder.Click(driver.FindElement(By.Name("windowOne"))); - Assert.That(second, Is.Not.Null.Or.Empty); - Assert.AreNotEqual(first, second); + Assert.That(second, Is.Not.Null.And.Not.Empty); + Assert.That(second, Is.Not.EqualTo(first)); finder = new PopupWindowFinder(driver); string third = finder.Click(driver.FindElement(By.Name("windowTwo"))); - Assert.That(third, Is.Not.Null.Or.Empty); - Assert.AreNotEqual(first, third); - Assert.AreNotEqual(second, third); + Assert.That(third, Is.Not.Null.And.Not.Empty); + Assert.That(third, Is.Not.EqualTo(first)); + Assert.That(third, Is.Not.EqualTo(second)); driver.SwitchTo().Window(second); driver.Close(); @@ -109,7 +109,9 @@ public void ShouldNotFindPopupWindowWhenNoneExists() { driver.Url = xhtmlTestPage; PopupWindowFinder finder = new PopupWindowFinder(driver); - Assert.Throws(() => { string handle = finder.Click(driver.FindElement(By.Id("linkId"))); }); + Assert.That( + () => finder.Click(driver.FindElement(By.Id("linkId"))), + Throws.TypeOf()); } } } diff --git a/dotnet/test/support/UI/SelectBrowserTests.cs b/dotnet/test/support/UI/SelectBrowserTests.cs index fc835d96a4596..3978627f37073 100644 --- a/dotnet/test/support/UI/SelectBrowserTests.cs +++ b/dotnet/test/support/UI/SelectBrowserTests.cs @@ -51,7 +51,9 @@ public void Setup() public void ShouldThrowAnExceptionIfTheElementIsNotASelectElement() { IWebElement element = driver.FindElement(By.Name("checky")); - Assert.Throws(() => { SelectElement elementWrapper = new SelectElement(element); }); + Assert.That( + () => new SelectElement(element), + Throws.TypeOf()); } [Test] @@ -59,7 +61,7 @@ public void ShouldIndicateThatASelectCanSupportMultipleOptions() { IWebElement element = driver.FindElement(By.Name("multi")); SelectElement elementWrapper = new SelectElement(element); - Assert.IsTrue(elementWrapper.IsMultiple); + Assert.That(elementWrapper.IsMultiple, Is.True); } [Test] @@ -67,7 +69,7 @@ public void ShouldIndicateThatASelectCanSupportMultipleOptionsWithEmptyMultipleA { IWebElement element = driver.FindElement(By.Name("select_empty_multiple")); SelectElement elementWrapper = new SelectElement(element); - Assert.IsTrue(elementWrapper.IsMultiple); + Assert.That(elementWrapper.IsMultiple, Is.True); } [Test] @@ -75,7 +77,7 @@ public void ShouldIndicateThatASelectCanSupportMultipleOptionsWithTrueMultipleAt { IWebElement element = driver.FindElement(By.Name("multi_true")); SelectElement elementWrapper = new SelectElement(element); - Assert.IsTrue(elementWrapper.IsMultiple); + Assert.That(elementWrapper.IsMultiple, Is.True); } [Test] @@ -83,7 +85,7 @@ public void ShouldNotIndicateThatANormalSelectSupportsMulitpleOptions() { IWebElement element = driver.FindElement(By.Name("selectomatic")); SelectElement elementWrapper = new SelectElement(element); - Assert.IsFalse(elementWrapper.IsMultiple); + Assert.That(elementWrapper.IsMultiple, Is.False); } [Test] @@ -91,7 +93,7 @@ public void ShouldIndicateThatASelectCanSupportMultipleOptionsWithFalseMultipleA { IWebElement element = driver.FindElement(By.Name("multi_false")); SelectElement elementWrapper = new SelectElement(element); - Assert.IsTrue(elementWrapper.IsMultiple); + Assert.That(elementWrapper.IsMultiple, Is.True); } [Test] @@ -101,19 +103,19 @@ public void ShouldReturnAllOptionsWhenAsked() SelectElement elementWrapper = new SelectElement(element); IList returnedOptions = elementWrapper.Options; - Assert.AreEqual(4, returnedOptions.Count); + Assert.That(returnedOptions, Has.Exactly(4).Items); string one = returnedOptions[0].Text; - Assert.AreEqual("One", one); + Assert.That(one, Is.EqualTo("One")); string two = returnedOptions[1].Text; - Assert.AreEqual("Two", two); + Assert.That(two, Is.EqualTo("Two")); string three = returnedOptions[2].Text; - Assert.AreEqual("Four", three); + Assert.That(three, Is.EqualTo("Four")); string four = returnedOptions[3].Text; - Assert.AreEqual("Still learning how to count, apparently", four); + Assert.That(four, Is.EqualTo("Still learning how to count, apparently")); } @@ -125,10 +127,10 @@ public void ShouldReturnOptionWhichIsSelected() IList returnedOptions = elementWrapper.AllSelectedOptions; - Assert.AreEqual(1, returnedOptions.Count); + Assert.That(returnedOptions, Has.One.Items); string one = returnedOptions[0].Text; - Assert.AreEqual("One", one); + Assert.That(one, Is.EqualTo("One")); } [Test] @@ -139,13 +141,13 @@ public void ShouldReturnOptionsWhichAreSelected() IList returnedOptions = elementWrapper.AllSelectedOptions; - Assert.AreEqual(2, returnedOptions.Count); + Assert.That(returnedOptions, Has.Exactly(2).Items); string one = returnedOptions[0].Text; - Assert.AreEqual("Eggs", one); + Assert.That(one, Is.EqualTo("Eggs")); string two = returnedOptions[1].Text; - Assert.AreEqual("Sausages", two); + Assert.That(two, Is.EqualTo("Sausages")); } [Test] @@ -156,7 +158,7 @@ public void ShouldReturnFirstSelectedOption() IWebElement firstSelected = elementWrapper.AllSelectedOptions[0]; - Assert.AreEqual("Eggs", firstSelected.Text); + Assert.That(firstSelected.Text, Is.EqualTo("Eggs")); } // [Test] @@ -169,7 +171,7 @@ public void ShouldThrowANoSuchElementExceptionIfNothingIsSelected() IWebElement element = driver.FindElement(By.Name("select_empty_multiple")); SelectElement elementWrapper = new SelectElement(element); - Assert.AreEqual(0, elementWrapper.AllSelectedOptions.Count); + Assert.That(elementWrapper.AllSelectedOptions.Count, Is.Zero); } [Test] @@ -179,7 +181,7 @@ public void ShouldAllowOptionsToBeSelectedByVisibleText() SelectElement elementWrapper = new SelectElement(element); elementWrapper.SelectByText("select_2"); IWebElement firstSelected = elementWrapper.AllSelectedOptions[0]; - Assert.AreEqual("select_2", firstSelected.Text); + Assert.That(firstSelected.Text, Is.EqualTo("select_2")); } [Test] @@ -189,7 +191,7 @@ public void ShouldAllowOptionsToBeSelectedByPartialText() SelectElement elementWrapper = new SelectElement(element); elementWrapper.SelectByText("4", true); IWebElement firstSelected = elementWrapper.AllSelectedOptions[0]; - Assert.AreEqual("select_4", firstSelected.Text); + Assert.That(firstSelected.Text, Is.EqualTo("select_4")); } [Test] @@ -197,7 +199,9 @@ public void ShouldThrowExceptionOnSelectByTextExactMatchIfOptionDoesNotExist() { IWebElement element = driver.FindElement(By.Name("select_empty_multiple")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.SelectByText("4")); + Assert.That( + () => elementWrapper.SelectByText("4"), + Throws.TypeOf()); } [Test] @@ -206,7 +210,9 @@ public void ShouldNotAllowInvisibleOptionsToBeSelectedByVisibleText() { IWebElement element = driver.FindElement(By.Name("invisi_select")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.SelectByText("Apples")); + Assert.That( + () => elementWrapper.SelectByText("Apples"), + Throws.TypeOf()); } [Test] @@ -214,7 +220,9 @@ public void ShouldThrowExceptionOnSelectByVisibleTextIfOptionDoesNotExist() { IWebElement element = driver.FindElement(By.Name("select_empty_multiple")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.SelectByText("not there")); + Assert.That( + () => elementWrapper.SelectByText("not there"), + Throws.TypeOf()); } [Test] @@ -222,7 +230,9 @@ public void ShouldThrowExceptionOnSelectByVisibleTextIfOptionDisabled() { IWebElement element = driver.FindElement(By.Name("single_disabled")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.SelectByText("Disabled")); + Assert.That( + () => elementWrapper.SelectByText("Disabled"), + Throws.TypeOf()); } [Test] @@ -232,7 +242,7 @@ public void ShouldAllowOptionsToBeSelectedByIndex() SelectElement elementWrapper = new SelectElement(element); elementWrapper.SelectByIndex(1); IWebElement firstSelected = elementWrapper.AllSelectedOptions[0]; - Assert.AreEqual("select_2", firstSelected.Text); + Assert.That(firstSelected.Text, Is.EqualTo("select_2")); } [Test] @@ -240,7 +250,9 @@ public void ShouldThrowExceptionOnSelectByIndexIfOptionDoesNotExist() { IWebElement element = driver.FindElement(By.Name("select_empty_multiple")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.SelectByIndex(10)); + Assert.That( + () => elementWrapper.SelectByIndex(10), + Throws.TypeOf()); } [Test] @@ -248,7 +260,9 @@ public void ShouldThrowExceptionOnSelectByIndexIfOptionDisabled() { IWebElement element = driver.FindElement(By.Name("single_disabled")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.SelectByIndex(1)); + Assert.That( + () => elementWrapper.SelectByIndex(1), + Throws.InvalidOperationException); } [Test] @@ -258,7 +272,7 @@ public void ShouldAllowOptionsToBeSelectedByReturnedValue() SelectElement elementWrapper = new SelectElement(element); elementWrapper.SelectByValue("select_2"); IWebElement firstSelected = elementWrapper.AllSelectedOptions[0]; - Assert.AreEqual("select_2", firstSelected.Text); + Assert.That(firstSelected.Text, Is.EqualTo("select_2")); } [Test] @@ -266,7 +280,9 @@ public void ShouldThrowExceptionOnSelectByReturnedValueIfOptionDoesNotExist() { IWebElement element = driver.FindElement(By.Name("select_empty_multiple")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.SelectByValue("not there")); + Assert.That( + () => elementWrapper.SelectByValue("not there"), + Throws.TypeOf()); } [Test] @@ -274,7 +290,9 @@ public void ShouldThrowExceptionOnSelectByReturnedValueIfOptionDisabled() { IWebElement element = driver.FindElement(By.Name("single_disabled")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.SelectByValue("disabled")); + Assert.That( + () => elementWrapper.SelectByValue("disabled"), + Throws.InvalidOperationException); } [Test] @@ -285,7 +303,7 @@ public void ShouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections() elementWrapper.DeselectAll(); IList returnedOptions = elementWrapper.AllSelectedOptions; - Assert.AreEqual(0, returnedOptions.Count); + Assert.That(returnedOptions, Is.Empty); } [Test] @@ -293,7 +311,9 @@ public void ShouldNotAllowUserToDeselectAllWhenSelectDoesNotSupportMultipleSelec { IWebElement element = driver.FindElement(By.Name("selectomatic")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.DeselectAll()); + Assert.That( + () => elementWrapper.DeselectAll(), + Throws.InvalidOperationException); } [Test] @@ -304,7 +324,7 @@ public void ShouldAllowUserToDeselectOptionsByVisibleText() elementWrapper.DeselectByText("Eggs"); IList returnedOptions = elementWrapper.AllSelectedOptions; - Assert.AreEqual(1, returnedOptions.Count); + Assert.That(returnedOptions.Count, Is.EqualTo(1)); } [Test] @@ -313,7 +333,9 @@ public void ShouldNotAllowUserToDeselectOptionsByInvisibleText() { IWebElement element = driver.FindElement(By.Name("invisi_select")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.DeselectByText("Apples")); + Assert.That( + () => elementWrapper.DeselectByText("Apples"), + Throws.TypeOf()); } [Test] @@ -324,7 +346,7 @@ public void ShouldAllowOptionsToBeDeselectedByIndex() elementWrapper.DeselectByIndex(0); IList returnedOptions = elementWrapper.AllSelectedOptions; - Assert.AreEqual(1, returnedOptions.Count); + Assert.That(returnedOptions.Count, Is.EqualTo(1)); } [Test] @@ -335,7 +357,7 @@ public void ShouldAllowOptionsToBeDeselectedByReturnedValue() elementWrapper.DeselectByValue("eggs"); IList returnedOptions = elementWrapper.AllSelectedOptions; - Assert.AreEqual(1, returnedOptions.Count); + Assert.That(returnedOptions.Count, Is.EqualTo(1)); } [Test] @@ -343,7 +365,9 @@ public void ShouldThrowExceptionOnDeselectByReturnedValueIfOptionDoesNotExist() { IWebElement element = driver.FindElement(By.Name("select_empty_multiple")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.DeselectByValue("not there")); + Assert.That( + () => elementWrapper.DeselectByValue("not there"), + Throws.TypeOf()); } [Test] @@ -351,7 +375,9 @@ public void ShouldThrowExceptionOnDeselectByTextIfOptionDoesNotExist() { IWebElement element = driver.FindElement(By.Name("select_empty_multiple")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.DeselectByText("not there")); + Assert.That( + () => elementWrapper.DeselectByText("not there"), + Throws.TypeOf()); } [Test] @@ -359,7 +385,9 @@ public void ShouldThrowExceptionOnDeselectByIndexIfOptionDoesNotExist() { IWebElement element = driver.FindElement(By.Name("select_empty_multiple")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.DeselectByIndex(10)); + Assert.That( + () => elementWrapper.DeselectByIndex(10), + Throws.TypeOf()); } [Test] @@ -367,7 +395,9 @@ public void ShouldNotAllowUserToDeselectByTextWhenSelectDoesNotSupportMultipleSe { IWebElement element = driver.FindElement(By.Name("selectomatic")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.DeselectByText("Four")); + Assert.That( + () => elementWrapper.DeselectByText("Four"), + Throws.InvalidOperationException); } [Test] @@ -375,7 +405,9 @@ public void ShouldNotAllowUserToDeselectByValueWhenSelectDoesNotSupportMultipleS { IWebElement element = driver.FindElement(By.Name("selectomatic")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.DeselectByValue("two")); + Assert.That( + () => elementWrapper.DeselectByValue("two"), + Throws.InvalidOperationException); } [Test] @@ -383,7 +415,9 @@ public void ShouldNotAllowUserToDeselectByIndexWhenSelectDoesNotSupportMultipleS { IWebElement element = driver.FindElement(By.Name("selectomatic")); SelectElement elementWrapper = new SelectElement(element); - Assert.Throws(() => elementWrapper.DeselectByIndex(0)); + Assert.That( + () => elementWrapper.DeselectByIndex(0), + Throws.InvalidOperationException); } } } diff --git a/dotnet/test/support/UI/SelectTests.cs b/dotnet/test/support/UI/SelectTests.cs index a6ccaf476b491..d4966e29aea6c 100644 --- a/dotnet/test/support/UI/SelectTests.cs +++ b/dotnet/test/support/UI/SelectTests.cs @@ -41,7 +41,9 @@ public void SetUp() public void ThrowUnexpectedTagNameExceptionWhenNotSelectTag() { webElement.SetupGet(_ => _.TagName).Returns("form"); - Assert.Throws(() => new SelectElement(webElement.Object)); + Assert.That( + () => new SelectElement(webElement.Object), + Throws.TypeOf()); } [Test] @@ -50,7 +52,7 @@ public void CanCreateNewInstanceOfSelectWithNormalSelectElement() webElement.SetupGet(_ => _.TagName).Returns("select"); webElement.Setup(_ => _.GetAttribute(It.Is(x => x == "multiple"))).Returns((string)null); - Assert.IsFalse(new SelectElement(webElement.Object).IsMultiple); + Assert.That(new SelectElement(webElement.Object).IsMultiple, Is.False); } [Test] @@ -59,7 +61,7 @@ public void CanCreateNewInstanceOfSelectWithMultipleSelectElement() webElement.SetupGet(_ => _.TagName).Returns("select"); webElement.Setup(_ => _.GetAttribute(It.Is(x => x == "multiple"))).Returns("true"); - Assert.IsTrue(new SelectElement(webElement.Object).IsMultiple); + Assert.That(new SelectElement(webElement.Object).IsMultiple, Is.True); } [Test] @@ -70,7 +72,7 @@ public void CanGetListOfOptions() webElement.Setup(_ => _.GetAttribute(It.Is(x => x == "multiple"))).Returns("true"); webElement.Setup(_ => _.FindElements(It.IsAny())).Returns(new ReadOnlyCollection(options)); - Assert.AreEqual(options, new SelectElement(webElement.Object).Options); + Assert.That(new SelectElement(webElement.Object).Options, Is.EqualTo(options)); } [Test] @@ -89,7 +91,7 @@ public void CanGetSingleSelectedOption() webElement.Setup(_ => _.FindElements(It.IsAny())).Returns(new ReadOnlyCollection(options)).Verifiable(); IWebElement option = new SelectElement(webElement.Object).SelectedOption; - Assert.AreEqual(selected.Object, option); + Assert.That(option, Is.EqualTo(selected.Object)); notSelected.Verify(_ => _.Selected, Times.Once); selected.Verify(_ => _.Selected, Times.Once); webElement.Verify(); @@ -111,8 +113,8 @@ public void CanGetAllSelectedOptions() webElement.Setup(_ => _.FindElements(It.IsAny())).Returns(new ReadOnlyCollection(options)).Verifiable(); IList returnedOption = new SelectElement(webElement.Object).AllSelectedOptions; - Assert.That(returnedOption.Count == 1); - Assert.AreEqual(selected.Object, returnedOption[0]); + Assert.That(returnedOption, Has.Count.EqualTo(1)); + Assert.That(returnedOption[0], Is.EqualTo(selected.Object)); notSelected.Verify(_ => _.Selected, Times.Once); selected.Verify(_ => _.Selected, Times.Once); webElement.Verify(); @@ -412,7 +414,10 @@ public void SelectedOptionPropertyShouldThrowExceptionWhenNoOptionSelected() webElement.Setup(_ => _.FindElements(It.IsAny())).Returns(new ReadOnlyCollection(options)).Verifiable(); SelectElement element = new SelectElement(webElement.Object); - Assert.Throws(() => { IWebElement selectedOption = element.SelectedOption; }); + Assert.That( + () => element.SelectedOption, + Throws.TypeOf()); + notSelected.Verify(_ => _.Selected, Times.Once); webElement.Verify(_ => _.FindElements(It.IsAny()), Times.Once); } @@ -422,7 +427,7 @@ public void ShouldConvertAnUnquotedStringIntoOneWithQuotes() { string result = EscapeQuotes("foo"); - Assert.AreEqual("\"foo\"", result); + Assert.That(result, Is.EqualTo("\"foo\"")); } [Test] @@ -430,7 +435,7 @@ public void ShouldConvertAStringWithATickIntoOneWithQuotes() { string result = EscapeQuotes("f'oo"); - Assert.AreEqual("\"f'oo\"", result); + Assert.That(result, Is.EqualTo("\"f'oo\"")); } [Test] @@ -438,7 +443,7 @@ public void ShouldConvertAStringWithAQuotIntoOneWithTicks() { string result = EscapeQuotes("f\"oo"); - Assert.AreEqual("'f\"oo'", result); + Assert.That(result, Is.EqualTo("'f\"oo'")); } [Test] @@ -446,7 +451,7 @@ public void ShouldProvideConcatenatedStringsWhenStringToEscapeContainsTicksAndQu { string result = EscapeQuotes("f\"o'o"); - Assert.AreEqual("concat(\"f\", '\"', \"o'o\")", result); + Assert.That(result, Is.EqualTo("concat(\"f\", '\"', \"o'o\")")); } /** @@ -458,7 +463,7 @@ public void ShouldProvideConcatenatedStringsWhenStringEndsWithQuote() { string result = EscapeQuotes("Bar \"Rock'n'Roll\""); - Assert.AreEqual("concat(\"Bar \", '\"', \"Rock'n'Roll\", '\"')", result); + Assert.That(result, Is.EqualTo("concat(\"Bar \", '\"', \"Rock'n'Roll\", '\"')")); } private string EscapeQuotes(string toEscape) diff --git a/dotnet/test/support/UI/SlowLoadableComponentTest.cs b/dotnet/test/support/UI/SlowLoadableComponentTest.cs index 61543e8dd1c43..bf1de0f683fe5 100644 --- a/dotnet/test/support/UI/SlowLoadableComponentTest.cs +++ b/dotnet/test/support/UI/SlowLoadableComponentTest.cs @@ -45,7 +45,7 @@ public void TestShouldCauseTheLoadMethodToBeCalledIfTheComponentIsNotAlreadyLoad int numberOfTimesThroughLoop = 1; SlowLoading slowLoading = new SlowLoading(TimeSpan.FromSeconds(1), new SystemClock(), numberOfTimesThroughLoop).Load(); - Assert.AreEqual(numberOfTimesThroughLoop, slowLoading.GetLoopCount()); + Assert.That(slowLoading.GetLoopCount(), Is.EqualTo(numberOfTimesThroughLoop)); } [Test] diff --git a/dotnet/test/support/UI/WebDriverWaitTest.cs b/dotnet/test/support/UI/WebDriverWaitTest.cs index cd6995b48130c..3997b3151f851 100644 --- a/dotnet/test/support/UI/WebDriverWaitTest.cs +++ b/dotnet/test/support/UI/WebDriverWaitTest.cs @@ -47,7 +47,7 @@ public void CanGetListOfOptions() var condition = GetCondition(() => null, () => SOME_STRING); var wait = new WebDriverWait(new TickingClock(), mockDriver.Object, FIVE_SECONDS, ZERO_SECONDS); - Assert.AreEqual(SOME_STRING, wait.Until(condition)); + Assert.That(wait.Until(condition), Is.EqualTo(SOME_STRING)); } [Test] @@ -57,7 +57,7 @@ public void WaitsForBaseObjectType() var condition = GetCondition(() => null, () => new object()); var wait = new WebDriverWait(new TickingClock(), mockDriver.Object, FIVE_SECONDS, ZERO_SECONDS); - Assert.IsNotNull(wait.Until(condition)); + Assert.That(wait.Until(condition), Is.Not.Null); } [Test] @@ -67,7 +67,7 @@ public void WaitsUntilABooleanResultIsTrue() var condition = GetCondition(() => false, () => true); var wait = new WebDriverWait(new TickingClock(), mockDriver.Object, FIVE_SECONDS, ZERO_SECONDS); - Assert.True(wait.Until(condition)); + Assert.That(wait.Until(condition), Is.True); } [Test] @@ -79,8 +79,8 @@ public void ThrowsForInvalidTypes() var wait = new WebDriverWait(new TickingClock(), mockDriver.Object, FIVE_SECONDS, ZERO_SECONDS); - Assert.Throws(typeof(ArgumentException), () => wait.Until(nullableBooleanCondition)); - Assert.Throws(typeof(ArgumentException), () => wait.Until(intCondition)); + Assert.That(() => wait.Until(nullableBooleanCondition), Throws.ArgumentException); + Assert.That(() => wait.Until(intCondition), Throws.ArgumentException); } [Test] @@ -89,7 +89,9 @@ public void ThrowsAnExceptionIfTheTimerRunsOut() var mockDriver = new Mock(); var wait = new WebDriverWait(GetClock(), mockDriver.Object, ONE_SECONDS, ZERO_SECONDS); - Assert.Throws(typeof(WebDriverTimeoutException), () => wait.Until(driver => false)); + Assert.That( + () => wait.Until(driver => false), + Throws.TypeOf()); } [Test] @@ -101,7 +103,7 @@ public void SilentlyCapturesNoSuchElementExceptions() var wait = new WebDriverWait(new TickingClock(), mockDriver.Object, FIVE_SECONDS, ZERO_SECONDS); - Assert.AreEqual(element.Object, wait.Until(condition)); + Assert.That(wait.Until(condition), Is.EqualTo(element.Object)); } [Test] @@ -114,7 +116,7 @@ public void PassesWebDriverFromConstructorToExpectation() var wait = new WebDriverWait(new TickingClock(), mockDriver.Object, FIVE_SECONDS, ZERO_SECONDS); - Assert.AreEqual(SOME_STRING, wait.Until(condition)); + Assert.That(wait.Until(condition), Is.EqualTo(SOME_STRING)); mockDriver.Verify(_ => _.CurrentWindowHandle, Times.Once); } @@ -134,7 +136,7 @@ public void ChainsNoSuchElementExceptionWhenTimingOut() } catch (WebDriverTimeoutException e) { - Assert.IsInstanceOf(typeof(NoSuchElementException), e.InnerException); + Assert.That(e.InnerException, Is.InstanceOf()); } }