Esempio n. 1
0
  public void testPreviewDiffBug() throws Exception {
    // https://bugs.corefiling.com/show_bug.cgi?id=13510
    // Old versions of the diff_match_patch package have a bug in the diff_cleanupSemantic method
    // The two comparison strings need to be well crafted to trigger the bug.
    String name = uniqueWikiPageName("PreviewPageTest");
    String content =
        "="
            + NEWLINE_TEXTAREA
            + "This is a lis of things that someone be doing if"
            + NEWLINE_TEXTAREA
            + "===Wiki"
            + NEWLINE_TEXTAREA;
    String newContent = "||" + NEWLINE_TEXTAREA + "==";

    HtmlPage edited = editWikiPage(name, content, "", "", true);
    HtmlPage editPage = clickEditLink(edited);
    HtmlForm form = editPage.getFormByName(ID_EDIT_FORM);
    HtmlTextArea contentArea = form.getTextAreaByName("content");
    contentArea.setText(newContent);
    editPage = (HtmlPage) form.getInputByValue("Preview").click();

    form = editPage.getFormByName(ID_EDIT_FORM);
    contentArea = form.getTextAreaByName("content");
    assertEquals(newContent + NEWLINE_TEXTAREA, contentArea.getText());
  }
Esempio n. 2
0
  public void testPreview() throws Exception {
    String name = uniqueWikiPageName("PreviewPageTest");
    HtmlPage editPage = clickEditLink(getWikiPage(name));
    HtmlForm form = editPage.getFormByName(ID_EDIT_FORM);
    HtmlInput minorEdit = form.getInputByName("minorEdit");
    assertFalse(minorEdit.isChecked());
    minorEdit.setChecked(true);
    HtmlInput description = form.getInputByName("description");
    String expectedDescription = "My test change";
    description.setValueAttribute(expectedDescription);
    HtmlTextArea content = form.getTextAreaByName("content");
    String expectedContent = "http://www.example.com";
    content.setText(expectedContent);

    // Now if we preview we should get the previewed text rendered, and in
    // the edit area.  The other options should be preserved too.
    editPage = (HtmlPage) form.getInputByValue("Preview").click();
    form = editPage.getFormByName(ID_EDIT_FORM);
    minorEdit = form.getInputByName("minorEdit");
    description = form.getInputByName("description");
    content = form.getTextAreaByName("content");
    assertEquals(expectedDescription, description.getValueAttribute());
    assertTrue(minorEdit.isChecked());
    assertEquals(expectedContent + NEWLINE_TEXTAREA, content.getText());
    // This checks for the rendering...
    assertNotNull(editPage.getAnchorByHref(expectedContent));
  }
Esempio n. 3
0
  private void testInvalidSessionIdHelper(
      final String button,
      final String name,
      final String failMsg,
      final boolean fakeAppendedSessionId)
      throws IOException, JaxenException {
    HtmlPage editPage = clickEditLink(getWikiPage(name));
    final HtmlForm form = editPage.getFormByName(ID_EDIT_FORM);
    final HtmlInput sessionId = form.getInputByName("sessionId");
    sessionId.setValueAttribute(FAKE_SESSION_ID);
    if (fakeAppendedSessionId) {
      form.setActionAttribute(name + ";jsessionid=" + FAKE_SESSION_ID);
    }
    final HtmlTextArea content = form.getTextAreaByName("content");
    final String expectedContent = "http://www.example.com";
    content.setText(expectedContent);

    editPage = (HtmlPage) form.getInputByValue(button).click();

    try {
      getAnchorByHrefContains(editPage, expectedContent);
      fail(failMsg);
    } catch (NoSuchElementException e) {
    }
  }
Esempio n. 4
0
  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.
    }
  }
