@Test
  public void simpletest01() throws Exception {

    util.type(By.name("query"), "Test");
    util.clickAndWait(By.className("sch_submit"));
    System.out.println(util.getCapabilities().getPlatform());
  }
 private void doSomething() {
   WebDriver driver = WebDriverFactory.getDriver(DesiredCapabilities.firefox());
   driver.get("http://seleniumhq.org/");
   driver.findElement(By.name("q")).sendKeys("selenium");
   driver.findElement(By.id("submit")).click();
   new WebDriverWait(driver, 30).until(ExpectedConditions.titleContains("Google Custom Search"));
 }
예제 #3
0
/** @author Aliaksei Boole */
public class EditCommentForm extends AbstractCommentForm {
  private static final String FORM_DIV_CSS = "DIV[class='comments-list']>DIV[class='comment-form']";
  private static final By FORM_DIV = By.cssSelector(FORM_DIV_CSS);
  private static final By AVATAR = By.cssSelector(FORM_DIV_CSS + ">img");
  private static final By CANCEL_BUTTON =
      By.cssSelector(FORM_DIV_CSS + " span[class~='yui-reset-button']>span>button");
  public static final By SUBMIT_BUTTON =
      By.cssSelector(FORM_DIV_CSS + " span[class~='yui-submit-button']>span>button");

  public void clickSaveCommentButton() {
    click(SUBMIT_BUTTON);
  }

  public void clickCancelButton() {
    click(CANCEL_BUTTON);
  }

  public boolean isDisplay() {
    return isElementDisplayed(FORM_DIV);
  }

  public boolean isAvatarDisplay() {
    return isElementDisplayed(AVATAR);
  }

  public boolean isButtonsEnable() {
    return super.isButtonsEnable(SUBMIT_BUTTON, CANCEL_BUTTON);
  }
}
예제 #4
0
  @Test
  public void shouldShowCorrectAnswerPopupWhenAnswerIsCorrect() {
    driver.get(URL);
    String title = driver.getTitle();
    assertEquals("Rule Financial Registration Form", title);

    this.fillRegistrationFields();
    driver.findElement(By.xpath("//*[@class='gwt-Button' and text()='Java']")).click();
    if (this.chooseTypeOfAnswerForQuestion(true)) {
      driver.findElement(By.xpath("//*[@id='gwt-uid-26']")).click(); // checkBox on the site
      // Save button             | //*[text()='Save']
      driver
          .findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/table/tbody/tr/td[1]/button"))
          .click();

      String alertText =
          driver
              .findElement(By.xpath("html/body/div[5]/div/div/table/tbody/tr[1]/td/div"))
              .getText();
      // close an alert
      driver.findElement(By.xpath("//button[text()='Close']")).click();
      assertEquals("Congratulations! You've won:", alertText);
    } else {
      System.out.println("Błąd z zaznaczeniem check box, lub przyciskiem Save");
    }
  }
  /**
   * 取得新闻标题、时间和评论数的集合
   *
   * @param urls 所有新闻URL集合
   * @return 新闻标题、时间和评论数的集合
   */
  public static List<String> getTimeAndJoin(List<String> urls) {
    List<String> listTimeAndJoin = new ArrayList<String>();

    int num = 1;
    // System.setProperty("webdriver.ie.driver", "." + File.separator + "Driver" + File.separator +
    // "IEDriverServer.exe");
    // WebDriver driver = new InternetExplorerDriver();
    WebDriver driver = new FirefoxDriver();
    for (int i = 0; i < urls.size(); i++) {
      // System.setProperty("webdriver.ie.driver", "." + File.separator + "Driver" + File.separator
      // + "IEDriverServer.exe");
      // WebDriver driver = new InternetExplorerDriver();
      driver.get(urls.get(i));
      List<WebElement> headline =
          driver.findElements(By.cssSelector("div[class='atitle tCenter']"));
      List<WebElement> timeAndJoin = driver.findElements(By.cssSelector("div[class='about']"));

      StringBuffer sb = null;
      sb = new StringBuffer();

      if ((timeAndJoin.size() == 1) && (headline.size() == 1)) {
        sb.append("[新闻 " + num + "]");
        sb.append(headline.get(0).getText() + "\t");
        String[] temp = timeAndJoin.get(0).getText().split("\n");
        sb.append(temp[0] + "\t" + temp[1] + "\t" + temp[2]);
        // sb.append(timeAndJoin.get(0).getText().replaceAll("\\s+", ""));
        listTimeAndJoin.add(sb.toString());
        num++;
      }
      // driver.close();
    }
    driver.close();
    return listTimeAndJoin;
  }
 public WebElement getModerateResponseButtonInQuestionView(int qnNo, int responseNo) {
   return browser
       .driver
       .findElement(By.id("questionBody-" + (qnNo - 1)))
       .findElement(By.className("table-responsive"))
       .findElement(By.xpath("table/tbody/tr[" + responseNo + "]/td[6]/form"));
 }
