diff --git a/dotnet/test/common/BiDi/Browser/BrowserTest.cs b/dotnet/test/common/BiDi/Browser/BrowserTest.cs index ede287cefd953..096970d178543 100644 --- a/dotnet/test/common/BiDi/Browser/BrowserTest.cs +++ b/dotnet/test/common/BiDi/Browser/BrowserTest.cs @@ -41,7 +41,7 @@ public async Task CanGetUserContexts() var userContexts = await bidi.Browser.GetUserContextsAsync(); Assert.That(userContexts, Is.Not.Null); - Assert.That(userContexts.Count, Is.GreaterThanOrEqualTo(2)); + Assert.That(userContexts, Has.Count.GreaterThanOrEqualTo(2)); Assert.That(userContexts, Does.Contain(userContext1)); Assert.That(userContexts, Does.Contain(userContext2)); } diff --git a/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs b/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs index 14baaf25d8f9a..74e736e70b0c4 100644 --- a/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs @@ -99,7 +99,7 @@ public async Task CanListenToBeforeRequestSentEventWithCookie() var req = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); - Assert.That(req.Request.Cookies.Count, Is.EqualTo(1)); + Assert.That(req.Request.Cookies, Has.Count.EqualTo(1)); Assert.That(req.Request.Cookies[0].Name, Is.EqualTo("foo")); Assert.That((req.Request.Cookies[0].Value as BytesValue.String).Value, Is.EqualTo("bar")); } diff --git a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs index da692fd898111..798ea1cbbf9f2 100644 --- a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs +++ b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs @@ -34,7 +34,7 @@ public async Task CanGetAllRealms() var realms = await bidi.Script.GetRealmsAsync(); Assert.That(realms, Is.Not.Null); - Assert.That(realms.Count, Is.EqualTo(2)); + Assert.That(realms, Has.Count.EqualTo(2)); Assert.That(realms[0], Is.AssignableFrom()); Assert.That(realms[0].Realm, Is.Not.Null); @@ -51,7 +51,7 @@ public async Task CanGetAllRealmsByType() var realms = await bidi.Script.GetRealmsAsync(new() { Type = RealmType.Window }); Assert.That(realms, Is.Not.Null); - Assert.That(realms.Count, Is.EqualTo(2)); + Assert.That(realms, Has.Count.EqualTo(2)); Assert.That(realms[0], Is.AssignableFrom()); Assert.That(realms[0].Realm, Is.Not.Null); diff --git a/dotnet/test/common/BiDi/Storage/StorageTest.cs b/dotnet/test/common/BiDi/Storage/StorageTest.cs index 19db76a0d4a7b..642f17756ef57 100644 --- a/dotnet/test/common/BiDi/Storage/StorageTest.cs +++ b/dotnet/test/common/BiDi/Storage/StorageTest.cs @@ -94,7 +94,7 @@ await context.Storage.SetCookieAsync(new("fish", "cod", UrlBuilder.HostName) var cookies = await context.Storage.GetCookiesAsync(); Assert.That(cookies, Is.Not.Null); - Assert.That(cookies.Count, Is.EqualTo(1)); + Assert.That(cookies, Has.Count.EqualTo(1)); var cookie = cookies[0]; @@ -119,7 +119,7 @@ public async Task CanGetAllCookies() var cookies = await bidi.Storage.GetCookiesAsync(); Assert.That(cookies, Is.Not.Null); - Assert.That(cookies.Count, Is.EqualTo(2)); + Assert.That(cookies, Has.Count.EqualTo(2)); Assert.That(cookies[0].Name, Is.EqualTo("key1")); Assert.That(cookies[1].Name, Is.EqualTo("key2")); } @@ -157,7 +157,7 @@ public async Task CanDeleteCookieWithName() var cookies = await bidi.Storage.GetCookiesAsync(); Assert.That(cookies, Is.Not.Null); - Assert.That(cookies.Count, Is.EqualTo(1)); + Assert.That(cookies, Has.Count.EqualTo(1)); Assert.That(cookies[0].Name, Is.EqualTo("key2")); } diff --git a/dotnet/test/common/ClickScrollingTest.cs b/dotnet/test/common/ClickScrollingTest.cs index e217f88d53a60..d5a73aed7c33c 100644 --- a/dotnet/test/common/ClickScrollingTest.cs +++ b/dotnet/test/common/ClickScrollingTest.cs @@ -44,7 +44,7 @@ public void ClickingOnAnchorScrollsPage() // Sometimes JS is returning a double object result = ((IJavaScriptExecutor)driver).ExecuteScript(scrollScript); - var yOffset = Convert.ChangeType(result, typeof(long)); + var yOffset = Convert.ToInt64(result); //Focusing on to click, but not actually following, //the link will scroll it in to view, which is a few pixels further than 0 diff --git a/dotnet/test/common/DriverElementFindingTest.cs b/dotnet/test/common/DriverElementFindingTest.cs index f491f4857335b..6c44b9a4602e9 100644 --- a/dotnet/test/common/DriverElementFindingTest.cs +++ b/dotnet/test/common/DriverElementFindingTest.cs @@ -93,7 +93,7 @@ public void ShouldFindElementsById() { driver.Url = nestedPage; ReadOnlyCollection elements = driver.FindElements(By.Id("test_id")); - Assert.That(elements.Count, Is.EqualTo(2)); + Assert.That(elements, Has.Count.EqualTo(2)); } [Test] @@ -101,7 +101,7 @@ public void ShouldFindElementsByLinkText() { driver.Url = nestedPage; ReadOnlyCollection elements = driver.FindElements(By.LinkText("hello world")); - Assert.That(elements.Count, Is.EqualTo(12)); + Assert.That(elements, Has.Count.EqualTo(12)); } [Test] @@ -109,7 +109,7 @@ public void ShouldFindElementsByName() { driver.Url = nestedPage; ReadOnlyCollection elements = driver.FindElements(By.Name("form1")); - Assert.That(elements.Count, Is.EqualTo(4)); + Assert.That(elements, Has.Count.EqualTo(4)); } [Test] @@ -117,7 +117,7 @@ public void ShouldFindElementsByXPath() { driver.Url = nestedPage; ReadOnlyCollection elements = driver.FindElements(By.XPath("//a")); - Assert.That(elements.Count, Is.EqualTo(12)); + Assert.That(elements, Has.Count.EqualTo(12)); } [Test] @@ -125,7 +125,7 @@ public void ShouldFindElementsByClassName() { driver.Url = nestedPage; ReadOnlyCollection elements = driver.FindElements(By.ClassName("one")); - Assert.That(elements.Count, Is.EqualTo(3)); + Assert.That(elements, Has.Count.EqualTo(3)); } [Test] @@ -133,7 +133,7 @@ public void ShouldFindElementsByPartialLinkText() { driver.Url = nestedPage; ReadOnlyCollection elements = driver.FindElements(By.PartialLinkText("world")); - Assert.That(elements.Count, Is.EqualTo(12)); + Assert.That(elements, Has.Count.EqualTo(12)); } [Test] @@ -141,7 +141,7 @@ public void ShouldFindElementsByTagName() { driver.Url = nestedPage; ReadOnlyCollection elements = driver.FindElements(By.TagName("a")); - Assert.That(elements.Count, Is.EqualTo(12)); + Assert.That(elements, Has.Count.EqualTo(12)); } #endregion } diff --git a/dotnet/test/common/ElementElementFindingTest.cs b/dotnet/test/common/ElementElementFindingTest.cs index 67cf47bbe8f92..26d75b6279374 100644 --- a/dotnet/test/common/ElementElementFindingTest.cs +++ b/dotnet/test/common/ElementElementFindingTest.cs @@ -101,7 +101,7 @@ public void ShouldFindElementsById() driver.Url = nestedPage; IWebElement parent = driver.FindElement(By.Name("form2")); ReadOnlyCollection children = parent.FindElements(By.Id("2")); - Assert.That(children.Count, Is.EqualTo(2)); + Assert.That(children, Has.Count.EqualTo(2)); } [Test] @@ -110,7 +110,7 @@ public void ShouldFindElementsByLinkText() driver.Url = nestedPage; IWebElement parent = driver.FindElement(By.Name("div1")); ReadOnlyCollection children = parent.FindElements(By.PartialLinkText("hello world")); - Assert.That(children.Count, Is.EqualTo(2)); + Assert.That(children, Has.Count.EqualTo(2)); Assert.That(children[0].Text, Is.EqualTo("hello world")); Assert.That(children[1].Text, Is.EqualTo("hello world")); } @@ -121,7 +121,7 @@ public void ShouldFindElementsByName() driver.Url = nestedPage; IWebElement parent = driver.FindElement(By.Name("form2")); ReadOnlyCollection children = parent.FindElements(By.Name("selectomatic")); - Assert.That(children.Count, Is.EqualTo(2)); + Assert.That(children, Has.Count.EqualTo(2)); } [Test] @@ -130,7 +130,7 @@ public void ShouldFindElementsByXPath() driver.Url = nestedPage; IWebElement parent = driver.FindElement(By.Name("classes")); ReadOnlyCollection children = parent.FindElements(By.XPath("span")); - Assert.That(children.Count, Is.EqualTo(3)); + Assert.That(children, Has.Count.EqualTo(3)); Assert.That(children[0].Text, Is.EqualTo("Find me")); Assert.That(children[1].Text, Is.EqualTo("Also me")); Assert.That(children[2].Text, Is.EqualTo("But not me")); @@ -142,7 +142,7 @@ public void ShouldFindElementsByClassName() driver.Url = nestedPage; IWebElement parent = driver.FindElement(By.Name("classes")); ReadOnlyCollection children = parent.FindElements(By.ClassName("one")); - Assert.That(children.Count, Is.EqualTo(2)); + Assert.That(children, Has.Count.EqualTo(2)); Assert.That(children[0].Text, Is.EqualTo("Find me")); Assert.That(children[1].Text, Is.EqualTo("Also me")); } @@ -153,7 +153,7 @@ public void ShouldFindElementsByPartialLinkText() driver.Url = nestedPage; IWebElement parent = driver.FindElement(By.Name("div1")); ReadOnlyCollection children = parent.FindElements(By.PartialLinkText("hello ")); - Assert.That(children.Count, Is.EqualTo(2)); + Assert.That(children, Has.Count.EqualTo(2)); Assert.That(children[0].Text, Is.EqualTo("hello world")); Assert.That(children[1].Text, Is.EqualTo("hello world")); } @@ -164,7 +164,7 @@ public void ShouldFindElementsByTagName() driver.Url = nestedPage; IWebElement parent = driver.FindElement(By.Name("classes")); ReadOnlyCollection children = parent.FindElements(By.TagName("span")); - Assert.That(children.Count, Is.EqualTo(3)); + Assert.That(children, Has.Count.EqualTo(3)); Assert.That(children[0].Text, Is.EqualTo("Find me")); Assert.That(children[1].Text, Is.EqualTo("Also me")); Assert.That(children[2].Text, Is.EqualTo("But not me")); diff --git a/dotnet/test/common/ExecutingAsyncJavascriptTest.cs b/dotnet/test/common/ExecutingAsyncJavascriptTest.cs index 161d26c463857..ef0711453b6dc 100644 --- a/dotnet/test/common/ExecutingAsyncJavascriptTest.cs +++ b/dotnet/test/common/ExecutingAsyncJavascriptTest.cs @@ -118,7 +118,7 @@ public void ShouldBeAbleToReturnArraysOfPrimitivesFromAsyncScripts() Assert.That(result, Is.Not.Null); Assert.That(result, Is.InstanceOf>()); ReadOnlyCollection resultList = result as ReadOnlyCollection; - Assert.That(resultList.Count, Is.EqualTo(5)); + Assert.That(resultList, Has.Count.EqualTo(5)); Assert.That(resultList[0], Is.Null); Assert.That((long)resultList[1], Is.EqualTo(123)); Assert.That(resultList[2].ToString(), Is.EqualTo("abc")); @@ -221,10 +221,12 @@ public void ShouldCatchErrorsWithMessageAndStacktraceWhenExecutingInitialScript( string js = "function functionB() { throw Error('errormessage'); };" + "function functionA() { functionB(); };" + "functionA();"; - Exception ex = Assert.Catch(() => executor.ExecuteAsyncScript(js)); - Assert.That(ex, Is.InstanceOf()); - Assert.That(ex.Message.Contains("errormessage")); - Assert.That(ex.StackTrace.Contains("functionB")); + + Assert.That( + () => executor.ExecuteAsyncScript(js), + Throws.InstanceOf() + .With.Message.Contains("errormessage") + .And.Property(nameof(WebDriverException.StackTrace)).Contains("functionB")); } [Test] diff --git a/dotnet/test/common/ExecutingJavascriptTest.cs b/dotnet/test/common/ExecutingJavascriptTest.cs index 64e26d5aea9b4..d5b239a9cf206 100644 --- a/dotnet/test/common/ExecutingJavascriptTest.cs +++ b/dotnet/test/common/ExecutingJavascriptTest.cs @@ -256,10 +256,12 @@ public void ShouldThrowAnExceptionWithMessageAndStacktraceWhenTheJavascriptIsBad string js = "function functionB() { throw Error('errormessage'); };" + "function functionA() { functionB(); };" + "functionA();"; - Exception ex = Assert.Catch(() => ExecuteScript(js)); - Assert.That(ex, Is.InstanceOf()); - 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'"); + + Assert.That( + () => ExecuteScript(js), + Throws.InstanceOf() + .With.Message.Contains("errormessage") + .And.Property(nameof(WebDriverException.StackTrace)).Contains("functionB")); } [Test] @@ -467,7 +469,7 @@ public void ShouldBeAbleToExecuteABigChunkOfJavascriptCode() if (fileList.Length > 0) { string jquery = System.IO.File.ReadAllText(fileList[0]); - Assert.That(jquery.Length, Is.GreaterThan(50000)); + Assert.That(jquery, Has.Length.GreaterThan(50000)); ExecuteScript(jquery, null); } } diff --git a/dotnet/test/common/Interactions/ActionBuilderTest.cs b/dotnet/test/common/Interactions/ActionBuilderTest.cs index fadf473ee7202..d7acb6a95888f 100644 --- a/dotnet/test/common/Interactions/ActionBuilderTest.cs +++ b/dotnet/test/common/Interactions/ActionBuilderTest.cs @@ -19,7 +19,6 @@ using NUnit.Framework; using System; -using System.Collections; using System.Collections.Generic; namespace OpenQA.Selenium.Interactions @@ -55,8 +54,9 @@ public void OutputsPointerEventsToDictionary() 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"]); + Assert.That(dictionary["parameters"], Is.EquivalentTo(parameters)); var events = new Dictionary { @@ -72,8 +72,8 @@ public void OutputsPointerEventsToDictionary() {"type", "pointerDown"}, {"button", 0} }; - var actions = (IList)dictionary["actions"]; - CollectionAssert.AreEquivalent(events, (IEnumerable)actions[0]); + var actions = (IList)dictionary["actions"]; + Assert.That(actions[0], Is.EquivalentTo(events)); } } } diff --git a/dotnet/test/common/Internal/Logging/FileLogHandlerTest.cs b/dotnet/test/common/Internal/Logging/FileLogHandlerTest.cs index 63deb2bece47b..5c3e3150061dd 100644 --- a/dotnet/test/common/Internal/Logging/FileLogHandlerTest.cs +++ b/dotnet/test/common/Internal/Logging/FileLogHandlerTest.cs @@ -72,7 +72,7 @@ public void ShouldCreateFileIfDoesNotExist() fileLogHandler2.Handle(new LogEvent(typeof(FileLogHandlerTest), DateTimeOffset.Now, LogEventLevel.Info, "test message")); } - Assert.That(Regex.Matches(File.ReadAllText(tempFile), "test message").Count, Is.EqualTo(1)); + Assert.That(Regex.Matches(File.ReadAllText(tempFile), "test message"), Has.Count.EqualTo(1)); } finally { @@ -97,7 +97,7 @@ public void ShouldAppendFileIfExists() fileLogHandler2.Handle(new LogEvent(typeof(FileLogHandlerTest), DateTimeOffset.Now, LogEventLevel.Info, "test message")); } - Assert.That(Regex.Matches(File.ReadAllText(tempFilePath), "test message").Count, Is.EqualTo(2)); + Assert.That(Regex.Matches(File.ReadAllText(tempFilePath), "test message"), Has.Count.EqualTo(2)); } finally { @@ -117,7 +117,7 @@ public void ShouldOverwriteFileIfExists() fileLogHandler.Handle(new LogEvent(typeof(FileLogHandlerTest), DateTimeOffset.Now, LogEventLevel.Info, "test message")); } - Assert.That(Regex.Matches(File.ReadAllText(tempFile), "test message").Count, Is.EqualTo(1)); + Assert.That(Regex.Matches(File.ReadAllText(tempFile), "test message"), Has.Count.EqualTo(1)); } finally { @@ -137,7 +137,7 @@ public void ShouldAppendFileIfDoesNotExist() fileLogHandler.Handle(new LogEvent(typeof(FileLogHandlerTest), DateTimeOffset.Now, LogEventLevel.Info, "test message")); } - Assert.That(Regex.Matches(File.ReadAllText(tempFilePath), "test message").Count, Is.EqualTo(1)); + Assert.That(Regex.Matches(File.ReadAllText(tempFilePath), "test message"), Has.Count.EqualTo(1)); } finally { diff --git a/dotnet/test/common/NavigationTest.cs b/dotnet/test/common/NavigationTest.cs index 40f4d53bed1ec..6dce194d446d4 100644 --- a/dotnet/test/common/NavigationTest.cs +++ b/dotnet/test/common/NavigationTest.cs @@ -112,12 +112,11 @@ public void ShouldRefreshPage() [Test] [NeedsFreshDriver(IsCreatedBeforeTest = true)] - public Task ShouldNotHaveProblemNavigatingWithNoPagesBrowsedAsync() + public void ShouldNotHaveProblemNavigatingWithNoPagesBrowsedAsync() { var navigation = driver.Navigate(); - Assert.DoesNotThrowAsync(async () => await navigation.BackAsync()); - Assert.DoesNotThrowAsync(async () => await navigation.ForwardAsync()); - return Task.CompletedTask; + Assert.That(async () => await navigation.BackAsync(), Throws.Nothing); + Assert.That(async () => await navigation.ForwardAsync(), Throws.Nothing); } [Test] diff --git a/dotnet/test/common/PositionAndSizeTest.cs b/dotnet/test/common/PositionAndSizeTest.cs index 0a9d700ad1a8b..5d5cab17a89e5 100644 --- a/dotnet/test/common/PositionAndSizeTest.cs +++ b/dotnet/test/common/PositionAndSizeTest.cs @@ -111,7 +111,7 @@ public void ShouldGetCoordinatesInViewPortOfAnElementInAFrame() 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"))); + // Assert.That(GetLocationInViewPort(By.Id("box")), Is.EqualTo(new Point(25, 25))); } [Test] @@ -123,7 +123,7 @@ public void ShouldGetCoordinatesInViewPortOfAnElementInANestedFrame() 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"))); + // Assert.That(GetLocationInViewPort(By.Id("box")), Is.EqualTo(new Point(40, 40))); } [Test] diff --git a/dotnet/test/firefox/FirefoxDriverTest.cs b/dotnet/test/firefox/FirefoxDriverTest.cs index bf897c5ac49d6..0de306815de96 100644 --- a/dotnet/test/firefox/FirefoxDriverTest.cs +++ b/dotnet/test/firefox/FirefoxDriverTest.cs @@ -34,15 +34,9 @@ public void ShouldContinueToWorkIfUnableToFindElementById() { driver.Url = formsPage; - try - { - driver.FindElement(By.Id("notThere")); - Assert.Fail("Should not be able to select element by id here"); - } - catch (NoSuchElementException) - { - // This is expected - } + Assert.That( + () => driver.FindElement(By.Id("notThere")), + Throws.InstanceOf()); // Is this works, then we're golden driver.Url = xhtmlTestPage; diff --git a/dotnet/test/remote/RemoteWebDriverSpecificTests.cs b/dotnet/test/remote/RemoteWebDriverSpecificTests.cs index cb23945359c36..391309436ff6c 100644 --- a/dotnet/test/remote/RemoteWebDriverSpecificTests.cs +++ b/dotnet/test/remote/RemoteWebDriverSpecificTests.cs @@ -62,7 +62,7 @@ public void ShouldBeAbleToSendFileToRemoteServer() IAllowsFileDetection fileDetectionDriver = driver as IAllowsFileDetection; if (fileDetectionDriver == null) { - Assert.Fail("driver does not support file detection. This should not be"); + Assert.That(driver, Is.InstanceOf(), "driver does not support file detection. This should not be"); } fileDetectionDriver.FileDetector = new LocalFileDetector(); diff --git a/dotnet/test/support/Events/EventFiringWebDriverTest.cs b/dotnet/test/support/Events/EventFiringWebDriverTest.cs index a062163d83156..bf2d95aec33f3 100644 --- a/dotnet/test/support/Events/EventFiringWebDriverTest.cs +++ b/dotnet/test/support/Events/EventFiringWebDriverTest.cs @@ -184,15 +184,9 @@ public void ShouldCallListenerOnException() EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.Object); firingDriver.ExceptionThrown += new EventHandler(firingDriver_ExceptionThrown); - try - { - firingDriver.FindElement(By.Id("foo")); - Assert.Fail("Expected exception to be propogated"); - } - catch (NoSuchElementException) - { - // Fine - } + Assert.That( + () => firingDriver.FindElement(By.Id("foo")), + Throws.InstanceOf()); Assert.That(log.ToString(), Does.Contain(exception.Message)); } diff --git a/dotnet/test/support/UI/LoadableComponentTests.cs b/dotnet/test/support/UI/LoadableComponentTests.cs index 3416532ad6638..0d99c2c8161f1 100644 --- a/dotnet/test/support/UI/LoadableComponentTests.cs +++ b/dotnet/test/support/UI/LoadableComponentTests.cs @@ -53,31 +53,21 @@ public void ShouldThrowAnErrorIfCallingLoadDoesNotCauseTheComponentToLoad() { LoadsOk ok = new LoadsOk(false); - try - { - ok.Load(); - Assert.Fail(); - } - catch (LoadableComponentException e) - { - Assert.That(e.Message, Is.EqualTo("Expected failure")); - } + Assert.That( + () => ok.Load(), + Throws.InstanceOf().With.Message.EqualTo("Expected failure")); } [Test] public void ShouldCallHandleLoadErrorWhenWebDriverExceptionOccursDuringExecuteLoad() { ExecuteLoadThrows loadThrows = new ExecuteLoadThrows(); - try - { - loadThrows.Load(); - Assert.Fail(); - } - catch (Exception e) - { - Assert.That(e.Message, Is.EqualTo("HandleLoadError called")); - Assert.That(e.InnerException.Message, Is.EqualTo("Excpected failure in ExecuteLoad")); - } + + Assert.That( + () => loadThrows.Load(), + Throws.Exception + .With.Message.EqualTo("HandleLoadError called") + .And.InnerException.Message.EqualTo("Excpected failure in ExecuteLoad")); } diff --git a/dotnet/test/support/UI/SlowLoadableComponentTest.cs b/dotnet/test/support/UI/SlowLoadableComponentTest.cs index bf1de0f683fe5..bc198f7e8cccb 100644 --- a/dotnet/test/support/UI/SlowLoadableComponentTest.cs +++ b/dotnet/test/support/UI/SlowLoadableComponentTest.cs @@ -65,15 +65,10 @@ public void TestTheLoadMethodShouldOnlyBeCalledOnceIfTheComponentTakesALongTimeT public void TestShouldThrowAnErrorIfCallingLoadDoesNotCauseTheComponentToLoadBeforeTimeout() { FakeClock clock = new FakeClock(); - try - { - new BasicSlowLoader(TimeSpan.FromSeconds(2), clock).Load(); - Assert.Fail(); - } - catch (WebDriverTimeoutException) - { - // We expect to time out - } + + Assert.That( + () => new BasicSlowLoader(TimeSpan.FromSeconds(2), clock).Load(), + Throws.InstanceOf()); } [Test] @@ -81,15 +76,9 @@ public void TestShouldCancelLoadingIfAnErrorIsDetected() { HasError error = new HasError(); - try - { - error.Load(); - Assert.Fail(); - } - catch (CustomException) - { - // This is expected - } + Assert.That( + () => error.Load(), + Throws.InstanceOf()); } diff --git a/dotnet/test/support/UI/WebDriverWaitTest.cs b/dotnet/test/support/UI/WebDriverWaitTest.cs index 3997b3151f851..acacbbfd2ebd2 100644 --- a/dotnet/test/support/UI/WebDriverWaitTest.cs +++ b/dotnet/test/support/UI/WebDriverWaitTest.cs @@ -129,15 +129,9 @@ public void ChainsNoSuchElementExceptionWhenTimingOut() var wait = new WebDriverWait(GetClock(), mockDriver.Object, ONE_SECONDS, ZERO_SECONDS); - try - { - wait.Until(condition); - Assert.Fail("Expected WebDriverTimeoutException to be thrown"); - } - catch (WebDriverTimeoutException e) - { - Assert.That(e.InnerException, Is.InstanceOf()); - } + Assert.That( + () => wait.Until(condition), + Throws.InstanceOf().With.InnerException.InstanceOf()); } private Func GetCondition(Func first, Func second)