예제 #1
0
 /**
  * Closes the active Pop Up, assumes only 1 Pop Up is open
  *
  * @return
  */
 public boolean closePopUp() {
   try {
     se.log().logSeStep("Closing PopUp:");
     if (currentPopUp != null) {
       se.driver().switchTo().window(currentPopUp).close();
       se.driver().switchTo().window(prevWindowHandle);
       se.util().sleep(1000);
       currentPopUp = null;
       prevWindowHandle = null;
       return true;
     } else {
       String currentWindow = se.driver().getWindowHandle();
       Set<String> windows = se.driver().getWindowHandles();
       for (Iterator<String> iterator = windows.iterator(); iterator.hasNext(); ) {
         String string = (String) iterator.next();
         if (!currentWindow.equals(string)) {
           se.driver().switchTo().window(string).close();
           se.driver().switchTo().window(currentWindow);
           se.util().sleep(1000);
           return true;
         }
       }
     }
     return false;
   } catch (Exception e) {
     se.log().logSeStep("Un-handled Exception in closePopUp:");
     se.log().logSeStep(e.getMessage());
     return false;
   }
 }
예제 #2
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;
  }
예제 #3
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();
  }
예제 #4
0
  // ODI6.x-628:Number formatting
  public void numberFormat() {
    String dmName = "US_AIRWAYS";
    gotoreports(dmName);
    pickAvalidDate();
    try {
      new WebDriverWait(driver, 10)
          .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("reportContent"));
      WebElement page =
          new WebDriverWait(driver, 10)
              .until(ExpectedConditions.visibilityOfElementLocated(By.id("CrystalViewer")));
      List<WebElement> check = page.findElements(By.tagName("span"));
      for (int i = 0; i < check.size(); i++) {
        content = check.get(i).getText();
        if (content.equals("Call Volume")) {
          contentValue = check.get(i + 1).getText();
          System.out.println(contentValue);
          decimalcheck(contentValue, "example", 0);
          System.out.println(contentValue);
        }
        if (content.equals("Call Duration (minutes)")) {
          contentValue = check.get(i + 1).getText();
          decimalcheck(contentValue, "In call duration", 2);
        } else if (content.equals("Average Call Duration (minutes)")) {
          contentValue = check.get(i + 1).getText();
          decimalcheck(contentValue, "In average call duration", 2);
        } else if (content.equals("Average Call Duration for Transferred Calls (minutes)")) {
          contentValue = check.get(i + 1).getText();
          decimalcheck(contentValue, "In average call duration for transfered calls", 2);
        } else if (content.equals("Peak Hour Average Call Duration (minutes)")) {
          contentValue = check.get(i + 1).getText();
          decimalcheck(contentValue, "In peak hour average call duration", 2);
        } else if (content.equals("Average Weekly Call Volume")) {
          contentValue = check.get(i + 1).getText();
          decimalcheck(contentValue, "Average Weekly call volume", 1);
        }

        if (content.equals("Transfer Rate (All)")) {
          String percentage = check.get(i + 1).getText();
          String[] contentValues = percentage.split("%");
          contentValue = contentValues[0];
          System.out.println(contentValue);
          decimalcheck(contentValue, "In Transfer Rate ", 1);
        } else if (content.equals("Containment Rate (All)")) {
          String percentage = check.get(i + 1).getText();
          String[] contentValues = percentage.split("%");
          contentValue = contentValues[0];
          System.out.println(contentValue);
          // System.out.println(NumberFormat.getNumberInstance(Locale.US).format(contentValue));
          decimalcheck(contentValue, "In Containment Rate ", 1);
        }
      }
      ReportFile.addTestCase(
          "ODI6.x-628:CSSR numbers Formatting", "ODI6.x-628:CSSR numbers Formatting => Pass");
    } catch (Exception e) {
      driver.quit();
      e.printStackTrace();
    }
    driver.quit();
  }
예제 #5
0
  /**
   * Get the current url of the browser.
   *
   * @return The url as a string.
   */
  public String getCurrentUrl() {

    try {
      return se.driver().getCurrentUrl();
    } catch (Exception e) {
      System.out.println("Unhandled Exception in getCurrentUrl");
      System.out.println(e.getMessage());
      return null;
    }
  }
예제 #6
0
  /**
   * Switch to a window containing a certain url
   *
   * @param url of window to switch to
   * @return
   */
  public String switchToWindowByUrl(String url) {
    try {
      return getHandleByUrl(url);
    } catch (Exception e) {
      System.out.println("Un-handled Exception in switchToWindowByUrl:");
      System.out.println(e.getMessage());
    }

    return null;
  }
