Skip to content

Commit d36bb78

Browse files
committed
Finish porting affected tests to expressions and Throws.TypeOf
1 parent a4ab3d5 commit d36bb78

File tree

5 files changed

+78
-47
lines changed

5 files changed

+78
-47
lines changed

dotnet/test/common/ExecutingJavascriptTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public void ShouldThrowAnExceptionIfAnArgumentIsNotValid()
401401

402402
Assert.That(
403403
() => ExecuteScript("return arguments[0];", driver),
404-
Throws.TypeOf<ArgumentException>().With.Message.StartsWith("Argument is of an illegal type: "));
404+
Throws.ArgumentException.With.Message.StartsWith("Argument is of an illegal type: "));
405405
}
406406

407407
[Test]

dotnet/test/common/FrameSwitchingTest.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,16 @@ public void FrameSearchesShouldBeRelativeToTheCurrentlySelectedFrame()
175175
driver.SwitchTo().Frame(frameElement);
176176
Assert.AreEqual("2", driver.FindElement(By.Id("pageNumber")).Text);
177177

178-
Assert.That(() =>
179-
{
180-
driver.SwitchTo().Frame("third");
181-
}, Throws.InstanceOf<NoSuchFrameException>());
178+
Assert.That(
179+
() => driver.SwitchTo().Frame("third"),
180+
Throws.TypeOf<NoSuchFrameException>());
182181

183182
driver.SwitchTo().DefaultContent();
184183
driver.SwitchTo().Frame("third");
185184

186-
Assert.That(() =>
187-
{
188-
driver.SwitchTo().Frame("second");
189-
}, Throws.InstanceOf<NoSuchFrameException>());
185+
Assert.That(
186+
() => driver.SwitchTo().Frame("second"),
187+
Throws.TypeOf<NoSuchFrameException>());
190188

191189
driver.SwitchTo().DefaultContent();
192190
driver.SwitchTo().Frame("second");
@@ -206,22 +204,30 @@ public void ShouldThrowFrameNotFoundExceptionLookingUpSubFramesWithSuperFrameNam
206204
{
207205
driver.Url = framesetPage;
208206
driver.SwitchTo().Frame("fourth");
209-
Assert.That(() => driver.SwitchTo().Frame("second"), Throws.InstanceOf<NoSuchFrameException>());
207+
Assert.That(
208+
() => driver.SwitchTo().Frame("second"),
209+
Throws.TypeOf<NoSuchFrameException>());
210210

211211
}
212212

213213
[Test]
214214
public void ShouldThrowAnExceptionWhenAFrameCannotBeFound()
215215
{
216216
driver.Url = xhtmlTestPage;
217-
Assert.That(() => driver.SwitchTo().Frame("Nothing here"), Throws.InstanceOf<NoSuchFrameException>());
217+
218+
Assert.That(
219+
() => driver.SwitchTo().Frame("Nothing here"),
220+
Throws.TypeOf<NoSuchFrameException>());
218221
}
219222

220223
[Test]
221224
public void ShouldThrowAnExceptionWhenAFrameCannotBeFoundByIndex()
222225
{
223226
driver.Url = xhtmlTestPage;
224-
Assert.That(() => driver.SwitchTo().Frame(27), Throws.InstanceOf<NoSuchFrameException>());
227+
228+
Assert.That(
229+
() => driver.SwitchTo().Frame(27),
230+
Throws.TypeOf<NoSuchFrameException>());
225231
}
226232

227233
[Test]
@@ -460,7 +466,9 @@ public void ShouldNotBeAbleToDoAnythingTheFrameIsDeletedFromUnderUs()
460466
IWebElement killIframe = driver.FindElement(By.Id("killIframe"));
461467
killIframe.Click();
462468

463-
Assert.That(() => driver.FindElement(By.Id("killIframe")), Throws.InstanceOf<NoSuchWindowException>());
469+
Assert.That(
470+
() => driver.FindElement(By.Id("killIframe")),
471+
Throws.TypeOf<NoSuchWindowException>());
464472
}
465473