예제 #7
0
  public MetricsAreaFragment getMetricsArea(String title) {
    ////// add property
    By selector =
        By.xpath(
            ".//table[contains(@class, '"
                + PropUtils.get("metrics.container.class")
                + "')][.//h3[text()='"
                + title
                + "']]");
    WebElement element = null;
    try {
      element = getContentRoot().findElement(selector);
    } catch (NoSuchElementException exc) {
      return null;
    }
    MetricsAreaFragment area = Graphene.createPageFragment(MetricsAreaFragment.class, element);

    Map<String, String> metricGrid =
        element
            .findElement(By.className(PropUtils.get("metrics.grid.class")))
            .findElements(By.tagName("tr"))
            .stream()
            .collect(
                Collectors.toMap(
                    e ->
                        e.findElement(By.className(PropUtils.get("metrics.grid.nominal.class")))
                            .getText(),
                    e ->
                        e.findElement(By.className(PropUtils.get("metrics.grid.numerical.class")))
                            .getText()));

    area.setMetricGrid(metricGrid);

    return area;
  }
예제 #8
0
 public boolean exibiuTituloPublicidade() {
   return !getDriver()
       .findElement(By.className("publicidade-container"))
       .findElement(By.tagName("p"))
       .getText()
       .isEmpty();
 }
예제 #9
0
파일: Find.java 프로젝트: AlexWengh/HMM
 @Override
 public ExecuteContext execute(ExecuteContext context) throws Exception {
   WebDriver driver = context.getDriver();
   By by = null;
   switch (method) {
     case ID:
       by = By.id(value);
       break;
     case NAME:
       by = By.name(value);
       break;
     case XPATH:
       by = By.xpath(value);
       break;
     case TAGNAME:
       by = By.tagName(value);
       break;
     case LINKTEXT:
       by = By.linkText(value);
       break;
     default:
       break;
   }
   WebElement element = driver.findElement(by);
   context.setWebElement(element);
   return context;
 }
예제 #10
0
 public boolean exibiuTituloDePrevisoes() {
   return !getDriver()
       .findElement(By.className("info"))
       .findElement(By.className("resume"))
       .getText()
       .isEmpty();
 }
예제 #11
0
 public boolean exibiuData() {
   return !getDriver()
       .findElement(By.className("info"))
       .findElement(By.className("dateTime"))
       .getText()
       .isEmpty();
 }
 /**
  * Test all SCOes
  *
  * @param mode
  * @param course
  * @param scoLeft
  */
 public void testSCO(char mode, int course, int scoLeft) {
   wait.until(presenceOfElementLocated(By.id("n")));
   String url = driver.getCurrentUrl();
   if (mode == 'b') {
     driver.findElement(By.id("b")).click();
   } else {
     driver.findElement(By.id("n")).click();
   }
   driver.findElement(By.xpath("//input[@value='Enter']")).click();
   wait.until(presenceOfElementLocated(By.id("ygtvcontentel2")));
   wait.until(presenceOfElementLocated(By.id("scorm_object")));
   System.out.println("SCO Loaded. Testing ...");
   driver.switchTo().frame("scorm_object");
   if ((course == 1 && currentSCO != 4) || (course == 2 && currentSCO != 2)) {
     wait.until(
         presenceOfElementLocated(
             By.xpath("//*[contains(.,'Status:  This SCO Test Completed.')]")));
   } else if ((course == 1 && currentSCO == 4) || (course == 2 && currentSCO == 2)) {
     // for both course 1 and course 2
     if (scoLeft != 0) {
       wait.until(
           presenceOfElementLocated(
               By.xpath("//*[contains(.,'Please Log out and re-login to the LMS.')]")));
       return;
     } else {
       wait.until(
           presenceOfElementLocated(
               By.xpath("//*[contains(.,'Status:  This SCO Test Completed.')]")));
     }
   }
   System.out.println(driver.findElement(By.id("teststatus")).getText());
   currentSCO++;
   driver.get(url);
 }
