/**
   * Regression test for
   * https://sf.net/tracker/index.php?func=detail&aid=1527799&group_id=47038&atid=448266.
   *
   * @throws Exception if test fails
   */
  @Test
  public void followingAxis() throws Exception {
    final String content =
        "<html><title>XPath tests</title><body>\n"
            + "<table id='table1'>\n"
            + "<tr id='tr1'>\n"
            + "<td id='td11'>a3</td>\n"
            + "<td id='td12'>c</td>\n"
            + "</tr>\n"
            + "<tr id='tr2'>\n"
            + "<td id='td21'>a4</td>\n"
            + "<td id='td22'>c</td>\n"
            + "</tr>\n"
            + "</table>\n"
            + "</body></html>";

    final HtmlPage page = loadPage(content);
    final HtmlElement td12 = page.getHtmlElementById("td12");
    final HtmlElement tr2 = page.getHtmlElementById("tr2");
    final HtmlElement td21 = page.getHtmlElementById("td21");
    final HtmlElement td22 = page.getHtmlElementById("td22");
    xpath(page, "//*[contains(.,'a4')]/following::td[.='c']", new Object[] {td22});

    xpath(page, "//body/following::*", new Object[] {});
    xpath(page, "//html/following::*", new Object[] {});
    xpath(page, "//table/following::*", new Object[] {});
    xpath(page, "//td[@id='td11']/following::*", new Object[] {td12, tr2, td21, td22});
  }
Exemplo n.º 2
0
  private void testFF_StopPropagation(final String cancelMethod) throws Exception {
    final String content =
        "<html><head><title>foo</title>\n"
            + "<script>\n"
            + "var counter = 0;\n"
            + "function t(_s) {\n"
            + "  return function(e) { alert(_s); counter++; if (counter >= 4) e."
            + cancelMethod
            + "; };\n"
            + "}\n"
            + "function init() {\n"
            + "  window.addEventListener('click', t('window capturing'), true);\n"
            + "  var oDiv = document.getElementById('theDiv');\n"
            + "  oDiv.addEventListener('click', t('div capturing'), true);\n"
            + "  var oSpan = document.getElementById('theSpan');\n"
            + "  oSpan.addEventListener('click', t('span capturing'), true);\n"
            + "}\n"
            + "</script>\n"
            + "</head><body onload='init()'>\n"
            + "<div onclick=\"alert('div')\" id='theDiv'>\n"
            + "<span id='theSpan'>blabla</span>\n"
            + "</div>\n"
            + "</body></html>";

    final List<String> collectedAlerts = new ArrayList<String>();
    final HtmlPage page = loadPage(getBrowserVersion(), content, collectedAlerts);
    page.getHtmlElementById("theSpan").click();
    final String[] expectedAlerts1 = {"window capturing", "div capturing", "span capturing", "div"};
    assertEquals(expectedAlerts1, collectedAlerts);
    collectedAlerts.clear();

    page.getHtmlElementById("theSpan").click();
    final String[] expectedAlerts2 = {"window capturing"};
    assertEquals(expectedAlerts2, collectedAlerts);
  }
Exemplo n.º 3
0
  @Override
  public String[] getRowCSV(HtmlPage page) {
    String title = page.getTitleText();

    String video = null;
    List<HtmlElement> anchorsBgcover =
        page.getHtmlElementById("bgcover").getHtmlElementsByTagName("a");

    if (!anchorsBgcover.isEmpty()) {
      video = anchorsBgcover.get(0).getAttribute("href");
    }

    String rating = null;
    List<HtmlElement> spansBgcover =
        page.getHtmlElementById("bgcover").getHtmlElementsByTagName("span");
    if (!spansBgcover.isEmpty()) {
      rating = spansBgcover.get(0).asText();
      if (rating.equals("MYMO NET RO?")) {
        rating = null;
      }
    }

    String[] idArray = page.getUrl().toString().split("/");
    String id = idArray[idArray.length - 1];

    String[] elementRow = {id, title, video, rating};

    System.out.println(title);

    return elementRow;
  }