예제 #7
0
 /**
  * executes javascript on the document and returns the result as a java Object
  *
  * @param javascript
  * @return
  */
 public Object executeJavascriptReturnsObject(String javascript, boolean log) {
   if (log) se.log().trace("Executing Javascript:" + javascript);
   try {
     Object result = ((JavascriptExecutor) se.driver()).executeScript(javascript);
     if (result != null) return result;
     else return null;
   } catch (Exception e) {
     System.out.println(e.getMessage());
     return null;
   }
 }
예제 #8
0
 public boolean browse(WebLocator el) {
   try {
     el.focus();
     Actions builder = new Actions(driver);
     builder.moveToElement(el.currentElement).perform();
     builder.click().perform();
     return true;
   } catch (Exception e) {
     LOGGER.error(e.getMessage(), e);
     return false;
   }
 }
예제 #9
0
 /**
  * Returns True of an Alert Pop Up is present
  *
  * @return
  */
 public boolean hasAlert() {
   // Get a handle to the open alert, prompt or confirmation
   try {
     se.driver().switchTo().alert();
     se.log().logSeStep("Has Alert");
     return true;
   } catch (Exception e) {
     // no alert
     se.log().logSeStep("No Alert");
     se.log().logSeStep(e.getMessage());
     return false;
   }
 }
예제 #10
0
 /**
  * Takes a screenshot and returns as a base64 encoded string.
  *
  * <p>Doesn't add to report directly.
  *
  * @return base64 encoded string of screenshot
  */
 public String takeScreenShot() {
   if (se.driver() == null) return null;
   WebDriver driver = se.driver();
   if (!(driver instanceof TakesScreenshot)) driver = (new Augmenter()).augment(driver);
   try {
     return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
   } catch (Exception e) {
     se.log().trace(e.getMessage());
     se.log().trace(e.getStackTrace().toString());
   }
   se.util().sleep(500);
   return null;
 }
예제 #11
0
 // Method that I invoke in findlablesfilter() function in the above method
 private void isElementpresent(String name, By by) {
   try {
     if (driver.findElement(by) != null) {
       System.out.println(name + " " + "Element  is Present");
     } else {
       // System.out.println("Element is Absent");
       throw new Exception(name + " " + "Element is absent");
     }
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
예제 #12
0
 /**
  * Executes javascript on an element and returns the result as a java String
  *
  * @param javascript snippit of javascript that returns a string
  * @param webElement Element to execute the javascript on, reference in snippit as "arguments[0]"
  * @return Returned value of the snippit
  */
 public String executeJavascriptOnWebElement(String javascript, WebElement webElement) {
   se.log()
       .logSeStep(
           "Executing Javascript on WebElement:" + javascript + ", " + webElement.toString());
   try {
     Object result = ((JavascriptExecutor) se.driver()).executeScript(javascript, webElement);
     if (result != null) return result.toString();
     else return "";
   } catch (Exception e) {
     System.out.println(e.getMessage());
     return "";
   }
 }
예제 #13
0
 /**
  * Closes a window containing a url
  *
  * @param url of window to close (matched using string.contains)
  * @return true if successful
  */
 public boolean closeWindowByUrl(String url) {
   try {
     se.log().logSeStep("Closing Window With Url:" + url);
     String windowHandle = getHandleByUrl(url);
     se.driver().switchTo().window(windowHandle);
     // return returnToPrevWindow();
     return closeCurrentWindow();
   } catch (Exception e) {
     se.log().logSeStep("Un-handled Exception in closeWindowByUrl:");
     se.log().logSeStep(e.getMessage());
     return false;
   }
 }
예제 #14
0
 /**
  * Closes a window by the window title
  *
  * @param windowTitle
  * @return true if successful
  */
 public boolean closeWindowByTitle(String windowTitle) {
   try {
     se.log().logSeStep("Closing Window With Title:" + windowTitle);
     String windowHandle = getHandleByTitle(windowTitle);
     se.driver().switchTo().window(windowHandle);
     // ((JavascriptExecutor) myDriver).executeScript("window.close()");
     // return returnToPrevWindow();
     return closeCurrentWindow();
   } catch (Exception e) {
     se.log().logSeStep("Un-handled Exception in closeWindowByTitle:");
     se.log().logSeStep(e.getMessage());
     return false;
   }
 }
예제 #15
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;
   }
 }
  public static void main(String[] args)
      throws MalformedURLException, UnsupportedEncodingException {

    System.out.println("Run started");
    driver = setupDriver(true);

    try {

      ArrayList<ArrayList<String>> list1 = new ArrayList<ArrayList<String>>();
      LinksTest listLinks1 = new LinksTest(driver);

      list1 = listLinks1.linksTest("www.google.co.il");
      list1 = listLinks1.getBrokenLinks();
      list1 = listLinks1.getListOfPageLinks();
      list1 = listLinks1.getLoadFailedLinks();
      list1 = listLinks1.getSucceededLinks();

      LinksTest listLinks2 = new LinksTest(driver, "www.google.co.il");
      list1 = listLinks2.linksTest();

      /*listLinks.getBrokenLinks();
      listLinks.getPageLinks();
      listLinks.getPageLinks("www.nxc.co.il");
      listLinks.printPageLinksStatus();
      listLinks.testLinks();
      listLinks.printPageLinksStatus();
      ArrayList<ArrayList<String>> links = listLinks.getBrokenLinks();
      links = listLinks.getLoadFailedLinks();
      links = listLinks.getSucceededLinks();*/
      /*listLinks.setUrl("www.google.co.il");
      listLinks.printPageLinksStatus();
      listLinks.getPageLinks();
      listLinks.printPageLinksStatus();
      listLinks.testLinks();
      listLinks.printPageLinksStatus();
      ArrayList<ArrayList<String>> links = listLinks.getBrokenLinks();
      links = listLinks.getLoadFailedLinks();
      links = listLinks.getSucceededLinks();*/

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      driver.quit();
    }

    System.out.println("Run ended");
  }
