Example #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();
  }
Example #2
0
  @JavascriptEnabled
  @Ignore(OPERA)
  @Test
  public void testDragAndDropOnJQueryItems() {
    driver.get(pages.droppableItems);

    WebElement toDrag = driver.findElement(By.id("draggable"));
    WebElement dropInto = driver.findElement(By.id("droppable"));

    // Wait until all event handlers are installed.
    doSleep(500);

    new Actions(driver).dragAndDrop(toDrag, dropInto).perform();

    String text = dropInto.findElement(By.tagName("p")).getText();

    long waitEndTime = System.currentTimeMillis() + 15000;

    while (!text.equals("Dropped!") && (System.currentTimeMillis() < waitEndTime)) {
      doSleep(200);
      text = dropInto.findElement(By.tagName("p")).getText();
    }

    assertEquals("Dropped!", text);

    WebElement reporter = driver.findElement(By.id("drop_reports"));
    // Assert that only one mouse click took place and the mouse was moved
    // during it.
    String reporterText = reporter.getText();
    Pattern pattern = Pattern.compile("start( move)* down( move)+ up( move)*");

    Matcher matcher = pattern.matcher(reporterText);

    assertTrue("Reporter text:" + reporterText, matcher.matches());
  }
  // Returns the number of replies to a post
  protected int getPostRepliesCount(String strPostDataPath) {
    int nReplies = 0;

    WebElement elemPost = getPostByDataPathOrFail(strPostDataPath);

    String strReplies = null;

    setDefaultWaitTime(2);

    try {
      /*
      <div class="detail-entry-replies">
          <i class="icon-replies" title="Replies"></i>
          <span class="replies-count" title="Replies">0</span>
      */
      String strRepliesXPath = ".//span[@class='replies-count' and @title='Replies']";
      WebElement elemRepliesCount = elemPost.findElement(By.xpath(strRepliesXPath));

      strReplies = elemRepliesCount.getText();
    } catch (NoSuchElementException ex) {
      fail(
          "Could not find the number of replies on the post with the data path " + strPostDataPath);
    }

    resetDefaultWaitTime();

    try {
      nReplies = Integer.parseInt(strReplies);
    } catch (NumberFormatException ex) {
      fail("Could not parse an integer out of \"" + strReplies + "\": " + ex.getMessage());
    }

    return nReplies;
  } // getPostRepliesCount
 @Ignore({MARIONETTE})
 @Test(expected = InvalidSelectorException.class)
 public void
     testShouldThrowInvalidSelectorExceptionWhenXPathIsSyntacticallyInvalidInElementFindElement() {
   driver.get(pages.formPage);
   WebElement body = driver.findElement(By.tagName("body"));
   body.findElement(By.xpath("this][isnot][valid"));
 }
  @Ignore({REMOTE})
  @Test
  public void testLinkWithFormattingTags() {
    driver.get(pages.simpleTestPage);
    WebElement elem = driver.findElement(By.id("links"));

    WebElement res = elem.findElement(By.partialLinkText("link with formatting tags"));
    assertThat(res.getText(), is("link with formatting tags"));
  }
  @Ignore({MARIONETTE})
  @Test(expected = InvalidSelectorException.class)
  public void
      testShouldThrowInvalidSelectorExceptionWhenXPathReturnsWrongTypeInElementFindElement() {
    driver.get(pages.formPage);

    WebElement body = driver.findElement(By.tagName("body"));
    body.findElement(By.xpath("count(//input)"));
  }
 @Ignore({SELENESE, IPHONE, ANDROID})
 @Test
 public void testShouldSubmitAFormUsingTheEnterKey() {
   driver.get(pages.formPage);
   WebElement nestedForm = driver.findElement(By.id("nested_form"));
   WebElement input = nestedForm.findElement(By.name("x"));
   input.sendKeys(Keys.ENTER);
   waitFor(pageTitleToBe(driver, "We Arrive Here"));
   assertTrue(driver.getCurrentUrl().endsWith("?x=name"));
 }
Example #8
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();
   }
 }
Example #9
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();
  }
 @Override
 public WebElement findElement(WebElement element, By by) {
   return element.findElement(by);
 }
Example #11
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();
        }
      }
    }
  }
  // Returns true if a post has a specific status, such as the Approved icon appears on it
  protected Boolean postHasStatus(String strPostDataPath, PostStatus status) {
    Boolean bPostHasSpecificStatus = false;

    /*
    <article class="card-collection card-page foundation-collection-item cq-gui-admin-open quickaction" data-path="...">
        <div class="selectable qaanchor" data-path="...">
            <div class="detail-entry-replies">
                <i class="icon-flag" title="Flagged"></i>
    */
    String strStatusIconXPath = null;

    switch (status) {
      case Flagged:
        {
          // <i class="icon-flag" title="Flagged"></i>
          strStatusIconXPath = ".//i[@class='icon-flag' and @title='Flagged']";
          break;
        }
      case Pending:
        {
          // <i class="icon-pending" title="Pending"></i>
          strStatusIconXPath = ".//i[@class='icon-pending' and @title='Pending']";
          break;
        }
      case Approved:
        {
          // <i class="icon-check" title="Approved"></i>
          strStatusIconXPath = ".//i[@class='icon-check' and @title='Approved']";
          break;
        }
      case Denied:
        {
          // <i class="icon-exclude" title="Denied"></i>
          strStatusIconXPath = ".//i[@class='icon-exclude' and @title='Denied']";
          break;
        }
      case Spam:
        {
          // <i class="icon-spam" title="Spam"></i>
          strStatusIconXPath = ".//i[@class='icon-spam' and @title='Spam']";
          break;
        }
      default:
        {
          fail("postHasStatus() called with an unsupported post status: " + status.toString());
        }
    } // switch

    WebElement elemPost = getPostByDataPathOrFail(strPostDataPath);

    setDefaultWaitTime(2);

    try {
      WebElement elemStatusIcon = elemPost.findElement(By.xpath(strStatusIconXPath));

      bPostHasSpecificStatus = true;
    } catch (NoSuchElementException ex) {
      bPostHasSpecificStatus = false;
    }

    resetDefaultWaitTime();

    return bPostHasSpecificStatus;
  } // postHasStatus
 @Override
 public WebElement findElement(By by) {
   return webElement.findElement(by);
 }