Exemplo n.º 4
0
 @Test
 public void testRowRemoved() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/repeatRemoved.xhtml");
   assertNotNull(page.getHtmlElementById("f:r:0:i"));
   HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("f:r:0:b");
   page = button.click();
   assertNull(page.getElementById("f:r:0:i"));
 }
Exemplo n.º 5
0
 @Test
 public void testIssue1825() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/issue1825.xhtml");
   HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("form:button");
   page = button.click();
   assertEquals(200, page.getWebResponse().getStatusCode());
   button = (HtmlSubmitInput) page.getHtmlElementById("form:button");
   page = button.click();
   assertEquals(200, page.getWebResponse().getStatusCode());
 }
Exemplo n.º 6
0
  /** @throws Exception if an error occurs */
  @Test
  public void preventDefault() throws Exception {
    final String html =
        "<html><head><title>First</title>\n"
            + "<script>\n"
            + "function block(e) {\n"
            + "  if (e && e.preventDefault)\n"
            + "    e.preventDefault();\n"
            + "  else\n"
            + "    return false;\n"
            + "}\n"
            + "\n"
            + "function test() {\n"
            + "  document.getElementById('myForm').onsubmit = block;\n"
            + "}\n"
            + "</script>\n"
            + "</head><body onload='test()'>\n"
            + "<form id='myForm' action='doesnt_exist.html'>\n"
            + "  <input type='submit' id='mySubmit' value='Continue'></p>\n"
            + "</form>"
            + "</body></html>";

    final HtmlPage page = loadPageWithAlerts(html);
    final HtmlPage page2 = page.getHtmlElementById("mySubmit").click();
    assertEquals(getDefaultUrl(), page2.getWebResponse().getWebRequest().getUrl());
  }
Exemplo n.º 7
0
  /**
   * Tests that event fires on key press.
   *
   * @throws Exception if the test fails
   */
  @Test
  public void testEventOnKeyDown() throws Exception {
    final String html =
        "<html><head></head><body>\n"
            + "<button type='button' id='clickId'>Click Me</button>\n"
            + "<script>\n"
            + "function handler(_e) {\n"
            + "  var e = _e ? _e : window.event;\n"
            + "  if (e.keyCode == 65)\n"
            + "    alert('pass');\n"
            + "  else\n"
            + "    alert('fail:' + e.keyCode);\n"
            + "}\n"
            + "document.getElementById('clickId').onkeydown = handler;\n"
            + "document.getElementById('clickId').onclick = handler;</script>\n"
            + "</body></html>";

    final List<String> collectedAlerts = new ArrayList<String>();
    final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts);
    final HtmlElement element = page.getHtmlElementById("clickId");
    element.type('A');
    element.type('B');
    element.click();
    final String[] expectedAlerts = {"pass", "fail:66", "fail:undefined"};
    assertEquals(expectedAlerts, collectedAlerts);
  }
Exemplo n.º 8
0
  private void testEventOnClick_Shift_Ctrl_Alt(
      final boolean shiftKey,
      final boolean ctrlKey,
      final boolean altKey,
      final String[] expectedAlerts)
      throws Exception {
    final String htmlContent =
        "<html><head><title>foo</title></head><body>\n"
            + "<form id='form1'>\n"
            + "    <button name='button' type='button' id='button'>Push me</button>\n"
            + "</form>\n"
            + "<script>\n"
            + "function handler(_e) {\n"
            + "  var e = _e ? _e : window.event;\n"
            + "  alert(e.shiftKey + ',' + e.ctrlKey + ',' + e.altKey);\n"
            + "}\n"
            + "document.getElementById('button').onclick = handler;\n"
            + "</script>\n"
            + "</body></html>";
    final List<String> collectedAlerts = new ArrayList<String>();
    final HtmlPage page = loadPage(getBrowserVersion(), htmlContent, collectedAlerts);
    final HtmlButton button = page.getHtmlElementById("button");

    final HtmlPage secondPage = button.click(shiftKey, ctrlKey, altKey);

    assertEquals(expectedAlerts, collectedAlerts);

    assertSame(page, secondPage);
  }