예제 #17
0
  /**
   * Switch to a window using the title
   *
   * @param title of window
   * @return true of successful
   */
  public String switchToWindow(String title) {

    try {
      if (prevWindow == null || prevWindow != title) {
        prevWindow = se.driver().getTitle();
        prevWindowHandle = se.driver().getWindowHandle();
        se.log().logSeStep("Saved Prev Window Title:" + prevWindow);
      }
      se.log().logSeStep("Switching To Window Title:" + title);
      return getHandleByTitle(title);
    } catch (Exception e) {
      se.log().logSeStep("Un-handled Exception in switchToWindow:");
      se.log().logSeStep(e.getMessage());
    }

    return null;
  }
예제 #18
0
  /**
   * Waits for the window title to contain windowTitle
   *
   * @param windowTitle Text for the window title to contain
   * @param timeOut Seconds to wait for the title to contain
   * @return True if WindowTitle found in title before timeOut
   */
  public boolean waitForWindowTitleToContain(String windowTitle, int timeOut) {
    se.log()
        .logSeStep("Waiting for Window Title to contain " + windowTitle + " (" + timeOut + " sec)");

    WebDriverWait wait = new WebDriverWait(se.driver(), timeOut);
    try {
      wait.until(windowTitleContains(windowTitle));
      return true;
    } catch (TimeoutException e) {
      se.log().logSeStep("Timed out waiting for Window Title to contain " + windowTitle);
      return false;
    } catch (Exception e) {
      String errorName = "Un-handled Exception in waitForWindowTitleToContain:";
      se.log().logSeStep(errorName + e.getMessage());
      return false;
    }
  }
예제 #19
0
 public void waitLoadjQueryElement() {
   if ((Boolean) ((JavascriptExecutor) this).executeScript("return window.jQuery != undefined")) {
     WebDriverWait webDriverWait = new WebDriverWait(this, 10);
     try {
       webDriverWait.until(
           new ExpectedCondition<Boolean>() {
             @Override
             public Boolean apply(WebDriver driver) {
               return (Boolean)
                   ((JavascriptExecutor) driver).executeScript("return window.jQuery.active == 0");
             }
           });
     } catch (Exception exc) {
       exc.printStackTrace();
     }
   }
 }
예제 #20
0
 /**
  * Used for initial get of first page Log.setTcStartTime(); is called. use get(url) to get pages
  * without overwriting the start time.
  *
  * @param url
  */
 public boolean openUrl(String url) {
   se.log().logSeStep("Open URL: " + url);
   try {
     se.driver().get(url);
     deleteCookies();
     se.log().setTcStartTime();
     se.driver().get(url);
   } catch (Exception e) {
     se.log()
         .logTcError(
             String.format(
                 "Unhandled Exception in openUrl %s: %s: %s: %s",
                 url, e, e.getMessage(), ExceptionUtils.getFullStackTrace(e)),
             takeScreenShot());
     return false;
   }
   return se.driver().getTitle() != null;
 }
