예제 #1
0
  // odi.614 Able to generate reports for time range
  public void search() {
    String dmName = "US_AIRWAYS";
    gotoreports(dmName);
    try {
      driver.findElement(By.id("PARAM_START_DATE")).clear();
      Alert alert = driver.switchTo().alert();
      alert.dismiss();
      driver.findElement(By.id("PARAM_START_DATE")).sendKeys("8/11/2013");
      driver.findElement(By.id("PARAM_END_DATE")).clear();
      alert.dismiss();
      driver.findElement(By.id("PARAM_END_DATE")).sendKeys("9/11/2013");
      driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
      driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
      new WebDriverWait(driver, 10)
          .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("reportContent"));
      WebElement page =
          new WebDriverWait(driver, 10)
              .until(ExpectedConditions.visibilityOfElementLocated(By.id("CrystalViewer")));
      WebElement rangeStart = page.findElement(By.xpath("//*[contains(text(),'8/11/2013')]"));
      WebElement rangeEnd = page.findElement(By.xpath("//*[contains(text(),'9/11/2013')]"));
      if (rangeStart != null && rangeEnd != null) {
        System.out.println("Report for selected range is showed");
      }
      ReportFile = new WriteXmlFile();
      driver.switchTo().defaultContent();
      ReportFile.addTestCase("ODI6.x-614:CSSR-Search", "ODI6.x-614:CSSR-Search => Pass");

    } catch (Exception e) {
      System.out.print("trace: ");
      e.printStackTrace();
    }
    // driver.quit();
    ReportFile.WriteToFile();
  }
예제 #2
0
 public TrashSubPage emptyTrash() {
   findElementWaitUntilEnabledAndClick(By.id(EMPTY_TRASH_BUTTON_ID));
   Alert alert = driver.switchTo().alert();
   assertEquals("Permanently delete all documents in trash?", alert.getText());
   alert.accept();
   return asPage(TrashSubPage.class);
 }
예제 #3
0
  // Accept a confirmation
  public void waitForConfirmation(String confirmationText, int... wait) {
    String message = getTextFromAlert();
    int timeOut = wait.length > 0 ? wait[0] : DEFAULT_TIMEOUT;

    // log("confirmation: " + message);
    if (message.isEmpty()) {
      if (loopCount > timeOut / 500) {
        Assert.fail("Message is empty");
      }
      Utils.pause(500);
      loopCount++;
      waitForConfirmation(confirmationText);
      return;
    }

    for (int second = 0; ; second++) {
      if (second >= timeOut) {
        Assert.fail("Timeout at waitForConfirmation: " + confirmationText);
      }
      if (message.contains(confirmationText)) {
        break;
      }

      Utils.pause(100);
    }
    Alert alert = driver.switchTo().alert();
    alert.accept();
    Utils.pause(3000);
  }
  @Test
  public void basicPromptConfirmHandlingAcceptTest() {

    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.accept();

    assertEquals("change me", 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());
  }
예제 #6
0
  protected File savePageSourceToFile(String fileName, WebDriver webdriver, boolean retryIfAlert) {
    File pageSource = new File(reportsFolder, fileName + ".html");

    try {
      writeToFile(webdriver.getPageSource(), pageSource);
    } catch (UnhandledAlertException e) {
      if (retryIfAlert) {
        try {
          Alert alert = webdriver.switchTo().alert();
          log.severe(e + ": " + alert.getText());
          alert.accept();
          savePageSourceToFile(fileName, webdriver, false);
        } catch (Exception unableToCloseAlert) {
          log.severe("Failed to close alert: " + unableToCloseAlert);
        }
      } else {
        printOnce("savePageSourceToFile", e);
      }
    } catch (UnreachableBrowserException e) {
      writeToFile(e.toString(), pageSource);
      return pageSource;
    } catch (Exception e) {
      writeToFile(e.toString(), pageSource);
      printOnce("savePageSourceToFile", e);
    }
    return pageSource;
  }