Exemplo n.º 9
0
  /**
   * Test for event bubbling in IE.
   *
   * @throws Exception if the test fails
   */
  @Test
  @Browsers(Browser.IE)
  @NotYetImplemented // TODO: in IE no click event can be registered for the window
  @Alerts({"span bubbling", "div", "div bubbling"})
  public void testIE_EventBubbling() throws Exception {
    final String content =
        "<html><head><title>foo</title>\n"
            + "<script>\n"
            + "function t(_s) {\n"
            + "     return function() { alert(_s) };\n"
            + "}\n"
            + "function init() {\n"
            + "  window.attachEvent('onclick', t('window bubbling'));\n"
            + "  var oDiv = document.getElementById('theDiv');\n"
            + "  oDiv.attachEvent('onclick', t('div bubbling'));\n"
            + "  var oSpan = document.getElementById('theSpan');\n"
            + "  oSpan.attachEvent('onclick', t('span bubbling'));\n"
            + "}\n"
            + "</script>\n"
            + "</head><body onload='init()'>\n"
            + "<div onclick=\"alert('div')\" id='theDiv'>\n"
            + "<span id='theSpan'>blabla</span>\n"
            + "</div>\n"
            + "</body></html>";

    final List<String> collectedAlerts = new ArrayList<String>();
    final HtmlPage page = loadPage(getBrowserVersion(), content, collectedAlerts);
    page.getHtmlElementById("theSpan").click();

    assertEquals(getExpectedAlerts(), collectedAlerts);
  }
  @Test(groups = {"notLoggedIn"})
  public void testUserFilterWithAjaxDeny() throws Exception {
    clickOnBasePage("tynamoLoginLink");
    loginAction();
    clickOnBasePage("contributed");
    // now go log out in a different "window"
    HtmlPage indexPage = webClient.getPage(BASEURI);
    indexPage.getHtmlElementById("tynamoLogoutLink").click();

    // Clicking on this link should make an ajax request, but HTMLUnit doesn't like it and sends a
    // non-ajax request
    HtmlElement ajaxLink = (HtmlElement) page.getElementById("ajaxLink");
    URL ajaxUrl = new URL(APP_HOST_PORT + ajaxLink.getAttribute("href"));
    WebRequest ajaxRequest = new WebRequest(ajaxUrl);
    ajaxRequest.setAdditionalHeader("X-Requested-With", "XMLHttpRequest");

    Page jsonLoginResponse = webClient.getPage(ajaxRequest);
    String ajaxLoginResp = jsonLoginResponse.getWebResponse().getContentAsString();
    JSONObject jsonResp = new JSONObject(ajaxLoginResp);
    String ajaxRedirectUrl = jsonResp.getJSONObject("_tapestry").getString("redirectURL");
    assertTrue(
        ajaxRedirectUrl.startsWith(APP_CONTEXT + "security/login"),
        "The ajax redirect response '"
            + ajaxRedirectUrl
            + "' did not start with '"
            + APP_CONTEXT
            + "security/login'");
    page = webClient.getPage(APP_HOST_PORT + ajaxRedirectUrl);
    assertLoginPage();
  }
  /**
   * Reads the tests results from the browser output and creates the modules and tests objects from
   * it.
   *
   * @param page Page which contains the tests results. It cannot be null.
   */
  private void readTests(final HtmlPage page) {
    Validate.notNull(page, "The page cannot be null.");

    HtmlElement element = page.getHtmlElementById("qunit-tests");

    List<HtmlElement> testResults = element.getElementsByTagName("li");

    TestSuite currentModule = null;

    for (HtmlElement result : testResults) {
      Matcher matcher = summary.matcher(result.asText());

      List<HtmlElement> testOutput = result.getElementsByTagName("li");

      if (matcher.lookingAt()) {
        TestSuite module = getModule(matcher);
        TestCase test = buildTest(matcher);

        if (currentModule != module) {
          if (currentModule != null) {
            currentModule.done();
          }

          currentModule = module;
        }

        for (HtmlElement outputLine : testOutput) {
          test.print(outputLine.getFirstChild().asXml());
        }

        module.addTest(test);
      }
    }
  }