466474
[Test]

dotnet/test/common/TargetLocatorTest.cs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,31 @@ public class TargetLocatorTest : DriverTestFixture
3030
public void ShouldThrowExceptionAfterSwitchingToNonExistingFrameIndex()
3131
{
3232
driver.Url = framesPage;
33-
Assert.That(() => driver.SwitchTo().Frame(10), Throws.InstanceOf<NoSuchFrameException>());
33+
34+
Assert.That(
35+
() => driver.SwitchTo().Frame(10),
36+
Throws.TypeOf<NoSuchFrameException>());
3437
}
3538

3639
[Test]
3740
public void ShouldThrowExceptionAfterSwitchingToNonExistingFrameName()
3841
{
3942
driver.Url = framesPage;
40-
Assert.That(() => driver.SwitchTo().Frame("æ©ñµøöíúüþ®éåä²doesnotexist"), Throws.InstanceOf<NoSuchFrameException>());
43+
44+
Assert.That(
45+
() => driver.SwitchTo().Frame("æ©ñµøöíúüþ®éåä²doesnotexist"),
46+
Throws.TypeOf<NoSuchFrameException>());
4147
}
4248

4349
[Test]
4450
public void ShouldThrowExceptionAfterSwitchingToNullFrameName()
4551
{
4652
string frameName = null;
4753
driver.Url = framesPage;
48-
Assert.That(() => driver.SwitchTo().Frame(frameName), Throws.InstanceOf<ArgumentNullException>());
54+
55+
Assert.That(
56+
() => driver.SwitchTo().Frame(frameName),
57+
Throws.TypeOf<ArgumentNullException>());
4958
}
5059

5160
[Test]
@@ -85,21 +94,19 @@ public void ShouldSwitchToFrameByNameAndBackToDefaultContent()
8594
driver.SwitchTo().DefaultContent();
8695

8796
// DefaultContent should not have the element in it.
88-
Assert.That(() =>
89-
{
90-
Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "1");
91-
}, Throws.InstanceOf<NoSuchElementException>());
97+
Assert.That(
98+
() => Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "1"),
99+
Throws.TypeOf<NoSuchElementException>());
92100

93101
driver.SwitchTo().Frame("second");
94102
Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "2");
95103

96104
driver.SwitchTo().DefaultContent();
97105

98106
// DefaultContent should not have the element in it.
99-
Assert.That(() =>
100-
{
101-
Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "1");
102-
}, Throws.InstanceOf<NoSuchElementException>());
107+
Assert.That(
108+
() => Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "1"),
109+
Throws.TypeOf<NoSuchElementException>());
103110
}
104111

105112
[Test]
@@ -113,10 +120,9 @@ public void ShouldSwitchToFrameByIndexAndBackToDefaultContent()
113120
driver.SwitchTo().DefaultContent();
114121

115122
// DefaultContent should not have the element in it.
116-
Assert.That(() =>
117-
{
118-
Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "1");
119-
}, Throws.InstanceOf<NoSuchElementException>());
123+
Assert.That(
124+
() => Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "1"),
125+
Throws.TypeOf<NoSuchElementException>());
120126

121127

122128
driver.SwitchTo().Frame(1);
@@ -125,10 +131,9 @@ public void ShouldSwitchToFrameByIndexAndBackToDefaultContent()
125131
driver.SwitchTo().DefaultContent();
126132

127133
// DefaultContent should not have the element in it.
128-
Assert.That(() =>
129-
{
130-
Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "1");
131-
}, Throws.InstanceOf<NoSuchElementException>());
134+
Assert.That(
135+
() => Assert.AreEqual(driver.FindElement(By.Id("pageNumber")).Text, "1"),
136+
Throws.TypeOf<NoSuchElementException>());
132137
}
133138

134139
}

dotnet/test/common/WindowSwitchingTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void ShouldThrowNoSuchWindowException()
6363