예제 #13
0
  // W-1625895: Safari WebDriver bug- cannot right click because interactions API not implemented
  @ExcludeBrowsers({
    BrowserType.IPAD,
    BrowserType.IPHONE,
    BrowserType.SAFARI,
    BrowserType.ANDROID_PHONE,
    BrowserType.ANDROID_TABLET
  })
  public void testBaseMouseClickEventValue() throws Exception {
    open(TEST_CMP);
    WebElement input = findDomElement(By.cssSelector(".keyup2"));
    WebElement outputValue = findDomElement(By.cssSelector(".outputValue"));

    // IE < 9 uses values 1, 2, 4 for left, right, middle click (respectively)
    String expectedVal =
        (BrowserType.IE7.equals(getBrowserType()) || BrowserType.IE8.equals(getBrowserType()))
            ? "1"
            : "0";
    input.click();
    assertEquals("Left click not performed ", expectedVal, outputValue.getText());

    // right click behavior
    Actions actions = new Actions(getDriver());
    actions.contextClick(input).perform();
    assertEquals("Right click not performed ", "2", outputValue.getText());
  }
예제 #14
0
 @Override
 protected void isLoaded() throws Error {
   waitForSomething(
       ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(disabledExplanationCss)));
   waitForSomething(ExpectedConditions.invisibilityOfElementLocated(By.id(sessionCheckMessageId)));
   waitForSomething(ExpectedConditions.elementToBeClickable(signInButton));
 }
  public void hoverClickAndViewStudentPhotoOnHeading(int panelHeadingIndex, String urlRegex)
      throws Exception {
    JavascriptExecutor jsExecutor = (JavascriptExecutor) browser.driver;
    String idOfPanelHeading = "panelHeading-" + panelHeadingIndex;
    WebElement photoDiv =
        browser
            .driver
            .findElement(By.id(idOfPanelHeading))
            .findElement(By.className("profile-pic-icon-hover"));
    jsExecutor.executeScript("arguments[0].scrollIntoView(true);", photoDiv);
    Actions actions = new Actions(browser.driver);
    actions.moveToElement(photoDiv).perform();
    waitForElementPresence(By.cssSelector(".popover-content"));

    jsExecutor.executeScript(
        "document.getElementsByClassName('popover-content')[0]"
            + ".getElementsByTagName('a')[0].click();");

    waitForElementPresence(By.cssSelector(".popover-content > img"));

    AssertHelper.assertContainsRegex(
        urlRegex,
        browser
            .driver
            .findElements(By.cssSelector(".popover-content > img"))
            .get(0)
            .getAttribute("src"));

    jsExecutor.executeScript(
        "document.getElementsByClassName('popover')[0].parentNode.removeChild(document.getElementsByClassName('popover')[0])");
  }
예제 #16
0
 public void login(Admin admin) {
   // driver.get(baseUrl + "/mantisbt-1.2.19/login_page.php");
   openUrl("/");
   type(By.name("username"), admin.login);
   type(By.name("password"), admin.password);
   click(By.cssSelector("input.button"));
 }
  public void hoverAndViewStudentPhotoOnBody(int panelBodyIndex, String urlRegex) throws Exception {
    String idOfPanelBody = "panelBodyCollapse-" + panelBodyIndex;
    WebElement photoLink =
        browser
            .driver
            .findElements(By.cssSelector('#' + idOfPanelBody + "> .panel-body > .row"))
            .get(0)
            .findElements(By.className("profile-pic-icon-hover"))
            .get(0);
    Actions actions = new Actions(browser.driver);
    actions.moveToElement(photoLink).perform();

    waitForElementPresence(By.cssSelector(".popover-content > img"));
    ThreadHelper.waitFor(500);

    AssertHelper.assertContainsRegex(
        urlRegex,
        browser
            .driver
            .findElements(By.cssSelector(".popover-content > img"))
            .get(0)
            .getAttribute("src"));

    JavascriptExecutor jsExecutor = (JavascriptExecutor) browser.driver;
    jsExecutor.executeScript(
        "document.getElementsByClassName('popover')[0].parentNode.removeChild(document.getElementsByClassName('popover')[0])");
  }
 protected String findNewUserRowIndexLocation() {
   WebElement we = driver.findElement(By.xpath(USER_TABLE_BODY_XPATH_LOCATION));
   if (!StringUtils.equals(we.getTagName(), "tbody")) {
     throw new RuntimeException();
   }
   return String.valueOf(we.findElements(By.tagName("tr")).size());
 }