Exemplo n.º 12
0
  /** @throws Exception if an error occurs */
  @Test
  @Browsers(Browser.FF)
  @Alerts({"capturing", "at target", "bubbling"})
  public void testEventPhase() throws Exception {
    final String html =
        "<html><head><script>\n"
            + "  function init() {\n"
            + "    var form = document.forms[0];\n"
            + "    form.addEventListener('click', alertPhase, true);\n"
            + "    form.addEventListener('click', alertPhase, false);\n"
            + "  }\n"
            + "  function alertPhase(e) {\n"
            + "    switch (e.eventPhase) {\n"
            + "      case 1: alert('capturing'); break;\n"
            + "      case 2: alert('at target'); break;\n"
            + "      case 3: alert('bubbling'); break;\n"
            + "      default: alert('unknown');\n"
            + "    }\n"
            + "  }\n"
            + "</script></head>\n"
            + "<body onload='init()'>\n"
            + "<form><input type='button' onclick='alertPhase(event)' id='b'></form>\n"
            + "</body></html>";

    final List<String> actual = new ArrayList<String>();
    final HtmlPage page = loadPage(getBrowserVersion(), html, actual);
    final HtmlButtonInput button = page.getHtmlElementById("b");
    button.click();
    assertEquals(getExpectedAlerts(), actual);
  }
Exemplo n.º 13
0
  /** @throws Exception if the test fails */
  @Test
  public void testEventOnBlur() throws Exception {
    final String content =
        "<html><head></head><body>\n"
            + "<form action='foo'>\n"
            + "<input name='textField' id='textField' onblur='alert(event != null)'>\n"
            + "<input type='submit' id='otherField'>\n"
            + "</form>\n"
            + "</body></html>";

    final List<String> collectedAlerts = new ArrayList<String>();
    final HtmlPage page = loadPage(getBrowserVersion(), content, collectedAlerts);
    page.getHtmlElementById("textField").focus();
    page.getHtmlElementById("otherField").focus();
    final String[] expectedAlerts = {"true"};
    assertEquals(expectedAlerts, collectedAlerts);
  }
Exemplo n.º 14
0
 private static List<String> getSimulatedProperties(final BrowserVersion browserVersion)
     throws Exception {
   final URL url = PropertiesTest.class.getClassLoader().getResource("objects/properties.html");
   final WebClient webClient = new WebClient(browserVersion);
   final HtmlPage page = webClient.getPage(url);
   final HtmlTextArea textarea = page.getHtmlElementById("myTextarea");
   return Arrays.asList(textarea.getText().split("\r\n|\n"));
 }
Exemplo n.º 15
0
 @Test
 public void testOutput() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/output.xhtml");
   HtmlElement elem = page.getHtmlElementById("output1");
   String xml = elem.asXml();
   assertTrue(xml.contains("<output"));
   assertTrue(xml.contains("id=\"" + "output1" + "\""));
 }
