Skip to content

Commit 15b9bba

Browse files
committed
A new test for the case of an alert generated by form submit
1 parent 5c8380b commit 15b9bba

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

java/client/test/org/openqa/selenium/AlertsTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,24 @@ public void testCanQuitWhenAnAlertIsPresent() {
597597
driver.quit();
598598
}
599599

600+
@JavascriptEnabled
601+
@Test
602+
@Ignore(value = MARIONETTE, issue = "https://github.com/mozilla/geckodriver/issues/620")
603+
public void shouldHandleAlertOnFormSubmit() {
604+
driver.get(appServer.create(new Page().withTitle("Testing Alerts").withBody(
605+
"<form id='theForm' action='javascript:alert(\"Tasty cheese\");'>",
606+
"<input id='unused' type='submit' value='Submit'>",
607+
"</form>")));
608+
609+
driver.findElement(By.id("theForm")).submit();
610+
Alert alert = wait.until(alertIsPresent());
611+
String value = alert.getText();
612+
alert.accept();
613+
614+
assertEquals("Tasty cheese", value);
615+
assertEquals("Testing Alerts", driver.getTitle());
616+
}
617+
600618
private static ExpectedCondition<Boolean> textInElementLocated(
601619
final By locator, final String text) {
602620
return driver -> text.equals(driver.findElement(locator).getText());

java/client/test/org/openqa/selenium/FormHandlingTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static org.junit.Assert.assertThat;
2626
import static org.junit.Assert.assertTrue;
2727
import static org.junit.Assume.assumeFalse;
28+
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
2829
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
2930
import static org.openqa.selenium.testing.Driver.IE;
3031
import static org.openqa.selenium.testing.Driver.MARIONETTE;
@@ -272,12 +273,13 @@ public void testEmptyTextBoxesShouldReturnAnEmptyStringNotNull() {
272273
@Test
273274
@Ignore(PHANTOMJS)
274275
@Ignore(SAFARI)
276+
@Ignore(value = MARIONETTE, issue = "https://github.com/mozilla/geckodriver/issues/620")
275277
public void handleFormWithJavascriptAction() {
276278
String url = appServer.whereIs("form_handling_js_submit.html");
277279
driver.get(url);
278280
WebElement element = driver.findElement(By.id("theForm"));
279281
element.submit();
280-
Alert alert = driver.switchTo().alert();
282+
Alert alert = wait.until(alertIsPresent());
281283
String text = alert.getText();
282284
alert.accept();
283285

0 commit comments

Comments
 (0)