6464
Assert.That(
6565
() => driver.SwitchTo().Window("invalid name"),
66-
Throws.InstanceOf<NoSuchWindowException>());
66+
Throws.TypeOf<NoSuchWindowException>());
6767

6868
driver.SwitchTo().Window(current);
6969
}
@@ -89,7 +89,7 @@ public void ShouldThrowNoSuchWindowExceptionOnAnAttemptToGetItsHandle()
8989
{
9090
Assert.That(
9191
() => driver.CurrentWindowHandle,
92-
Throws.InstanceOf<NoSuchWindowException>());
92+
Throws.TypeOf<NoSuchWindowException>());
9393
}
9494
finally
9595
{
@@ -118,11 +118,11 @@ public void ShouldThrowNoSuchWindowExceptionOnAnyOperationIfAWindowIsClosed()
118118
{
119119
Assert.That(
120120
() => driver.Title,
121-
Throws.InstanceOf<NoSuchWindowException>());
121+
Throws.TypeOf<NoSuchWindowException>());
122122

123123
Assert.That(
124124
() => driver.FindElement(By.TagName("body")),
125-
Throws.InstanceOf<NoSuchWindowException>());
125+
Throws.TypeOf<NoSuchWindowException>());
126126
}
127127
finally
128128
{
@@ -152,7 +152,7 @@ public void ShouldThrowNoSuchWindowExceptionOnAnyElementOperationIfAWindowIsClos
152152
{
153153
Assert.That(
154154
() => body.Text,
155-
Throws.InstanceOf<NoSuchWindowException>());
155+
Throws.TypeOf<NoSuchWindowException>());
156156
}
157157
finally
158158
{
@@ -260,7 +260,7 @@ public void FailingToSwitchToAWindowLeavesTheCurrentWindowAsIs()
260260

261261
Assert.That(
262262
() => driver.SwitchTo().Window("i will never exist"),
263-
Throws.InstanceOf<NoSuchWindowException>(),
263+
Throws.TypeOf<NoSuchWindowException>(),
264264
"Should not be able to change to a non-existant window");
265265

266266
String newHandle = driver.CurrentWindowHandle;

dotnet/test/support/Extensions/ExecuteJavaScriptTest.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public void ShouldConvertToIEnumerable()
5757

5858
driver.Setup(_ => _.ExecuteScript(It.IsAny<string>(), It.IsAny<object[]>())).Returns(expected);
5959

60-
Assert.That(() => driver.Object.ExecuteJavaScript<IEnumerable>(JavaScript, JavaScriptParameters), Throws.Nothing);
60+
Assert.That(
61+
() => driver.Object.ExecuteJavaScript<IEnumerable>(JavaScript, JavaScriptParameters),
62+
Throws.Nothing);
6163
}
6264

6365
[Test]
@@ -67,7 +69,9 @@ public void ShouldConvertToIEnumerableOfObject()
6769

6870
driver.Setup(_ => _.ExecuteScript(It.IsAny<string>(), It.IsAny<object[]>())).Returns(expected);
6971

70-
Assert.That(() => driver.Object.ExecuteJavaScript<IEnumerable<object>>(JavaScript, JavaScriptParameters), Throws.Nothing);
72+
Assert.That(
73+
() => driver.Object.ExecuteJavaScript<IEnumerable<object>>(JavaScript, JavaScriptParameters),
74+
Throws.Nothing);
7175
}
7276

7377
[Test]
@@ -77,7 +81,9 @@ public void ShouldNotConvertToIEnumerableOfInteger()
7781

7882
driver.Setup(_ => _.ExecuteScript(It.IsAny<string>(), It.IsAny<object[]>())).Returns(expected);
7983

80-
Assert.That(() => driver.Object.ExecuteJavaScript<IEnumerable<int>>(JavaScript, JavaScriptParameters), Throws.InstanceOf<WebDriverException>());
84+
Assert.That(
85+
() => driver.Object.ExecuteJavaScript<IEnumerable<int>>(JavaScript, JavaScriptParameters),
86+
Throws.TypeOf<WebDriverException>());
8187
}
8288