Exemplo n.º 16
0
 @Test
 public void testKeygen() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/keygen.xhtml");
   HtmlElement elem = page.getHtmlElementById("keygen1");
   String xml = elem.asXml();
   assertTrue(xml.contains("<keygen"));
   assertTrue(xml.contains("id=\"" + "keygen1" + "\""));
 }
  /**
   * Test component rendering
   *
   * @throws Exception
   */
  public void testRender() throws Exception {
    HtmlPage page = renderView();
    assertNotNull(page);
    // System.out.println(page.asXml());

    HtmlElement div1 = page.getHtmlElementById(stp1.getClientId(facesContext));
    assertNotNull(div1);
    assertEquals("div", div1.getNodeName());
    assertTrue(div1.getAttributeValue("class").contains("rich-stglpanel"));
    assertEquals("", div1.getAttributeValue("style"));

    HtmlDivision div2 =
        (HtmlDivision) page.getHtmlElementById(stp1.getClientId(facesContext) + "_header");
    assertNotNull(div2);
    assertEquals("div", div2.getNodeName());

    String classAttr2 = div2.getAttributeValue("class");
    assertTrue(classAttr2.contains("rich-stglpanel-header"));

    HtmlElement div3 = page.getHtmlElementById(stp1.getClientId(facesContext) + "_switch_on");
    assertNotNull(div3);
    assertEquals("div", div3.getNodeName());

    HtmlElement div5 = page.getHtmlElementById(stp1.getClientId(facesContext) + "_switch_off");
    assertNotNull(div5);
    assertEquals("div", div5.getNodeName());

    HtmlElement div4 = page.getHtmlElementById(stp1.getClientId(facesContext) + "_body");
    assertNotNull(div4);
    assertEquals("div", div4.getNodeName());
    assertEquals("", div4.getAttributeValue("style"));

    try {
      page.getHtmlElementById(openMarker1.getClientId(facesContext));
      assertTrue(false);
    } catch (Throwable t) {
    }

    HtmlElement f1 = page.getHtmlElementById(closeMarker1.getClientId(facesContext));
    assertNotNull(f1);

    HtmlElement f2 = page.getHtmlElementById(openMarker2.getClientId(facesContext));
    assertNotNull(f2);

    try {
      page.getHtmlElementById(closeMarker2.getClientId(facesContext));
      assertTrue(false);
    } catch (Throwable t) {
    }
  }
Exemplo n.º 18
0
  /**
   * geOutput
   *
   * @param pageName
   * @return String
   * @throws Exception
   */
  private String getOutput(String pageName) throws Exception {
    URL url = this.getURL(pageName);
    WebClient webClient = this.getWebClient();
    HtmlPage page = (HtmlPage) webClient.getPage(url);

    HtmlElement output = page.getHtmlElementById("output");

    return output.asText();
  }
Exemplo n.º 19
0
 @JsfTest(JsfVersion.JSF_2_2_1)
 @Test
 public void testNoELEvaluation() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/hOutputStylesheet.xhtml");
   assertEquals(200, page.getWebResponse().getStatusCode());
   HtmlElement button = page.getHtmlElementById("form:submit");
   page = button.click();
   assertEquals(200, page.getWebResponse().getStatusCode());
 }
Exemplo n.º 20
0
  @Test
  public void testMeter() throws Exception {
    HtmlPage page = webClient.getPage(webUrl + "faces/meter.xhtml");
    HtmlElement elem = page.getHtmlElementById("meter1");
    String xml = elem.asXml();
    assertTrue(xml.contains("<meter"));
    assertTrue(xml.contains("id=\"" + "meter1" + "\""));
    assertTrue(xml.contains("min=\"" + "200" + "\""));
    assertTrue(xml.contains("max=\"" + "500" + "\""));
    assertTrue(xml.contains("value=\"" + "350" + "\""));

    elem = page.getHtmlElementById("meter2");
    xml = elem.asXml();
    assertTrue(xml.contains("<meter"));
    assertTrue(xml.contains("id=\"" + "meter2" + "\""));
    assertTrue(xml.contains("min=\"" + "100" + "\""));
    assertTrue(xml.contains("max=\"" + "500" + "\""));
    assertTrue(xml.contains("value=\"" + "350" + "\""));
  }
