Skip to content

Commit fe2a70d

Browse files
committed
Updating .NET test suite to be consistent with Java tests
1 parent be25803 commit fe2a70d

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

dotnet/test/common/TestUtilities.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public static bool IsFirefox(IWebDriver driver)
4141

4242
public static bool IsInternetExplorer(IWebDriver driver)
4343
{
44-
return GetUserAgent(driver).Contains("MSIE");
44+
string userAgent = GetUserAgent(driver);
45+
return userAgent.Contains("MSIE") || userAgent.Contains("Trident");
4546
}
4647

4748
public static bool IsIE6(IWebDriver driver)

dotnet/test/common/WindowSwitchingTest.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ public void ShouldThrowNoSuchWindowExceptionOnAnyElementOperationIfAWindowIsClos
175175
[NeedsFreshDriver(BeforeTest = true, AfterTest = true)]
176176
[IgnoreBrowser(Browser.IE)]
177177
[IgnoreBrowser(Browser.Safari, "Hangs Safari driver")]
178-
//[IgnoreBrowser(Browser.Firefox)]
179178
public void ShouldBeAbleToIterateOverAllOpenWindows()
180179
{
181180
driver.Url = xhtmlTestPage;
@@ -199,10 +198,12 @@ public void ShouldBeAbleToIterateOverAllOpenWindows()
199198
}
200199

201200
[Test]
202-
[IgnoreBrowser(Browser.IE, "IE prompts with an alert when closing. Revisit when alert handling is done")]
203201
[IgnoreBrowser(Browser.Safari, "Hangs Safari driver")]
204202
public void ClickingOnAButtonThatClosesAnOpenWindowDoesNotCauseTheBrowserToHang()
205203
{
204+
bool isIEDriver = TestUtilities.IsInternetExplorer(driver);
205+
bool isIE6 = TestUtilities.IsIE6(driver);
206+
206207
driver.Url = xhtmlTestPage;
207208

208209
String currentHandle = driver.CurrentWindowHandle;
@@ -215,6 +216,11 @@ public void ClickingOnAButtonThatClosesAnOpenWindowDoesNotCauseTheBrowserToHang(
215216
{
216217
IWebElement closeElement = WaitFor(() => { return driver.FindElement(By.Id("close")); });
217218
closeElement.Click();
219+
if (isIEDriver && !isIE6)
220+
{
221+
IAlert alert = WaitFor<IAlert>(AlertToBePresent());
222+
alert.Accept();
223+
}
218224
// If we make it this far, we're all good.
219225
}
220226
finally
@@ -226,10 +232,12 @@ public void ClickingOnAButtonThatClosesAnOpenWindowDoesNotCauseTheBrowserToHang(
226232

227233
[Test]
228234
[Category("Javascript")]
229-
[IgnoreBrowser(Browser.IE, "IE prompts with an alert when closing. Revisit when alert handling is done")]
230235
[IgnoreBrowser(Browser.Safari, "Hangs Safari driver")]
231236
public void CanCallGetWindowHandlesAfterClosingAWindow()
232237
{
238+
bool isIEDriver = TestUtilities.IsInternetExplorer(driver);
239+
bool isIE6 = TestUtilities.IsIE6(driver);
240+
233241
driver.Url = xhtmlTestPage;
234242

235243
String currentHandle = driver.CurrentWindowHandle;
@@ -242,6 +250,11 @@ public void CanCallGetWindowHandlesAfterClosingAWindow()
242250
{
243251
IWebElement closeElement = WaitFor(() => { return driver.FindElement(By.Id("close")); });
244252
closeElement.Click();
253+
if (isIEDriver && !isIE6)
254+
{
255+
IAlert alert = WaitFor<IAlert>(AlertToBePresent());
256+
alert.Accept();
257+
}
245258
ReadOnlyCollection<string> handles = driver.WindowHandles;
246259
// If we make it this far, we're all good.
247260
}
@@ -413,5 +426,22 @@ private Func<bool> WindowWithName(string name)
413426
return false;
414427
};
415428
}
429+
430+
private Func<IAlert> AlertToBePresent()
431+
{
432+
return () =>
433+
{
434+
IAlert alert = null;
435+
try
436+
{
437+
alert = driver.SwitchTo().Alert();
438+
}
439+
catch (NoAlertPresentException)
440+
{
441+
}
442+
443+
return alert;
444+
};
445+
}
416446
}
417447
}

0 commit comments

Comments
 (0)