예제 #19
0
public class ReportPage extends AbstractBasePage {

  public static final String URL_PATH = "/home#/mds/dataBrowser";

  static final By MEMISSEDCLINICVISITSREPORT = By.linkText("M&E Missed Clinic Visits Report");

  static final By DAILYCLINICVISITSCHEDULEREPORT =
      By.linkText("Daily Clinic Visit Schedule Report");

  public ReportPage(WebDriver driver) {
    super(driver);
  }

  public void showMEMissedClinicVisitsReport() throws InterruptedException {
    clickWhenVisible(MEMISSEDCLINICVISITSREPORT);
  }

  public void showDailyClinicVisitReportSchedule() throws InterruptedException {
    clickWhenVisible(DAILYCLINICVISITSCHEDULEREPORT);
  }

  @Override
  public String expectedUrlPath() {
    return URL_ROOT + URL_PATH;
  }
}
  private void initParams() {
    WebElement dateSlot = getDriver().findElement(By.className("v-datecellslot"));
    int dateSlotWidth = dateSlot.getSize().getWidth();
    noOverlapWidth = dateSlotWidth;
    oneOverlapWidth = dateSlotWidth / 2;
    twoOverlapsWidth = dateSlotWidth / 3;

    Comparator<WebElement> startTimeComparator =
        new Comparator<WebElement>() {
          @Override
          public int compare(WebElement e1, WebElement e2) {
            int e1Top = e1.getLocation().getY();
            int e2Top = e2.getLocation().getY();
            return e1Top - e2Top;
          }
        };

    List<WebElement> eventElements =
        getDriver().findElements(By.className("v-calendar-event-content"));
    Collections.sort(eventElements, startTimeComparator);
    firstEvent = eventElements.get(0);
    secondEvent = eventElements.get(1);
    thirdEvent = eventElements.get(2);

    List<WebElement> resizeBottomElements =
        getDriver().findElements(By.className("v-calendar-event-resizebottom"));
    Collections.sort(resizeBottomElements, startTimeComparator);
    firstEventBottomResize = resizeBottomElements.get(0);
    secondEventBottomResize = resizeBottomElements.get(1);
    thirdEventBottomResize = resizeBottomElements.get(2);
  }
예제 #21
0
  @Test
  public void shouldShowWrongAnswerPopupWhenAsnwerIsIncorrect() {
    driver.get(URL);
    String title = driver.getTitle();
    assertEquals("Rule Financial Registration Form", title);
    /*
     * Your code needs to be here, sample below should help you a bit
     * driver.findElement(By.name("firstName")).clear();
     * driver.findElement(By.name("firstName")).sendKeys("Marek");
     */
    this.fillRegistrationFields();
    driver.findElement(By.xpath("//*[@class='gwt-Button' and text()='Java']")).click();
    if (this.chooseTypeOfAnswerForQuestion(false)) {
      driver.findElement(By.xpath("//*[@id='gwt-uid-26']")).click(); // checkBox on the site
      // Save button             | //*[text()='Save']
      driver
          .findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/table/tbody/tr/td[1]/button"))
          .click();

      String alertText =
          driver
              .findElement(By.xpath("html/body/div[5]/div/div/table/tbody/tr[1]/td/div"))
              .getText();
      // close an alert
      driver.findElement(By.xpath("//button[text()='Close']")).click();
      assertEquals("We're sorry but your answer was incorrect.", alertText);
    } else {
      System.out.println("Błąd z zaznaczeniem check box, lub przyciskiem Save");
    }
  }
 public ProviderPage(WebDriver driver) {
   super(driver);
   MANAGE = By.linkText("Manage Providers");
   ADD = By.linkText("Add Provider");
   RETIRE = By.name("retireProviderButton");
   SAVE = By.name("saveProviderButton");
 }