Exemplo n.º 21
0
 @Test
 public void testLabel() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/label.xhtml");
   HtmlElement elem = page.getHtmlElementById("label1");
   String xml = elem.asXml();
   assertTrue(xml.contains("<label"));
   assertTrue(xml.contains("id=\"" + "label1" + "\""));
   assertTrue(xml.contains("form=\"" + "form" + "\""));
   assertTrue(xml.contains("for=\"" + "input1" + "\""));
 }
  @LocalData
  public void testOldActionViewsWithData() throws Exception {
    WebClient wc = getWebClient();
    HtmlPage page = wc.goTo("job/oldrobotbuild/");
    WebAssert.assertElementPresentByXPath(
        page, "//div[@id='navigation']//a[@href='/job/oldrobotbuild/robot']");
    WebAssert.assertElementPresentByXPath(
        page, "//td[@id='main-panel']//h4[contains(.,'Latest Robot Results:')]");
    WebAssert.assertElementPresentByXPath(page, "//td[@id='main-panel']//img[@src='robot/graph']");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='/job/oldrobotbuild/1/robot' and contains(text(),'Browse results')]");
    HtmlTable table = page.getHtmlElementById("robot-summary-table");
    Assert.assertTrue(
        table
            .asXml()
            .replaceAll("\\s", "")
            .contains(
                "<tableclass=\"table\"id=\"robot-summary-table\"><tbodyalign=\"left\"><tr><th/><th>Total</th><th>Failed</th><th>Passed</th><th>Pass%</th></tr><tr><th>Criticaltests</th><tdclass=\"table-upper-row\"style=\"border-left:0px;\">8</td><tdclass=\"table-upper-row\"><spanclass=\"fail\">4</span></td><tdclass=\"table-upper-row\">4</td><tdclass=\"table-upper-row\">50.0</td></tr><tr><th>Alltests</th><tdstyle=\"border-left:0px;\">8</td><td><spanclass=\"fail\">4</span></td><td>4</td><td>50.0</td></tr></tbody></table>"));

    page = wc.goTo("job/oldrobotbuild/robot/");
    WebAssert.assertTitleEquals(page, "Testcases & Othercases Test Report");

    page = wc.goTo("job/oldrobotbuild/1/");
    WebAssert.assertElementPresentByXPath(
        page, "//div[@id='navigation']//a[@href='/job/oldrobotbuild/1/robot']");
    WebAssert.assertElementPresentByXPath(
        page, "//td[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='/job/oldrobotbuild/1/robot' and contains(text(),'Browse results')]");
    table = page.getHtmlElementById("robot-summary-table");
    Assert.assertTrue(
        table
            .asXml()
            .replaceAll("\\s", "")
            .contains(
                "<tableclass=\"table\"id=\"robot-summary-table\"><tbodyalign=\"left\"><tr><th/><th>Total</th><th>Failed</th><th>Passed</th><th>Pass%</th></tr><tr><th>Criticaltests</th><tdclass=\"table-upper-row\"style=\"border-left:0px;\">8</td><tdclass=\"table-upper-row\"><spanclass=\"fail\">4</span></td><tdclass=\"table-upper-row\">4</td><tdclass=\"table-upper-row\">50.0</td></tr><tr><th>Alltests</th><tdstyle=\"border-left:0px;\">8</td><td><spanclass=\"fail\">4</span></td><td>4</td><td>50.0</td></tr></tbody></table>"));

    page = wc.goTo("job/oldrobotbuild/1/robot/");
    WebAssert.assertTitleEquals(page, "Testcases & Othercases Test Report");
  }
Exemplo n.º 23
0
  @JsfTest(JsfVersion.JSF_2_2_5)
  @Test
  public void testDropFlashCookie() throws Exception {

    HtmlPage page = webClient.getPage(webUrl + "faces/flashDropCookie.xhtml");
    webClient.getOptions().setRedirectEnabled(true);
    HtmlTextInput textInput = (HtmlTextInput) page.getHtmlElementById("input");
    textInput.setValueAttribute("test");
    HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("submit");

    int currentSize = webClient.getCookieManager().getCookies().size();

    page = button.click();
    HtmlElement element = page.getHtmlElementById("link");
    page = element.click();

    int newSize = webClient.getCookieManager().getCookies().size();

    assertTrue(newSize < currentSize);
  }
Exemplo n.º 24
0
  private HtmlPage doRefreshWithRedirectParamsButton(HtmlPage page, int storyNum) throws Exception {
    // click the "refreshWithRedirectParams" button and make sure we're still
    // on the same page.
    HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("refreshWithRedirectParams");
    page = (HtmlPage) button.click();
    String pageText = page.asText();
    assertTrue(-1 != pageText.indexOf(getTitleContains(storyNum)));
    assertTrue(-1 != pageText.indexOf(getContentContains(storyNum)));

    return page;
  }
Exemplo n.º 25
0
 @Test
 public void testLabelAjaxBehavior() throws Exception {
   webClient.setJavaScriptEnabled(true);
   webClient.setJavaScriptTimeout(60000);
   HtmlPage page = webClient.getPage(webUrl + "/faces/label.xhtml");
   HtmlElement label = page.getHtmlElementById("label2");
   page = (HtmlPage) label.mouseOver();
   webClient.waitForBackgroundJavaScript(60000);
   assertTrue(page.asXml().contains("label2 Event: begin"));
   assertTrue(page.asXml().contains("label2 Event: complete"));
   assertTrue(page.asXml().contains("label2 Event: success"));
 }
Exemplo n.º 26
0
 @Test
 public void testFieldSetAjaxBehavior() throws Exception {
   webClient.setJavaScriptEnabled(true);
   webClient.setJavaScriptTimeout(60000);
   HtmlPage page = webClient.getPage(webUrl + "/faces/fieldset.xhtml");
   HtmlFieldSet fieldset = (HtmlFieldSet) page.getHtmlElementById("fieldset4");
   page = fieldset.click();
   webClient.waitForBackgroundJavaScript(60000);
   assertTrue(page.asXml().contains("fieldset4 Event: begin"));
   assertTrue(page.asXml().contains("fieldset4 Event: complete"));
   assertTrue(page.asXml().contains("fieldset4 Event: success"));
 }
Exemplo n.º 27
0
  private HtmlPage doRefreshButton(HtmlPage page, int storyNum) throws Exception {
    String pageText = null;

    // Click the "refresh" button, ensure the page refreshes properly
    HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("refresh");
    page = (HtmlPage) button.click();
    pageText = page.asText();
    assertTrue(-1 != pageText.indexOf(getTitleContains(storyNum)));
    assertTrue(-1 != pageText.indexOf(getContentContains(storyNum)));

    return page;
  }
Exemplo n.º 28
0
  /**
   * Test evaluation relative from elements other than the whole page.
   *
   * @throws Exception if test fails
   */
  @Test
  public void xpathFromElement() throws Exception {
    final String content =
        "<html><head><title>Test page</title></head>\n"
            + "<body><a href='foo.html' id='myLink'>foo</a></body>\n"
            + "</html>";

    final HtmlPage page = loadPage(content);
    final HtmlBody body = page.getFirstByXPath("/html/body");

    assertEquals(page.getHtmlElementById("myLink"), body.getFirstByXPath("./a"));
  }
Exemplo n.º 29
0
  @Test
  public void testFieldset() throws Exception {
    HtmlPage page = webClient.getPage(webUrl + "faces/fieldset.xhtml");
    HtmlElement elem = page.getHtmlElementById("fieldset1");
    String xml = elem.asXml();
    assertTrue(xml.contains("<fieldset"));
    assertTrue(xml.contains("id=\"" + "fieldset1" + "\""));

    elem = page.getHtmlElementById("fieldset2");
    xml = elem.asXml();
    assertTrue(xml.contains("<fieldset"));
    assertTrue(xml.contains("id=\"" + "fieldset2" + "\""));
    assertTrue(xml.contains("disabled=\"" + "disabled" + "\""));

    elem = page.getHtmlElementById("fieldset3");
    xml = elem.asXml();
    assertTrue(xml.contains("<fieldset"));
    assertTrue(xml.contains("id=\"" + "fieldset3" + "\""));
    assertTrue(xml.contains("form=\"" + "form" + "\""));
    assertTrue(xml.contains("name=\"" + "myfieldset" + "\""));
  }
Exemplo n.º 30
0
  private HtmlPage doHomeKeepSelectionButton(HtmlPage page, int storyNum) throws Exception {
    String pageText = null;
    // Click the "homeKeepSelection" button, ensure you get back
    // to the home page with the proper story number
    HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("homeRememberSelection");
    page = (HtmlPage) button.click();
    pageText = page.asText();

    assertOnHomePage(pageText);
    assertTrue(-1 == pageText.indexOf("You just looked at story #" + storyNum + "."));

    return page;
  }