Esempio n. 5
0
    @Test public void privateView() throws Exception {
        j.createFreeStyleProject("project1");
        User user = User.get("me", true); // create user

        WebClient wc = j.createWebClient();
        HtmlPage userPage = wc.goTo("user/me");
        HtmlAnchor privateViewsLink = userPage.getFirstAnchorByText("My Views");
        assertNotNull("My Views link not available", privateViewsLink);

        HtmlPage privateViewsPage = (HtmlPage) privateViewsLink.click();

        Text viewLabel = (Text) privateViewsPage.getFirstByXPath("//div[@class='tabBar']//div[@class='tab active']/a/text()");
        assertTrue("'All' view should be selected", viewLabel.getTextContent().contains(Hudson_ViewName()));

        View listView = listView("listView");

        HtmlPage newViewPage = wc.goTo("user/me/my-views/newView");
        HtmlForm form = newViewPage.getFormByName("createItem");
        form.getInputByName("name").setValueAttribute("proxy-view");
        ((HtmlRadioButtonInput) form.getInputByValue("hudson.model.ProxyView")).setChecked(true);
        HtmlPage proxyViewConfigurePage = j.submit(form);
        View proxyView = user.getProperty(MyViewsProperty.class).getView("proxy-view");
        assertNotNull(proxyView);
        form = proxyViewConfigurePage.getFormByName("viewConfig");
        form.getSelectByName("proxiedViewName").setSelectedAttribute("listView", true);
        j.submit(form);

        assertTrue(proxyView instanceof ProxyView);
        assertEquals(((ProxyView) proxyView).getProxiedViewName(), "listView");
        assertEquals(((ProxyView) proxyView).getProxiedView(), listView);
    }
 @Override
 protected String getCallbackUrlForCancel(final HtmlPage authorizationPage) throws Exception {
   final HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlSubmitInput submit = form.getInputByValue("Cancel");
   final HtmlPage callbackPage = submit.click();
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }
Esempio n. 7
0
  /**
   * Static method for <code>Login</code>. Uses dependencies <b>HttpUnit</b> in connecting to Keats.
   *
   * @see com.gargoylesoftware.htmlunit
   * @param parent The parent window. instanceof<code>Scrape</code>, to set relative locations to
   * @param link The url of which to retrieve information from.
   * @param username The username to log in KEATS with.
   * @param password The password to log in KEATS with.
   * @return results.asText() Returns the content of the url if login successful. Returns null
   *     otherwise.
   */
  public static String login(Scrape parent, String link, String username, String password) {
    try {
      WebClient client = new WebClient();

      // Settings
      client.getOptions().setThrowExceptionOnScriptError(false);
      client.getOptions().setThrowExceptionOnScriptError(false);
      client.getOptions().setThrowExceptionOnFailingStatusCode(false);
      client.getOptions().setJavaScriptEnabled(false);
      client.getOptions().setCssEnabled(false);
      client.getOptions().setRedirectEnabled(true);
      client.getOptions().setUseInsecureSSL(true);
      client.getCookieManager().setCookiesEnabled(true);

      HtmlPage page = client.getPage("https://login-keats.kcl.ac.uk/");

      HtmlForm form =
          page.getFirstByXPath("//form[@action='https://keats.kcl.ac.uk/login/index.php']");

      HtmlInput usernameInput = form.getInputByName("username");
      usernameInput.setValueAttribute(username);
      HtmlInput passwordInput = form.getInputByName("password");
      passwordInput.setValueAttribute(password);

      page = form.getInputByValue("Log in").click();

      HtmlPage results = client.getPage(link);

      client.closeAllWindows();
      return results.asText();
    } catch (MalformedURLException e) {
      JOptionPane.showMessageDialog(
          parent,
          "The URL you have provided is not recognised. Please double check your "
              + "input and try again.",
          "MalformedURLException found.",
          JOptionPane.ERROR_MESSAGE);
      e.printStackTrace();
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          parent,
          "An error has occurred when attempting to read information from the "
              + "server. The input could be interrupted by external processes.",
          "IOException found.",
          JOptionPane.ERROR_MESSAGE);
      e.printStackTrace();
    }

    return null;
  }
Esempio n. 8
0
 private void editThenCancel(final String name) throws Exception {
   final String flagText = "Should not be saved.";
   HtmlPage editPage = clickEditLink(getWikiPage(name));
   HtmlForm form = editPage.getFormByName(ID_EDIT_FORM);
   form.getTextAreaByName("content").setText(flagText);
   HtmlPage viewPage = (HtmlPage) form.getInputByValue("Cancel").click();
   assertFalse(viewPage.asText().contains(flagText));
   try {
     viewPage.getFormByName(ID_EDIT_FORM);
     fail("Should be back to view page, not edit form.");
   } catch (ElementNotFoundException ignore) {
   }
   assertEquals("Should not be present.", 0, viewPage.getByXPath("id('lockedInfo')").size());
 }
 @Override
 protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage)
     throws Exception {
   final HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlPasswordInput password = form.getInputByName("password");
   password.setValueAttribute("testpwdpac4j");
   final HtmlSubmitInput submit = form.getInputByValue("Sign In");
   final HtmlPage callbackPage = submit.click();
   /*form = confirmPage.getForms().get(0);
   HtmlButton continueButton = (HtmlButton) form.getElementById("continue-button");
   HtmlPage callbackPage = continueButton.click();*/
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }
Esempio n. 10
0
  public void testPreviewWithChangedAttributes() throws Exception {
    String name = uniqueWikiPageName("PreviewPageTest");
    HtmlPage editPage = clickEditLink(getWikiPage(name));
    HtmlForm form = editPage.getFormByName(ID_EDIT_FORM);
    HtmlTextArea attributes = form.getTextAreaByName("attributes");
    String expectedContent = "SomeContent";
    String expectedAttributes = "\"text\" = \"" + expectedContent + "\"";
    attributes.setText(expectedAttributes);
    HtmlTextArea content = form.getTextAreaByName("content");
    String expectedContentSource = "<<attr:text>>";
    content.setText(expectedContentSource);

    // Now if we preview we should get the previewed text rendered, and in
    // the edit area.
    editPage = (HtmlPage) form.getInputByValue("Preview").click();
    editPage.asText().contains(expectedContent);
    form = editPage.getFormByName(ID_EDIT_FORM);
    attributes = form.getTextAreaByName("attributes");
    assertEquals(expectedAttributes + NEWLINE_TEXTAREA, attributes.getText());
    content = form.getTextAreaByName("content");
    assertEquals(expectedContentSource + NEWLINE_TEXTAREA, content.getText());
  }