예제 #21
0
 /**
  * Load a new url in the browser. Does not log the test case start time. Use openUrl() instead, if
  * this is the first url loaded for the test.
  *
  * @param url
  */
 public boolean get(String url) {
   se.log().logSeStep("Get URL: " + url);
   if (url == null) {
     se.log().logSeStep("url is null, nothing to get");
     return false;
   }
   try {
     se.driver().get(url);
   } catch (Exception e) {
     System.out.println("Unhandled Exception in Browser.get " + url);
     System.out.println(e.getMessage());
     return false;
   }
   if (se.driver().getTitle() == null
       || se.driver().getTitle().equals("Problem loading page")
       || se.driver().getTitle().contains("Oops! Google Chrome could not connect to")
       || se.driver().getTitle().equals("Internet Explorer cannot display the webpage")) {
     return false;
   } else return true;
 }
예제 #22
0
 // odi.618 Method for finding the lables of filters
 public void findthelables() {
   String dmname = "US_AIRWAYS";
   gotoreports(dmname);
   try {
     driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
     isElementpresent(Element1, By.id("date_range_label"));
     isElementpresent(Element2, By.id("PARAM_START_DATE_label"));
     isElementpresent(Element3, By.id("PARAM_END_DATE_label"));
     isElementpresent(Element4, By.id("PARAM_TIME_ZONE_label"));
     isElementpresent(Element5, By.id("PARAM_APP_ID_label"));
     isElementpresent(Element6, By.id("PARAM_DNIS_label"));
     isElementpresent(Element7, By.id("PARAM_LOCALE_label"));
     ReportFile.addTestCase(
         "ODI6.x-618:Labeling of Call Stat Summary filters",
         "ODI6.x-618:Labeling of Call Stat Summary filters => Pass");
   } catch (Exception e) {
     System.out.print("trace: ");
     e.printStackTrace();
   }
   ReportFile.WriteToFile();
 }
예제 #23
0
 // Method for getting to reports page
 public void gotoreports(String domainName) {
   gotohomepage();
   choosedomain(domainName);
   try {
     // click on On Demand Insight
     WebElement odi =
         (new WebDriverWait(driver, 10))
             .until(ExpectedConditions.elementToBeClickable(By.xpath(odipath)));
     odi.click();
     WebElement report =
         (new WebDriverWait(driver, 10))
             .until(ExpectedConditions.elementToBeClickable(By.xpath(reportspath)));
     report.click();
     WebElement cssr =
         (new WebDriverWait(driver, 10))
             .until(ExpectedConditions.elementToBeClickable(By.xpath(cssrpath)));
     cssr.click();
   } catch (Exception e) {
     System.out.print("trace: ");
     e.printStackTrace();
   }
 }
예제 #24
0
 // odi.620 Method that the report footer a/b filter should match all as it specified in left side
 // panel
 public void abfilter() {
   String dmName = "METROPCS";
   gotoreports(dmName);
   try {
     driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
     new WebDriverWait(driver, 10)
         .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("reportContent"));
     WebElement page =
         new WebDriverWait(driver, 10)
             .until(ExpectedConditions.visibilityOfElementLocated(By.id("CrystalViewer")));
     WebElement tag = page.findElement(By.xpath("//*[contains(text(),'A/B')]"));
     if (tag != null) {
       System.out.println("A/B Combo ID: NVP 5.0.0-NDF 6.1.0-0.0.0.1 filter is present");
       ReportFile.addTestCase(
           "ODI6.x-620:A/B filter: should be in the report footer",
           "ODI6.x-620:A/B filter: should be in the report footer => Pass");
     }
   } catch (Exception e) {
     System.out.print("trace: ");
     e.printStackTrace();
   }
 }
예제 #25
0
 /**
  * Returns if Popup is present and switches context to the popup window if present.
  *
  * @return true if popup is present, and switches test context to the popup.
  */
 public boolean isPopup() {
   try {
     se.log().logSeStep("Checking for PopUp:");
     String currentWindow = se.driver().getWindowHandle();
     Set<String> windows = se.driver().getWindowHandles();
     for (Iterator<String> iterator = windows.iterator(); iterator.hasNext(); ) {
       String string = (String) iterator.next();
       if (!currentWindow.equals(string)) {
         se.log().logSeStep("PopUp Found");
         currentPopUp = string;
         prevWindowHandle = currentWindow;
         se.driver().switchTo().window(currentPopUp);
         se.log().logSeStep("Switching Context to PopUp window: " + se.driver().getTitle());
         return true;
       }
     }
     return false;
   } catch (Exception e) {
     se.log().logSeStep("Un-handled Exception in isPopup:");
     se.log().logSeStep(e.getMessage());
     return false;
   }
 }