예제 #23
0
 private void SpecialNeeds() throws IOException {
   // Click Special Needs
   driver
       .findElement(
           By.xpath(
               "//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Special Needs\")]"))
       .click();
   // Select Special Needs
   Select SpecialNeeds = new Select(driver.findElement(By.id("edit-special-needs")));
   // Select Learning Center
   SpecialNeeds.selectByVisibleText("Learning Center");
   // Select Early Syllabus
   SpecialNeeds.selectByVisibleText("Early syllabus");
   // Click Apply
   driver.findElement(By.id("edit-special-needs-apply-filter")).click();
   // Check Result Received or Not
   try {
     assertTrue(
         func.isTextPresent(driver.findElement(By.className("search-total-results")).getText()));
   } catch (Error e) {
     verificationErrors.append(e.toString());
   }
   // Click All Selections
   driver.findElement(By.linkText("Clear All Selections")).click();
 }
public class ProviderPage extends AdminManagementPage {

  static final By IDENTIFIER = By.name("identifier");
  static final By PERSON = By.id("providerName");
  static final By SEARCH_ELEMENT = By.id("inputNode");
  static final By ERROR = By.cssSelector("span.error");

  public ProviderPage(WebDriver driver) {
    super(driver);
    MANAGE = By.linkText("Manage Providers");
    ADD = By.linkText("Add Provider");
    RETIRE = By.name("retireProviderButton");
    SAVE = By.name("saveProviderButton");
  }

  public void fillInIdentifier(String text) {
    fillInField(findElement(IDENTIFIER), text);
  }

  public void fillInPerson(String text) {
    fillInField(findElement(PERSON), text);
  }

  public void waitForError() {
    waitForElement(ERROR);
  }

  @Override
  public String getPageUrl() {
    return "/admin/provider/index.htm";
  }
}
  /**
   * Find a row in a table where columns exist that contain the specified text. Not all columns of
   * the table need to specified, however the order is important. Finding multiple matching results
   * will result in an error.
   *
   * <p>Once the row has been located, other FindInRow methods can be used that may in turn refer to
   * and set the 'Current Element', this method does not set the current element for that reason.
   *
   * @example FindTableRowWithColumnsThatContainText ["My Name","Where it all began...","December 19
   *     2012"]
   * @section Table
   * @param columnText A comma delimitted list of column values, each column can be double quoted
   */
  @Step("FindTableRowWithColumnsThatContainText \\[(.*)\\]")
  public void findRowInTableWithText(final String columnText) {

    final WebElement currentElement = webDriverContext().getCurrentElement();

    Assert.assertThat(
        "expecting the current element to be a table",
        currentElement.getTagName(),
        equalToIgnoringCase("table"));

    final String[] columnValues = columnText.split(",");
    final List<String> columnValList = new ArrayList<String>();
    for (final String s : columnValues) {
      columnValList.add(s.replaceAll("\"", "").trim());
    }

    final List<WebElement> tableRows = currentElement.findElements(By.tagName("tr"));

    List<WebElement> matchingRows = null;

    // TODO - refactor this into WebDriver Bys ..?

    // go through all rows
    for (final WebElement row : tableRows) {

      // for each row
      final List<WebElement> tableCells = row.findElements(By.tagName("td"));

      int lookingForIdx = 0;

      boolean found = false;
      // do we have a match ?
      for (final WebElement td : tableCells) {

        if (td.getText().contains(columnValList.get(lookingForIdx))) {

          lookingForIdx++;
          if (lookingForIdx >= columnValList.size()) {
            // found em all
            found = true;
            break;
          }
        }
      }

      if (found) {
        if (matchingRows == null) {
          matchingRows = new ArrayList<WebElement>();
        }
        matchingRows.add(row);
      }
    }

    Assert.assertNotNull("Didn't find any rows with values: [" + columnText + "]", matchingRows);

    Assert.assertThat(
        "Found too many rows that match values: [" + columnText + "]", matchingRows.size(), is(1));

    webDriverContext().stashElement(TABLE_ROW_KEY, matchingRows.get(0));
  }
 public void verifyCommentRowContent(
     String commentRowIdSuffix, String commentText, String giverName) {
   WebDriverWait wait = new WebDriverWait(browser.driver, 30);
   WebElement commentRow;
   try {
     commentRow =
         wait.until(
             ExpectedConditions.presenceOfElementLocated(
                 By.id("responseCommentRow" + commentRowIdSuffix)));
   } catch (TimeoutException e) {
     fail("Timeout!");
     commentRow = null;
   }
   try {
     wait.until(
         ExpectedConditions.textToBePresentInElement(
             commentRow.findElement(By.id("plainCommentText" + commentRowIdSuffix)), commentText));
   } catch (TimeoutException e) {
     fail("Not expected message");
   }
   try {
     assertTrue(commentRow.findElement(By.className("text-muted")).getText().contains(giverName));
   } catch (AssertionError e) {
     assertTrue(commentRow.findElement(By.className("text-muted")).getText().contains("you"));
   }
 }
