@Test
  public void basicPromptConfirmHandlingChangeAndDismissTest() {

    WebElement promptButton;
    WebElement promptResult;

    promptButton = driver.findElement(By.id("promptexample"));
    promptResult = driver.findElement(By.id("promptreturn"));

    assertEquals("pret", promptResult.getText());
    promptButton.click();

    String alertMessage = "I prompt you";

    Alert promptAlert = driver.switchTo().alert();

    if (Driver.currentDriver != Driver.BrowserName.IE) {
      // no point doing this in IE as we know it isn't the actual prompt
      assertEquals(alertMessage, promptAlert.getText());
    }

    promptAlert.sendKeys("Hello");
    promptAlert.dismiss();

    assertEquals("pret", promptResult.getText());
  }
  @Test
  public void basicPromptConfirmHandlingDismissTest() {

    WebElement promptButton;
    WebElement promptResult;

    promptButton = driver.findElement(By.id("promptexample"));
    promptResult = driver.findElement(By.id("promptreturn"));

    assertEquals("pret", promptResult.getText());
    promptButton.click();

    String alertMessage = "I prompt you";

    Alert promptAlert = driver.switchTo().alert();

    if (Driver.currentDriver == Driver.BrowserName.IE) {
      // In IE the alert always returns "Script Prompt:" and not the
      // actual prompt text, so this line is just to alert me if the
      // functionality changes
      if (!promptAlert.getText().equals("Script Prompt:")) {
        throw new RuntimeException("IE now does not do Script Prompt");
      }

    } else {
      // only check the alert prompt if not in IE
      assertEquals(alertMessage, promptAlert.getText());
    }

    promptAlert.dismiss();

    assertEquals("pret", promptResult.getText());
  }
Esempio n. 3
0
 private String closeAlertAndGetItsText() {
   try {
     Alert alert = driver.switchTo().alert();
     String alertText = alert.getText();
     if (acceptNextAlert) {
       alert.accept();
     } else {
       alert.dismiss();
     }
     return alertText;
   } finally {
     acceptNextAlert = true;
   }
 }
Esempio n. 4
0
  @JavascriptEnabled
  @Ignore({ANDROID, HTMLUNIT, IE, IPHONE, SELENESE})
  public void testShouldAllowUsersToDismissAnAlertManually() {
    if (!isCapableOfHandlingAlerts(driver)) {
      return;
    }

    driver.get(alertPage);

    driver.findElement(By.id("alert")).click();

    Alert alert = switchToAlert(driver);
    alert.dismiss();

    // If we can perform any action, we're good to go
    assertEquals("Testing Alerts", driver.getTitle());
  }
Esempio n. 5
0
  @Ignore
  public void testAlertShouldNotAllowAdditionalCommandsIfDimissed() {
    if (!isCapableOfHandlingAlerts(driver)) {
      return;
    }

    driver.get(alertPage);

    driver.findElement(By.id("alert")).click();

    Alert alert = switchToAlert(driver);
    alert.dismiss();

    try {
      alert.getText();
    } catch (NoAlertPresentException expected) {
    }
  }
  @Test
  public void basicConfirmHandlingDismissTest() {

    WebElement confirmButton;
    WebElement confirmResult;

    confirmButton = driver.findElement(By.id("confirmexample"));
    confirmResult = driver.findElement(By.id("confirmreturn"));

    assertEquals("cret", confirmResult.getText());
    confirmButton.click();

    String alertMessage = "I am a confirm alert";

    Alert confirmAlert = driver.switchTo().alert();

    assertEquals(alertMessage, confirmAlert.getText());

    confirmAlert.dismiss();

    assertEquals("false", confirmResult.getText());
  }
Esempio n. 7
0
 public void cancelAlert() {
   Alert alert = driver.switchTo().alert();
   alert.dismiss();
 }