예제 #26
0
  // odi.623.Method for DNIS value search
  public void dnisfilter() {
    String dmName = "US_AIRWAYS";
    gotoreports(dmName);
    try {
      WebElement DNISvalue = driver.findElement(By.id("PARAM_DNIS"));
      Select select = new Select(DNISvalue);
      select.deselectAll();
      select.selectByValue("2404953077");
      driver
          .manage()
          .timeouts()
          .implicitlyWait(
              20,
              TimeUnit
                  .SECONDS); // submit should be clickable if delay is there in selecting the DNIS
      driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
      new WebDriverWait(driver, 10)
          .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("reportContent"));
      WebElement page =
          new WebDriverWait(driver, 10)
              .until(ExpectedConditions.visibilityOfElementLocated(By.id("CrystalViewer")));
      WebElement tag = page.findElement(By.xpath("//*[contains(text(),'2404953077')]"));
      if (tag != null) {
        System.out.println("DNIS:2404953077 filter is present");
        ReportFile.addTestCase(
            "ODI6.x-623:DNIS filter: selected DNIS filter should be shown in report result",
            "ODI6.x-623:DNIS filter: selected DNIS filter should be shown in report result => Pass");
      }

    } catch (Exception e) {
      System.out.print("trace: ");
      e.printStackTrace();
    }
    // driver.quit();
    ReportFile.WriteToFile();
    driver.switchTo().defaultContent();
  }