예제 #27
0
  public void exit() {

    clickByCssSelector("span.name");
    clickByCssSelector("i.fa.fa-power-off");
    waitForElementPresent(By.id("user-email"), 60000);
    assertElementPresent(By.xpath("//div[2]/div/div/div/div[2]"));
  }
  public void clickViewPhotoLink(int panelBodyIndex, String urlRegex) throws Exception {
    String idOfPanelBody = "panelBodyCollapse-" + panelBodyIndex;
    WebElement photoCell =
        browser
            .driver
            .findElement(By.id(idOfPanelBody))
            .findElements(By.cssSelector(".profile-pic-icon-click"))
            .get(0);
    JavascriptExecutor jsExecutor = (JavascriptExecutor) browser.driver;
    jsExecutor.executeScript(
        "document.getElementById('"
            + idOfPanelBody
            + "')"
            + ".getElementsByClassName('profile-pic-icon-click')[0]"
            + ".getElementsByTagName('a')[0].click();");
    Actions actions = new Actions(browser.driver);

    actions.moveToElement(photoCell).perform();
    waitForElementPresence(By.cssSelector(".popover-content > img"));

    List<WebElement> photos = browser.driver.findElements(By.cssSelector(".popover-content > img"));
    AssertHelper.assertContainsRegex(urlRegex, photos.get(photos.size() - 1).getAttribute("src"));

    actions.moveByOffset(100, 100).click().perform();
  }
예제 #29
0
파일: Village.java 프로젝트: ttkyle/TWFB
  // Sends the number of catapults to the GUI
  public static void setCatapult() {

    // loop through all the show unit lines
    // if the unit name is found then display it on the GUI
    for (int i = 1; i < 15; i++) {
      try {
        String catapultLabel =
            WebAutomation.driver
                .findElement(By.xpath("//*[@id=\"show_units\"]/div/table/tbody/tr[" + i + "]"))
                .getText();
        if (substring(catapultLabel, 2, 10).equals("Catapult")
            || substring(catapultLabel, 3, 11).equals("Catapult")
            || substring(catapultLabel, 4, 12).equals("Catapult")
            || substring(catapultLabel, 5, 13).equals("Catapult")
            || substring(catapultLabel, 6, 14).equals("Catapult")
            || substring(catapultLabel, 7, 15).equals("Catapult")) {
          TroopsDetailPanel.setCatapultLabel(
              WebAutomation.driver
                  .findElement(
                      By.xpath("//*[@id='show_units']/div/table/tbody/tr[" + i + "]/td/strong"))
                  .getText());
          break;
        }
        // the troop was not found
        else {
          TroopsDetailPanel.setCatapultLabel("0");
        }
      } catch (NoSuchElementException e) {
      }
    }
  }
 public int quantidadeMinimaColunistas() {
   return getDriver()
       .findElement(By.className("gente-do-globo"))
       .findElement(By.tagName("ul"))
       .findElements(By.tagName("li"))
       .size();
 }