From 2f6e67d4b96f15a36b5a0f74e8201479f1ce54b5 Mon Sep 17 00:00:00 2001 From: Jim Evans Date: Wed, 17 Apr 2013 10:26:09 -0400 Subject: [PATCH] Updating .NET Alerts tests. Making test more robust by waiting for proper condition and adding test for quitting browser with onBeforeUnload event handler in place. --- .../test/WebDriver.Common.Tests/AlertsTest.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/dotnet/test/WebDriver.Common.Tests/AlertsTest.cs b/dotnet/test/WebDriver.Common.Tests/AlertsTest.cs index 0955202dd9ed7..33d3429e5e64b 100644 --- a/dotnet/test/WebDriver.Common.Tests/AlertsTest.cs +++ b/dotnet/test/WebDriver.Common.Tests/AlertsTest.cs @@ -343,7 +343,8 @@ public void SwitchingToMissingAlertInAClosedWindowThrows() { driver.FindElement(By.Id("open-new-window")).Click(); WaitFor(WindowHandleCountToBe(2)); - driver.SwitchTo().Window("newwindow").Close(); + WaitFor(WindowWithName("newwindow")); + driver.Close(); WaitFor(WindowHandleCountToBe(1)); try @@ -629,6 +630,29 @@ public void ShouldHandleOnBeforeUnloadAlert() Assert.IsTrue(driver.Url.Contains(alertsPage)); } + [Test] + [IgnoreBrowser(Browser.PhantomJS, "Alert commands not yet implemented in GhostDriver")] + [IgnoreBrowser(Browser.Safari)] + [NeedsFreshDriver(AfterTest = true)] + public void ShouldHandleOnBeforeUnloadAlertAtClose() + { + driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("pageWithOnBeforeUnloadMessage.html"); + IWebElement element = driver.FindElement(By.Id("navigate")); + element.Click(); + IAlert alert = WaitFor(AlertToBePresent); + driver.Quit(); + //alert.Dismiss(); + //Assert.IsTrue(driver.Url.Contains("pageWithOnBeforeUnloadMessage.html")); + + //// Can't move forward or even quit the driver + //// until the alert is accepted. + //element.Click(); + //alert = WaitFor(AlertToBePresent); + //alert.Accept(); + //WaitFor(() => { return driver.Url.Contains(alertsPage); }); + //Assert.IsTrue(driver.Url.Contains(alertsPage)); + } + [Test] [IgnoreBrowser(Browser.PhantomJS, "Alert commands not yet implemented in GhostDriver")] [IgnoreBrowser(Browser.Safari)]