예제 #27
0
  // li.active>span.next
  public static void main(String[] args) {

    if (args.length < 2) {
      System.out.println("please input two paremeter!");
      System.exit(0);
    }
    String filePath = args[0];
    String phantomJsPath = args[1];

    DesiredCapabilities cap = DesiredCapabilities.phantomjs();
    cap.setCapability(
        PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
        new String[] {
          //                       "--webdriver-loglevel=DEBUG",
          //			"--proxy=org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
        });
    cap.setCapability(
        PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "zh_CN");
    // cap.setCapability("phantomjs.page.settings.userAgent","Mozilla/5.0 (Macintosh; Intel Mac OS X
    // 10.9; rv:25.0) Gecko/20100101 Firefox/25.0");
    // "C:\\Users\\Administrator\\Desktop\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe"
    cap.setCapability("phantomjs.binary.path", phantomJsPath);
    cap.setJavascriptEnabled(true);
    driver = new PhantomJSDriver(cap);

    WebDriverWait wait = null;
    wait = new WebDriverWait(driver, 60);
    driver.get(URL);
    /*try {
        Thread.currentThread().sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }*/
    // screenShot((TakesScreenshot) driver, "/home/admin/"+"mo9"+c+".png");
    List<WebElement> nextElement = null;
    ArrayList<String> credits = new ArrayList<String>();

    int prePage = 1;
    int curPage = c;
    BufferedWriter br = null;
    File f = new File(filePath);
    try {
      br = new BufferedWriter(new FileWriter(f, true));
      br.write("mo9账号,真实姓名,身份证号,欠款金额,逾期天数");
      br.write("\r\n");
    } catch (IOException e1) {
      e1.printStackTrace();
    } finally {
      if (br != null) {
        try {
          br.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    while (!isLast) {
      List<WebElement> elements = null;
      try {
        elements =
            wait.until(
                ExpectedConditions.visibilityOfAllElementsLocatedBy(
                    By.cssSelector("div.faith-list>dl.fs12")));

      } catch (Exception e) {
        e.printStackTrace();
        driver.close();
        driver.quit();
        while (elements == null) {
          try {

            Thread.currentThread().sleep(720000);
            // c=((curPage/15)*15)+1;
            // curPage=c;
            driver = new PhantomJSDriver(cap);
            // driver=new FirefoxDriver(binary,profile);

            wait = new WebDriverWait(driver, 60);
            driver.get("https://www.mo9.com/creditCenter/p/" + curPage);
            elements =
                wait.until(
                    ExpectedConditions.visibilityOfAllElementsLocatedBy(
                        By.cssSelector("div.faith-list>dl.fs12")));
          } catch (Exception e1) {
            e1.printStackTrace();
          }
        }
      }

      System.out.println(curPage);
      for (WebElement element : elements) {
        StringBuffer sb = new StringBuffer();
        String acount =
            element.findElement(By.cssSelector("div.faith-list>dl.fs12>dt.row01")).getText();
        String name =
            element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row02")).getText();
        String certiCard =
            element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row03")).getText();
        String debt =
            element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row04")).getText();
        String overDue =
            element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row05")).getText();
        sb.append(acount + "," + name + "," + certiCard + "," + debt + "," + overDue);
        credits.add(sb.toString());
      }
      nextElement = driver.findElements(By.cssSelector("li>a.next"));

      if (credits.size() % 150 == 0 || nextElement.size() == 0) {
        try {
          br = new BufferedWriter(new FileWriter(f, true));
          for (String str : credits) {
            br.write(str);
            br.write("\r\n");
          }
          credits.clear();
        } catch (IOException e) {
          e.printStackTrace();
        } finally {
          if (br != null) {
            try {
              br.close();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
        try {
          // Random r=new Random(100);
          // int n=r.nextInt(90);
          Thread.currentThread().sleep(20000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }

      if (nextElement.size() == 0) {
        isLast = true;
      } else {
        nextElement.get(0).click();
        curPage++;
        try {
          Thread.currentThread().sleep(2000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
예제 #28
0
  // ODI6.x-627:generate cssr report with valid filters and check the number if they are reasonable
  public void cssrNumbers() {
    int CallVolumeValue = 0, TransfersValue = 0, PeakHourValue = 0;
    double roundOff = 0, AverageCallValue = 0;
    String dmName = "US_AIRWAYS";
    gotoreports(dmName);
    pickAvalidDate();
    try {
      new WebDriverWait(driver, 10)
          .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("reportContent"));
      WebElement page =
          new WebDriverWait(driver, 10)
              .until(ExpectedConditions.visibilityOfElementLocated(By.id("CrystalViewer")));
      List<WebElement> check = page.findElements(By.tagName("span"));
      for (int i = 0; i < check.size(); i++) {
        String content = (check.get(i).getText());
        if (content.equals("Call Volume")) {
          String CallVolume = (check.get(i + 1).getText());
          String[] CallVolumes = CallVolume.split("\\s");
          CallVolumeValue = Integer.parseInt(CallVolumes[1]);
          System.out.println(CallVolumeValue);
        } else if (content.equals("Transfers (All)")) {
          String TransfersAll = (check.get(i + 1).getText());
          String[] Tvalues = TransfersAll.split("\\s");
          TransfersValue = Integer.parseInt(Tvalues[1]);
          System.out.println(TransfersValue);
        } else if (content.equals("Peak Hour Call Volume")) {
          String PeakHourCallVolume = (check.get(i + 1).getText());
          String[] PeakHourCallValues = PeakHourCallVolume.split("\\s");
          PeakHourValue = Integer.parseInt(PeakHourCallValues[1]);
        } else if (content.equals("Call Duration (minutes)")) {
          String CallDuration = (check.get(i + 1).getText());
          String[] CallDurationValues = CallDuration.split("\\s");
          double CallDurationValue = Double.parseDouble(CallDurationValues[1]);
          double x = CallDurationValue / CallVolumeValue;
          roundOff = Math.round(x * 100.0) / 100.0;
        } else if (content.equals("Average Call Duration (minutes)")) {
          String AverageCallDuration = (check.get(i + 1).getText());
          String[] AverageCallDurationValues = AverageCallDuration.split("\\s");
          AverageCallValue = Double.parseDouble(AverageCallDurationValues[1]);
        }
      }
      try {
        if (CallVolumeValue >= TransfersValue) {
          logger.info("the call volume is greater than the Transfer");
          System.out.println("CallVolumeValue >= TransfersValue");
        }
        if (PeakHourValue <= CallVolumeValue) {
          System.out.println("PeakHourValue <= CallVolumeValue");
        }
        if (AverageCallValue == roundOff) {
          System.out.println("Average Call Duration =Call Duration (minutes)/Call Volume");
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
      ReportFile.addTestCase(
          "ODI6.x-627:CSSR numbers must be reasonable",
          "ODI6.x-627:CSSR numbers must be reasonable => Pass");
    } catch (Exception e) {
      e.printStackTrace();
    }
    ReportFile.WriteToFile();
    driver.quit();
  }