예제 #7
0
 protected void checkAlert() {
   try {
     Alert alert = driver.switchTo().alert();
     alert.accept();
   } catch (Exception e) {
   }
 }
  @Test
  public void test() throws InterruptedException {
    // Alert popup Handling.
    driver.findElement(By.xpath("input[@value='Show Me Alert']")).click();
    // To locate alert
    Alert A1 = driver.switchTo().alert();
    // To read the text from alert popup.
    String Alert1 = A1.getText();
    System.out.println(Alert1);
    Thread.sleep(2000);
    // To accept/Click OK on the alert popup
    A1.accept();

    // Confirmation Pop up handling.
    driver.findElement(By.xpath("//button[@onlick='myFunction()']")).click();
    Alert A2 = driver.switchTo().alert();
    String Alert2 = A2.getText();
    System.out.println(Alert2);
    Thread.sleep(2000);
    // To Click on cancel button of confirmation box.
    A2.dismiss();

    // Prompt pop up handling.
    driver.findElement(By.xpath("//button[contains(.,'Show Me Prompt')]")).click();
    Alert A3 = driver.switchTo().alert();
    String Alert3 = A3.getText();
    System.out.println(Alert3);
    // To type text Im text box of prompt pop up.
    A3.sendKeys("This is John");
    Thread.sleep(2000);
    A3.accept();
  }
  protected void acceptConfirmation() {
    WebDriver.TargetLocator targetLocator = switchTo();

    Alert alert = targetLocator.alert();

    alert.accept();
  }
예제 #10
0
  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();

    File file = new File("src/form.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);

    dr.get(filePath);
    Thread.sleep(1000);

    dr.findElement(By.cssSelector("input[type=checkbox]")).click();
    Thread.sleep(1000);

    dr.findElement(By.cssSelector("input[type=radio]")).click();
    Thread.sleep(1000);

    List<WebElement> options =
        dr.findElement(By.tagName("select")).findElements(By.tagName("option"));
    options.get(options.size() - 1).click();
    Thread.sleep(1000);

    dr.findElement(By.cssSelector("input[type=submit]")).click();

    Alert alert = dr.switchTo().alert();
    System.out.println(alert.getText());
    alert.accept();

    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit();
  }
예제 #11
0
  public void AlertHandler() {
    try {
      Alert alert = driver.switchTo().alert();
      alert.accept();
    } catch (Exception e) {

    }
  }
예제 #12
0
 // Get Text
 public String getTextFromAlert() {
   Utils.pause(1000);
   try {
     Alert alert = driver.switchTo().alert();
     return alert.getText();
   } catch (NoAlertPresentException e) {
     return "";
   }
 }
예제 #13
0
파일: alrt.java 프로젝트: tskreddyt/hello
 public static void main(String[] args) {
   WebDriver wd = new FirefoxDriver();
   wd.get("http://www.tizag.com/javascriptT/javascriptalert.php");
   wd.findElement(
           By.xpath("/html/body/table[3]/tbody/tr[1]/td[2]/table/tbody/tr/td/div[4]/form/input"))
       .click();
   Alert a = wd.switchTo().alert();
   a.dismiss();
 }
예제 #14
0
 // Cancel an Alert
 public void cancelAlert() {
   try {
     Alert alert = driver.switchTo().alert();
     alert.dismiss();
     switchToParentWindow();
   } catch (NoAlertPresentException e) {
   }
   Utils.pause(1000);
 }
  public static void main(String[] args) throws InterruptedException {
    System.setProperty(
        "webdriver.chrome.driver",
        "C:\\Users\\jakther\\Desktop\\jahed\\java\\chromedriver\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.get("https://test.salesforce.com");
    Thread.sleep(2000);

    driver.findElement(By.id("username")).sendKeys("*****@*****.**");
    driver.findElement(By.id("password")).sendKeys("06082003Tuba");
    driver.findElement(By.id("Login")).click();
    Thread.sleep(2000);
    driver.findElement(By.id("Account_Tab")).click();
    Thread.sleep(2000);
    List<WebElement> list = driver.findElements(By.cssSelector(".dataCell>a"));
    System.out.println(list.size());
    for (int i = 0; i < list.size(); i++) {
      WebElement ele =
          driver.findElement(
              By.xpath(
                  ".//*[@id='bodyCell']/div[3]/div[1]/div/div[2]/table/tbody/tr["
                      + (i + 2)
                      + "]/th/a"));
      System.out.println(ele.getText());

      switch (ele.getText()) {
        case "MD J Akther":
          ele.click();
          Thread.sleep(2000);
          driver.findElement(By.xpath(".//*[@id='topButtonRow']/input[4]")).click();
          Thread.sleep(2000);

          try {
            Alert alert = driver.switchTo().alert();
            alert.accept();
            Thread.sleep(2000);
          } catch (Exception e) {
          }
          break;

        case "Akther Nabil":
          ele.click();
          Thread.sleep(2000);
          driver.findElement(By.xpath(".//*[@id='topButtonRow']/input[4]")).click();
          Thread.sleep(2000);

          try {
            Alert alert = driver.switchTo().alert();
            alert.accept();
            Thread.sleep(2000);
          } catch (Exception e) {
          }
          break;
        default:
      }
    }
  }
예제 #16
0
 public void clickPopUp() {
   try {
     Alert alert = driver.switchTo().alert();
     // System.out.println("Read from popup: " + alert.getText());
     alert.accept();
   } catch (Exception e) {
     System.out.println("Alert not present");
   }
 }
 public static void VerifyPopUpForDelete() throws Exception {
   GenericClass.clickElement(FstCheckBox);
   GenericClass.clickElement(DeleteSeasonBtn);
   Alert al = GenericClass.driver.switchTo().alert();
   al.getText();
   al.dismiss();
   System.out.print("Alert Message");
   Reporter.log("Pop up showing when deleting Season", true);
 }
예제 #18
0
 // Input text
 public void inputAlertText(String text) {
   try {
     Alert alert = driver.switchTo().alert();
     alert.sendKeys(text);
     alert.accept();
     switchToParentWindow();
   } catch (NoAlertPresentException e) {
   }
   Utils.pause(1000);
 }
  @Override
  public String getAlert() {
    switchTo();

    WebDriverWait webDriverWait = new WebDriverWait(this, 1);

    Alert alert = webDriverWait.until(ExpectedConditions.alertIsPresent());

    return alert.getText();
  }
  @Before
  public void setUp() {
    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().window().maximize();

    driver.get("https://alpha-external.pay.naver.com/npoint/pay/charge.nhn?CHNL=NV#");
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    // 일반 로그인
    driver.findElement(By.id("id")).sendKeys("nvqa_bill111");
    driver.findElement(By.id("pw")).sendKeys("btest789");
    driver.findElement(By.cssSelector("input.int_jogin")).click();

    // 사파리 진입 시, 알럿확인
    try {
      Alert alert = driver.switchTo().alert();
      // String textOnAlert = alert.getText();
      alert.accept();

      // assertEquals("계좌이체 및 신용카드포인트 결제는 IE에서 가능합니다.", textOnAlert);
    } catch (NoAlertPresentException e) {
      e.printStackTrace();
    }

    // 확인해주세요 팝업 확인

    /*	String parentWindowId = driver.getWindowHandle();

    		Set<String> allWindows = driver.getWindowHandles();
    		if (!allWindows.isEmpty()) {
    			for (String windowID : allWindows) {
    				driver.switchTo().window(windowID);
    				if (driver.getPageSource().contains("확인해 주세요.")) {
    					try {
    						WebElement noMoreButton = driver
    								.findElement(By
    										.xpath("//*[@id='infoPopupNGCASH']/div/p/span"));
    						noMoreButton.click();

    						WebElement identifyButton = driver
    								.findElement(By
    										.xpath("//*[@id='infoPopupNGCASH']/div/p/a/img"));
    						identifyButton.click();
    						break;
    					} catch (NoSuchWindowException e) {
    						e.printStackTrace();
    					}
    				}
    			}
    		}

    		driver.switchTo().window(parentWindowId);
    */
  }
예제 #21
0
  // Method for selecting a date
  public void pickAvalidDate() {
    driver.findElement(By.id("PARAM_START_DATE")).clear();
    Alert alert = driver.switchTo().alert();
    alert.dismiss();
    driver.findElement(By.id("PARAM_START_DATE")).sendKeys("08/01/2013");
    driver.findElement(By.id("PARAM_END_DATE")).clear();
    alert.dismiss();
    driver.findElement(By.id("PARAM_END_DATE")).sendKeys("09/01/2013");

    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
  }
  /** Alert dismiss meaning click on Cancel button */
  public void alertDismiss(MethodParameters model) {
    WebDriverWait wait = new WebDriverWait(WebDriverClass.getDriver(), 30);
    wait.until(ExpectedConditions.alertIsPresent());

    MainTestNG.LOGGER.info("inside alertDismiss()");
    wait1(2000);
    model.getElement().get(0).click();
    Alert alert = WebDriverClass.getInstance().switchTo().alert();
    wait1(2000);
    alert.dismiss();
  }
 private void More메뉴_Webtoon을_클릭한다() {
   More메뉴에_마우스를_가져다놓는다();
   moveAndClick(By.xpath("//*[@id=\"navi\"]/div/ul/li[6]/div/ul/li[2]/a"));
   new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent());
   // alert을 닫는다.
   try {
     Thread.sleep(5 * 1000);
   } catch (InterruptedException e) {
   }
   Alert alert = driver.switchTo().alert();
   alert.accept();
 }
 /** @param model Verify the alert text */
 public void verifyalertText(MethodParameters model) {
   model.getElement().get(0).click();
   wait1(1000);
   Alert alert = WebDriverClass.getInstance().switchTo().alert();
   wait1(1000);
   if (!(alertText == null)) {
     alertText = null;
   }
   alertText = alert.getText();
   Assert.assertEquals(alertText.toString(), model.getData());
   alert.accept();
 }