Esempio n. 11
0
  public static void main(String[] args) throws Exception {
    // Create and initialize WebClient object
    // Create and initialize WebClient object
    String dualPwd = "xxxxxx";
    WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);
    // webClient.throwFailingHttpStatusCodeExceptionIfNecessary(webResponse);

    // visit Yahoo Mail login page and get the Form object
    HtmlPage page =
        (HtmlPage)
            webClient.getPage(
                "https://www.ebanking.hsbc.com.hk/1/2/logon?LANGTAG=en&COUNTRYTAG=US");
    HtmlForm form = page.getFormByName("User");

    // Enter login and passwd
    form.getInputByName("u_UserID").setValueAttribute("charlieskc");
    page = (HtmlPage) form.getInputByValue("press").setValueAttribute("click");
    List<HtmlAnchor> anchorList = page.getAnchors();
    for (HtmlAnchor anchor : anchorList) {
      if (anchor
          .getOnClickAttribute()
          .equals(
              "document.getElementById('submittype').value = 'click';PC_7_0G3UNU10SD0MHTI7TQA0000000000000_selectLogonMode(0)")) {
        System.out.println(anchor.getHrefAttribute());
        System.out.println(anchor.getOnClickAttribute());
        page = anchor.click();
        // System.out.println(page.asXml());
      }
    }

    HtmlForm passwordform = page.getFormByName("PC_7_0G3UNU10SD0MHTI7EMA0000000000000_pwd");
    passwordform.getInputByName("memorableAnswer").setValueAttribute("z0226409");

    HtmlForm secondPasswordform =
        page.getFormByName("PC_7_0G3UNU10SD0MHTI7EMA0000000000000_2ndpwd");
    // secondPasswordform.getInputByName("memorableAnswer").setValueAttribute("z0226409");

    HtmlTable table = getTableFromDomElement(secondPasswordform);

    System.out.println("Table xml" + table.asXml());

    for (HtmlElement element : secondPasswordform.getHtmlElementDescendants()) {
      // System.out.println(element.asXml());
    }

    ScriptResult result =
        page.executeJavaScript("PC_7_0G3UNU10SD0MHTI7TQA0000000000000_selectLogonMode(0)");
    page = (HtmlPage) result.getNewPage();

    // System.out.println("result: "+ result);

    // System.out.println("result: " + page.asXml());

    // form.getInputByName("logonMode").setValueAttribute("charlieskc");
    // form.getInputByName("passwd").setValueAttribute("@@@@@@@");

    // Click "Sign In" button/link

    // Click "Inbox" link
    HtmlAnchor anchor = (HtmlAnchor) page.getHtmlElementById("WelcomeInboxFolderLink");
    page = (HtmlPage) anchor.click();

    // Get the table object containing the mails
    HtmlTable dataTable = (HtmlTable) page.getHtmlElementById("datatable");

    // Go through each row and count the row with class=msgnew
    int newMessageCount = 0;
    List<HtmlTableRow> rows = (List) dataTable.getHtmlElementsByTagName("tr");
    for (HtmlTableRow row : rows) {
      if (row.getAttribute("class").equals("msgnew")) {
        newMessageCount++;
      }
    }

    // Print the newMessageCount to screen
    System.out.println("newMessageCount = " + newMessageCount);

    // System.out.println(page.asXml());
  }