8389
[Test]
@@ -87,7 +93,9 @@ public void ShouldConvertToReadOnlyCollectionOfObject()
8793

8894
driver.Setup(_ => _.ExecuteScript(It.IsAny<string>(), It.IsAny<object[]>())).Returns(expected);
8995

90-
Assert.That(() => driver.Object.ExecuteJavaScript<ReadOnlyCollection<object>>(JavaScript, JavaScriptParameters), Throws.Nothing);
96+
Assert.That(
97+
() => driver.Object.ExecuteJavaScript<ReadOnlyCollection<object>>(JavaScript, JavaScriptParameters),
98+
Throws.Nothing);
9199
}
92100

93101
[Test]
@@ -97,39 +105,49 @@ public void ShouldNotConvertToSubClassOfReadOnlyCollectionOfObject()
97105

98106
driver.Setup(_ => _.ExecuteScript(It.IsAny<string>(), It.IsAny<object[]>())).Returns(expected);
99107

100-
Assert.That(() => driver.Object.ExecuteJavaScript<SubClassOfReadOnlyCollectionOfObject>(JavaScript, JavaScriptParameters), Throws.InstanceOf<WebDriverException>());
108+
Assert.That(
109+
() => driver.Object.ExecuteJavaScript<SubClassOfReadOnlyCollectionOfObject>(JavaScript, JavaScriptParameters),
110+
Throws.TypeOf<WebDriverException>());
101111
}
102112

103113
[Test]
104114
public void ShouldNotThrowWhenNullIsReturned()
105115
{
106116
driver.Setup(_ => _.ExecuteScript(It.IsAny<string>(), It.IsAny<object[]>())).Returns(null);
107117

108-
Assert.That(() => driver.Object.ExecuteJavaScript<string>(JavaScript, JavaScriptParameters), Throws.Nothing);
118+
Assert.That(
119+
() => driver.Object.ExecuteJavaScript<string>(JavaScript, JavaScriptParameters),
120+
Throws.Nothing);
109121
}
110122

111123
[Test]
112124
public void ShouldNotThrowWhenNullIsReturnedForNullableValueType()
113125
{
114126
driver.Setup(_ => _.ExecuteScript(It.IsAny<string>(), It.IsAny<object[]>())).Returns(null);
115127

116-
Assert.That(() => driver.Object.ExecuteJavaScript<int?>(JavaScript, JavaScriptParameters), Throws.Nothing);
128+
Assert.That(
129+
() => driver.Object.ExecuteJavaScript<int?>(JavaScript, JavaScriptParameters),
130+
Throws.Nothing);
117131
}
118132

119133
[Test]
120134
public void ShouldThrowWhenNullIsReturnedForValueType()
121135
{
122136
driver.Setup(_ => _.ExecuteScript(It.IsAny<string>(), It.IsAny<object[]>())).Returns(null);
123137

124-
Assert.That(() => driver.Object.ExecuteJavaScript<int>(JavaScript, JavaScriptParameters), Throws.InstanceOf<WebDriverException>());
138+
Assert.That(
139+
() => driver.Object.ExecuteJavaScript<int>(JavaScript, JavaScriptParameters),
140+
Throws.TypeOf<WebDriverException>());
125141
}
126142

127143
[Test]
128144
public void ShouldAllowExecutingJavaScriptWithoutReturningResult()
129145
{
130146
driver.Setup(_ => _.ExecuteScript(It.IsAny<string>(), It.IsAny<object[]>())).Returns(null);
131147

132-
Assert.That(() => driver.Object.ExecuteJavaScript(JavaScript, JavaScriptParameters), Throws.Nothing);
148+
Assert.That(
149+
() => driver.Object.ExecuteJavaScript(JavaScript, JavaScriptParameters),
150+
Throws.Nothing);
133151
}
134152
}
135153
}

0 commit comments

Comments
 (0)