예제 #25
0
파일: New4.java 프로젝트: TKosmacki/CS1632
 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;
   }
 }
예제 #26
0
 /**
  * Close an Alert Pop Up
  *
  * @return
  */
 public boolean closeAlert() {
   // Get a handle to the open alert, prompt or confirmation
   try {
     Alert alert = se.driver().switchTo().alert();
     // And acknowledge the alert (equivalent to clicking "OK")
     alert.accept();
     se.log().logSeStep("Closing Alert");
     return true;
   } catch (Exception e) {
     // no alert
     se.log().logSeStep("Cannot Close Alert");
     e.printStackTrace();
     return false;
   }
 }
 protected String closeAlert(boolean confirm) {
   Alert alert = null;
   try {
     alert = webDriverCache.getCurrent().switchTo().alert();
     String text = alert.getText().replace("\n", "");
     if (!confirm) {
       alert.dismiss();
     } else {
       alert.accept();
     }
     return text;
   } catch (WebDriverException wde) {
     throw new Selenium2LibraryNonFatalException("There were no alerts");
   }
 }
  /** Alert accept meaning click on OK button */
  public void alertAccept(MethodParameters model) {

    WebDriverWait wait = new WebDriverWait(WebDriverClass.getDriver(), 30);
    wait.until(ExpectedConditions.alertIsPresent());

    MainTestNG.LOGGER.info("inside alertAccept()");

    wait1(2000);

    Alert alert = WebDriverClass.getInstance().switchTo().alert();
    wait1(2000);

    alert.accept();
    MainTestNG.LOGGER.info("completed alertAccept()");
  }
  public static String alertConfirm() {

    String alertText = "";
    try {
      Alert alert = driver.switchTo().alert();
      alertText = alert.getText();
      alert.dismiss();
      // or accept as below
      // alert.accept();

    } catch (NoAlertPresentException nape) {
      // nothing to do, because we only want to close it when pop up
      System.out.println("Alert not found!");
    }
    return alertText;
  }
  public static String getConfirmation(WebDriver webDriver) {
    webDriver.switchTo();

    WebDriverWait webDriverWait = new WebDriverWait(webDriver, 1);

    try {
      Alert alert = webDriverWait.until(ExpectedConditions.alertIsPresent());

      String confirmation = alert.getText();

      alert.accept();

      return confirmation;
    } catch (Exception e) {
      throw new WebDriverException();
    }
  }