Esempio n. 12
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    int no = 0;
    try {
      no = Integer.parseInt(request.getParameter("no"));

    } catch (NumberFormatException exception) {
      no = 0;
    }

    try {
      /* TODO output your page here. You may use following sample code. */
      out.println("<!DOCTYPE html>");
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet NewServlet</title>");
      out.println("</head>");
      out.println("<body>");

      final WebClient webClient = new WebClient();
      webClient.getCookieManager().clearCookies();
      webClient.getOptions().setUseInsecureSSL(true);
      webClient.setJavaScriptEnabled(false);
      final HtmlPage page = webClient.getPage("https://filestream.me/");
      // out.println(page.getTitleText());
      System.out.println("no of forms : " + page.getForms().size());
      HtmlForm form = page.getForms().get(1);
      final HtmlTextInput textField = form.getInputByName("login");
      textField.setAttribute("value", "*****@*****.**");

      final HtmlPasswordInput passField = form.getInputByName("password");
      passField.setAttribute("value", "ramkrishnan18");
      HtmlSubmitInput htmlSubmitInput = form.getInputByValue("login");
      HtmlPage page1 = htmlSubmitInput.click();

      HtmlTable htmlTable = page1.getHtmlElementById("fileCatTable");
      List<HtmlTableRow> listOfHtmlTableRow = htmlTable.getBodies().get(0).getRows();
      List<String> allLinks = new ArrayList<String>();
      for (HtmlTableRow htmlTableRow : listOfHtmlTableRow) {
        HtmlTableCell cell = htmlTableRow.getCells().get(htmlTableRow.getCells().size() - 1);
        for (DomElement domElement : cell.getChildElements()) {
          // out.println(domElement.getTagName());
          if (domElement.getTagName().equals("div")) {
            boolean flag = true;

            for (DomElement celldomElement : domElement.getChildElements()) {
              if (flag) {
                // out.println(celldomElement.getTagName());

                String title = celldomElement.getAttribute("title");
                if ("Download".equals(title) || "Downloads".equals(title)) {

                  String link = celldomElement.getAttribute("onclick");
                  String http =
                      link.substring(
                          link.indexOf('\'') + 1, link.indexOf('\'', link.indexOf('\'') + 1));

                  //  out.println(celldomElement.getAttribute("onclick") + "<br/>");
                  // out.println(http + "<br/>");
                  allLinks.add(http);
                  flag = false;
                }
              }
            }
          }
        }
      }

      //  InputStream is =anchorAttachment.click().getWebResponse().getContentAsStream();

      out.println("************ Start *************");

      //  HtmlAnchor anchorElement=HTMLAnchorElement.;
      //  anchorElement.set
      // anchorElement.setHref(allLinks.get(0));

      //  anchorElement.cl
      final String u = allLinks.get(no);
      Thread t =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  try {
                    URL url = new URL(u);
                    System.out.println("Link : " + u);
                    HttpURLConnection con = (HttpURLConnection) url.openConnection();

                    // System.out.println("Response Code : " + con.getInputStream().available());
                    con.setRequestProperty("Accept-Encoding", "gzip,deflate");
                    con.setRequestProperty(
                        "User-Agent",
                        "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36");

                    Map<String, List<String>> map = con.getHeaderFields();

                    for (String object : map.keySet()) {
                      System.out.println(object + " --> " + map.get(object));
                    }

                    System.out.println("Response Code : " + con.getResponseCode());
                    System.out.println("length :" + con.getContentLength());
                    System.out.println("Message " + con.getResponseMessage());

                    InputStream inputStream = con.getInputStream();
                    String path = System.getenv("OPENSHIFT_JBOSSAS_DIR");
                    FileOutputStream fileOutputStream = new FileOutputStream(path + "test.zip");
                    byte[] buffer = new byte[1024];
                    System.out.println(inputStream.available());
                    int bytesRead = 10;
                    while (true) {
                      //   System.out.print("--");
                      bytesRead = inputStream.read(buffer);
                      //   System.out.println(bytesRead);
                      if (bytesRead == -1) {
                        break;
                      }
                      fileOutputStream.write(buffer, 0, bytesRead);
                      // System.out.print(">");
                    }
                    fileOutputStream.close();

                    System.out.println("File Completed");
                  } catch (IOException ex) {
                    Logger.getLogger(MakeData.class.getName()).log(Level.SEVERE, null, ex);
                  }
                }
              });
      t.start();

      //            System.out.println(allLinks.get(0));
      //            System.out.println(webClient.getCookieManager().getCookies(new
      // URL(allLinks.get(0))).size());
      //            // System.out.println(httpPage.asText());
      //             HtmlPage httpPage = webClient.getPage(allLinks.get(0));
      //
      //           // final String pageAsXml = page1.asXml();
      //            // InputStream inputStream=httpPage.getWebResponse().getContentAsStream();
      //           //  inputStream.available();
      //              System.out.println("Code : "+httpPage.getWebResponse().getStatusMessage());
      //               System.out.println("Code : "+httpPage.getWebResponse().getContentType());
      //                System.out.println("netCode :
      // "+httpPage.getWebResponse().getContentCharset());
      //
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getStatusCode());
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getContentType());
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getContentCharset());

      // final String pageAsText = page1.asText();

      // out.println(pageAsXml);
      webClient.closeAllWindows();
      out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
      out.println("</body>");
      out.println("</html>");
    } finally {
      out.close();
    }
  }