예제 #1
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);
  }
예제 #2
0
파일: Main.java 프로젝트: 9316/IdeaProjects
  public static void main(String[] args) {
    WebClient client = new WebClient(BrowserVersion.CHROME);
    HtmlPage page = null;

    try {
      page = client.getPage("http://www.facebook.com");

      System.out.println(page.getTitleText());

      HtmlForm form = (HtmlForm) page.getElementById("login_form");
      form.getInputByName("email").setValueAttribute("*****@*****.**");
      form.getInputByName("pass").setValueAttribute("saburtalo16");
      page = form.getInputByValue("Log In").click();
      System.out.println(page.getTitleText());

      HtmlTextArea statusText = (HtmlTextArea) page.getElementByName("xhpc_message_text");
      statusText.click();
      statusText.setText("I'm a robot");
      HtmlButton post =
          (HtmlButton)
              page.getFirstByXPath("//button[@id=\"u_jsonp_3_4\"]/div/div[4]/div/ul/li[2]/button");
      post.click();

    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }
예제 #3
0
  private HtmlPage clickButtonReturnPage(Object tempsubmit) throws IOException {
    HtmlSubmitInput htmlsubmit;
    HtmlButton htmlbutton;
    //   a = "";
    if (tempsubmit.getClass().getName().contains("HtmlButton")) {
      htmlbutton = (HtmlButton) tempsubmit;
      return htmlbutton.click(); // .getWebResponse().getContentAsString();
    } else if (tempsubmit.getClass().getName().contains("HtmlSubmitInput")) {
      htmlsubmit = (HtmlSubmitInput) tempsubmit;
      return htmlsubmit.click(); // .getWebResponse().getContentAsString();
    }

    return null;
  }
예제 #4
0
  @Test
  public void testDirectLogin() throws IOException {
    beginAt("");
    clickLink("login");
    assertTitleEquals("MediaMagpie - Login");
    // System.out.println(getPageSource());
    setTextField("username", "rwe");
    setTextField("password", "rwe");
    IElement elementByXPath = getTestingEngine().getElementByXPath("//button[@type='submit']");
    HtmlButton submitButton = (HtmlButton) ((HtmlUnitElementImpl) elementByXPath).getHtmlElement();

    submitButton.click();

    // System.out.println(getPageSource());
    assertTitleEquals("MediaMagpie - Welcome to MediaMagpie");
  }
예제 #5
0
 @Override
 protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage)
     throws Exception {
   webClient.waitForBackgroundJavaScript(5000);
   HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlTextInput login = form.getInputByName("login_email");
   login.setValueAttribute("*****@*****.**");
   final HtmlPasswordInput passwd = form.getInputByName("login_password");
   passwd.setValueAttribute("testpwdscribeup");
   HtmlButton submit = form.getButtonByName("");
   HtmlPage confirmPage = submit.click();
   confirmPage = (HtmlPage) confirmPage.refresh();
   webClient.waitForBackgroundJavaScript(5000);
   form = confirmPage.getForms().get(0);
   HtmlButton submit2 = form.getButtonByName("allow_access");
   final HtmlPage callbackPage = submit2.click();
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }