public void testDoConfigure() throws Exception {
    UpdateSite target = new UpdateSite("test1", "http://example.com/test/update-center.json");

    // Multiple update site.
    Jenkins.getInstance().getUpdateCenter().getSites().clear();
    Jenkins.getInstance().getUpdateCenter().getSites().add(target);

    String originalId = target.getId();

    WebClient wc = new WebClient();

    HtmlPage editSitePage = wc.goTo(String.format("%s/%s", UpdateSitesManager.URL, target.getId()));

    HtmlForm editSiteForm = editSitePage.getFormByName("editSiteForm");
    assertNotNull("There must be editSiteForm", editSiteForm);

    String newId = "newId";
    String newUrl = "http://localhost/update-center.json";
    editSiteForm.getInputByName("_.id").setValueAttribute(newId);
    editSiteForm.getInputByName("_.url").setValueAttribute(newUrl);
    submit(editSiteForm);

    UpdateSite site = null;
    for (UpdateSite s : Jenkins.getInstance().getUpdateCenter().getSites()) {
      if (newId.equals(s.getId())) {
        site = s;
      }
      assertFalse("id must be updated(old one must not remain)", originalId.equals(s.getId()));
    }
    assertNotNull("id must be updated", site);
    assertEquals("url must be updated", newUrl, site.getUrl());
  }
예제 #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));
  }
예제 #3
0
  @Override
  protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception {
    HtmlForm form = authorizationPage.getFormByName("loginform");
    final HtmlTextInput login = form.getInputByName("log");
    login.setValueAttribute("testscribeup");
    final HtmlPasswordInput passwd = form.getInputByName("pwd");
    passwd.setValueAttribute("testpwdscribeup");

    HtmlElement button = (HtmlElement) authorizationPage.createElement("button");
    button.setAttribute("type", "submit");
    form.appendChild(button);
    // HtmlButton button = form.getButtonByName("wp-submit");

    final HtmlPage confirmPage = button.click();
    form = confirmPage.getFormByName("loginform");

    button = (HtmlElement) confirmPage.createElement("button");
    button.setAttribute("type", "submit");
    form.appendChild(button);
    // button = form.getButtonByName("wp-submit");

    final HtmlPage callbackPage = button.click();
    final String callbackUrl = callbackPage.getUrl().toString();
    logger.debug("callbackUrl : {}", callbackUrl);
    return callbackUrl;
  }
예제 #4
0
  public boolean athenticated() {

    web = new WebClient();
    try {
      page1 = web.getPage(url);
    } catch (FailingHttpStatusCodeException | IOException e) {
      e.printStackTrace();
    }
    HtmlForm form = page1.getFormByName("form2");

    form.getInputByName("txtUserName").setAttribute("value", username);
    form.getInputByName("txtPassword").setAttribute("value", password);
    try {
      page2 = form.getInputByName("LoginButton").click();
    } catch (ElementNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    if (page2.getUrl().toString().equals("http://78.39.200.210/Default.aspx")) {
      return true;
    } else {
      web.closeAllWindows();
      return false;
    }
  }
  public void testLogInWithOpenIDAndSignUp() throws Exception {
    openid = createServer();

    realm = new HudsonPrivateSecurityRealm(true);
    hudson.setSecurityRealm(realm);

    WebClient wc = new WebClient();
    // Workaround failing ajax requests to build queue
    wc.setThrowExceptionOnFailingAjax(false);

    // Login with OpenID as an unregistered user
    HtmlPage login = wc.goTo("federatedLoginService/openid/login?from=/");
    login
        .getDocumentElement()
        .getOneHtmlElementByAttribute("a", "title", "log in with OpenID")
        .click();
    HtmlForm loginForm = getFormById(login, "openid_form");
    loginForm.getInputByName("openid").setValueAttribute(openid.url);
    HtmlPage signUp = (HtmlPage) loginForm.submit();

    // Sign up user
    HtmlForm signUpForm =
        getFormByAction(signUp, "/securityRealm/createAccountWithFederatedIdentity");
    signUpForm.getInputByName("password1").setValueAttribute("x");
    signUpForm.getInputByName("password2").setValueAttribute("x");
    HtmlPage loggedIn = submit(signUpForm);

    assertNotNull(loggedIn.getAnchorByHref("/logout"));
    assertNotNull(loggedIn.getAnchorByHref("/user/aliceW"));

    wc.goTo("logout");

    // Re-login
    login(wc);
  }
예제 #6
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.
    }
  }
예제 #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;
  }
예제 #8
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) {
    }
  }
예제 #9
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);
    }
예제 #10
0
  public void testFileItemPersistence() throws Exception {
    // TODO: write a synchronous connector?
    byte[] testData = new byte[1024];
    for (int i = 0; i < testData.length; i++) testData[i] = (byte) i;

    Server server = new Server();
    SocketConnector connector = new SocketConnector();
    server.addConnector(connector);

    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(new ServletHolder(new FileItemPersistenceTestServlet()), "/");
    server.addHandler(handler);

    server.start();

    localPort = connector.getLocalPort();

    try {
      WebClient wc = new WebClient();
      HtmlPage p = (HtmlPage) wc.getPage("http://localhost:" + localPort + '/');
      HtmlForm f = p.getFormByName("main");
      HtmlFileInput input = (HtmlFileInput) f.getInputByName("test");
      input.setData(testData);
      f.submit();
    } finally {
      server.stop();
    }
  }
예제 #11
0
  public AppAnnieCrawlerJava(String application, String store, String rankType, AuthObject auth)
      throws ParsingException {
    url =
        "http://www.appannie.com/app/"
            + (store.equals("appstore") ? "ios" : store)
            + "/"
            + application.replaceAll(" ", "-").toLowerCase()
            + "/ranking/#view="
            + rankType
            + "&date=";

    WebClient webClient = buildWebClient();

    HtmlPage page = null;
    try {
      page = webClient.getPage("https://www.appannie.com/account/login/");
    } catch (IOException e) {
      e.printStackTrace(); // todo: throw exception
    }

    HtmlForm form = page.getFormByName("");

    // authentication
    try {
      form.getInputByName("username").setValueAttribute(auth.username());
    } catch (Throwable t) {
      throw new ParsingException(
          "Login form incorrect! Please check " + getClass().getName() + " for errors.");
    }

    try {
      form.getInputByName("password").setValueAttribute(auth.password());
    } catch (Throwable t) {
      throw new ParsingException(
          "Login form incorrect! Please check " + getClass().getName() + " for errors.");
    }

    try {
      form.getButtonByName("").click();
    } catch (IOException e) {
      throw new ParsingException(
          "Login form incorrect! Please check " + getClass().getName() + " for errors.");
    }

    cookieManager = webClient.getCookieManager();
  }
예제 #12
0
  /**
   * Test method.
   *
   * @throws IOException exception
   */
  public void testLoginInvalid() throws IOException {
    final WebClient webClient = new WebClient();
    // XXX: issues with jquery
    webClient.setJavaScriptEnabled(false);
    final HtmlPage page = webClient.getPage(HTTP_PROCC_LOGIN_USER);
    final HtmlForm form = page.getFormByName(LOGIN_USER_FORM_NAME);

    final HtmlTextInput textEmail = form.getInputByName(EMAIL_INPUT_NAME);
    final HtmlPasswordInput textPassword = form.getInputByName(PASSWD_INPUT_NAME);
    final HtmlSubmitInput btnLogin = form.getInputByName(LOGIN_SUBMIT_NAME);

    textEmail.setValueAttribute("invalidLogin");
    textPassword.setValueAttribute("invalidPasswd");

    final HtmlPage nextPage = btnLogin.click();
    assertTrue(nextPage.asText().contains("Błędny login bądź hasło"));

    webClient.closeAllWindows();
  }
예제 #13
0
 public static HtmlTextInput getTextInputByNames(final HtmlForm form, final List<String> names) {
   for (final String name : names) {
     try {
       final HtmlTextInput ret = form.getInputByName(name);
       return ret;
     } catch (final Exception e) {
     }
   }
   return null;
 }
예제 #14
0
  /**
   * Test method.
   *
   * @throws IOException exception
   */
  public void testLoginValid() throws IOException {
    final WebClient webClient = new WebClient();
    // XXX: issues with jquery
    webClient.setJavaScriptEnabled(false);
    final HtmlPage page = webClient.getPage(HTTP_PROCC_LOGIN_USER);
    final HtmlForm form = page.getFormByName(LOGIN_USER_FORM_NAME);

    final HtmlTextInput textEmail = form.getInputByName(EMAIL_INPUT_NAME);
    final HtmlPasswordInput textPassword = form.getInputByName(PASSWD_INPUT_NAME);
    final HtmlSubmitInput btnLogin = form.getInputByName(LOGIN_SUBMIT_NAME);

    textEmail.setValueAttribute("*****@*****.**");
    textPassword.setValueAttribute("malczyk123");

    final HtmlPage nextPage = btnLogin.click();
    assertTrue(nextPage.getTitleText().equals("Taskflow-Main"));

    webClient.closeAllWindows();
  }
예제 #15
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;
 }
예제 #16
0
    /**
     * Manual submission form.
     */
    public void testUploadJpi() throws Exception {
        HtmlPage page = new WebClient().goTo("pluginManager/advanced");
        HtmlForm f = page.getFormByName("uploadPlugin");
        File dir = env.temporaryDirectoryAllocator.allocate();
        File plugin = new File(dir, "tasks.jpi");
        FileUtils.copyURLToFile(getClass().getClassLoader().getResource("plugins/tasks.jpi"),plugin);
        f.getInputByName("name").setValueAttribute(plugin.getAbsolutePath());
        submit(f);

        assertTrue( new File(jenkins.getRootDir(),"plugins/tasks.jpi").exists() );
    }
예제 #17
0
 @Ignore("verified manually in Winstone but org.mortbay.JettyResponse.sendRedirect (6.1.26) seems to mangle the location")
 @Issue("JENKINS-18373")
 @Test public void unicodeName() throws Exception {
     HtmlForm form = j.createWebClient().goTo("newView").getFormByName("createItem");
     String name = "I ♥ NY";
     form.getInputByName("name").setValueAttribute(name);
     form.getRadioButtonsByName("mode").get(0).setChecked(true);
     j.submit(form);
     View view = j.jenkins.getView(name);
     assertNotNull(view);
     j.submit(j.createWebClient().getPage(view, "configure").getFormByName("viewConfig"));
 }
예제 #18
0
    @Issue("JENKINS-16608")
    @Test public void notAllowedName() throws Exception {
        HtmlForm form = j.createWebClient().goTo("newView").getFormByName("createItem");
        form.getInputByName("name").setValueAttribute("..");
        form.getRadioButtonsByName("mode").get(0).setChecked(true);

        try {
            j.submit(form);
            fail("\"..\" should not be allowed.");
        } catch (FailingHttpStatusCodeException e) {
            assertEquals(400, e.getStatusCode());
        }
    }
예제 #19
0
  // Submit the form with no modifications
  public void testFormInput02_submit01() throws Exception {

    checkFormInput00();
    HtmlPage page = getFormInput02();
    checkFormInput02(page, formInput02_pristine);
    HtmlForm form = getFormById(page, formInput02_name);
    assertNotNull("form exists", form);
    HtmlSubmitInput submit =
        (HtmlSubmitInput)
            form.getInputByName(formInput02_name + NamingContainer.SEPARATOR_CHAR + "submit");
    page = (HtmlPage) submit.click();
    checkFormInput02(page, formInput02_pristine);
  }
예제 #20
0
  // Submit the form with updates to every field
  public void testFormInput02_submit02() throws Exception {

    checkFormInput00();
    HtmlPage page = getFormInput02();
    checkFormInput02(page, formInput02_pristine);
    HtmlForm form = getFormById(page, formInput02_name);
    assertNotNull("form exists", form);
    for (int i = 0; i < formInput02_names.length; i++) {
      HtmlTextInput input =
          (HtmlTextInput)
              form.getInputByName(
                  formInput02_name + NamingContainer.SEPARATOR_CHAR + formInput02_names[i]);
      assertNotNull("field '" + formInput02_names[i] + "' exists", input);
      input.setValueAttribute(formInput02_updated[i]);
    }
    HtmlSubmitInput submit =
        (HtmlSubmitInput)
            form.getInputByName(formInput02_name + NamingContainer.SEPARATOR_CHAR + "submit");
    page = (HtmlPage) submit.click();
    checkFormInput02(page, formInput02_updated);
    checkFormInput01();
  }
예제 #21
0
  @Test
  public void enterCredential() throws Exception {
    HtmlPage p =
        j.createWebClient().goTo("descriptorByName/hudson.tools.JDKInstaller/enterCredential");
    HtmlForm form = p.getFormByName("postCredential");
    form.getInputByName("username").setValueAttribute("foo");
    form.getInputByName("password").setValueAttribute("bar");
    HtmlFormUtil.submit(form, null);

    DescriptorImpl d = j.jenkins.getDescriptorByType(DescriptorImpl.class);
    assertEquals("foo", d.getUsername());
    assertEquals("bar", d.getPassword().getPlainText());
  }
  private void login(WebClient wc) throws Exception {
    HtmlPage login = wc.goTo("federatedLoginService/openid/login?from=/");
    login
        .getDocumentElement()
        .getOneHtmlElementByAttribute("a", "title", "log in with OpenID")
        .click();
    HtmlForm loginForm = getFormById(login, "openid_form");
    loginForm.getInputByName("openid").setValueAttribute(openid.url);
    HtmlPage loggedIn = (HtmlPage) loginForm.submit();

    assertNotNull(loggedIn.getAnchorByHref("/logout"));
    assertNotNull(loggedIn.getAnchorByHref("/user/aliceW"));
  }
예제 #23
0
  public static HtmlPage login(HtmlPage page, String username, String password) {
    int attempts = 0;
    boolean loggedIn = false;
    while (!loggedIn) {
      try {
        if (attempts > 3) System.exit(1);
        attempts++;
        System.out.println("Logging in... (Attempt " + attempts + ")");

        page = wc.getPage("http://torn.com/login");

        final HtmlForm form = page.getFormByName("login");

        HtmlSubmitInput button = form.getInputByName("btnLogin");

        HtmlTextInput textField = form.getInputByName("player");

        // Change the value of the text field
        textField.setValueAttribute(username);

        final HtmlPasswordInput passwordField = form.getInputByName("password");

        // Change the value of the text field
        passwordField.setValueAttribute(password);

        // Now submit the form by clicking the button and get back the second page.
        page = button.click();

        page = wc.getPage("http://torn.com/index.php");
        loggedIn = true;

      } catch (Exception e) {
        System.out.println(e.toString());
        loggedIn = false;
      }
    }
    return page;
  }
예제 #24
0
  // Check the values of the input fields against the specified list
  private void checkJstlForEach01(HtmlPage page, String expected[]) {

    assertEquals("Correct page title", "jstl-foreach-01", page.getTitleText());
    HtmlForm form = getFormById(page, jstlForEach01_name);
    assertNotNull("form exists", form);
    for (int i = 0; i < expected.length; i++) {
      HtmlTextInput input =
          (HtmlTextInput)
              form.getInputByName(
                  jstlForEach01_name + NamingContainer.SEPARATOR_CHAR + jstlForEach01_names[i]);
      assertNotNull("field '" + jstlForEach01_names[i] + "' exists", input);
      assertEquals(
          "field '" + jstlForEach01_names[i] + "' value", expected[i], input.getValueAttribute());
    }
  }
예제 #25
0
 @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;
 }
예제 #26
0
 public void testCopy() throws Exception {
   String fromPageName = uniqueWikiPageName("CopyTestFrom");
   String toPageName = uniqueWikiPageName("CopyTestTo");
   editWikiPage(fromPageName, "Catchy tunes", "", "Whatever", true);
   HtmlPage page = getWikiPage(fromPageName);
   page = (HtmlPage) page.getAnchorByName("copy").click();
   HtmlForm form = page.getFormByName("copyForm");
   form.getInputByName("toPage").setValueAttribute(toPageName);
   page = (HtmlPage) form.getButtonByName("copy").click();
   assertTrue(
       page.getWebResponse().getWebRequest().getUrl().toURI().getPath().contains(toPageName));
   assertTrue(page.asText().contains("Catchy tunes"));
   page = getWikiPage(fromPageName);
   assertTrue(page.asText().contains("Catchy tunes"));
 }
예제 #27
0
  @Test
  public void testEndpoint()
      throws IOException, ServletException, DeploymentException, InterruptedException {
    UndertowWebSocketServer server = new UndertowWebSocketServer();
    server.start();

    WebClient webClient = new WebClient();
    HtmlPage page = webClient.getPage(BASE + "/index.html");
    HtmlForm dataForm = page.getForms().get(0);
    HtmlButtonInput sendMessageButton = dataForm.getInputByName("button");
    sendMessageButton.click();

    System.out.println(page.getElementById("div").getTextContent());

    server.stop();
  }
예제 #28
0
    /**
     * Creating two views with the same name.
     */
    @Email("http://d.hatena.ne.jp/ssogabe/20090101/1230744150")
    @Test public void conflictingName() throws Exception {
        assertNull(j.jenkins.getView("foo"));

        HtmlForm form = j.createWebClient().goTo("newView").getFormByName("createItem");
        form.getInputByName("name").setValueAttribute("foo");
        form.getRadioButtonsByName("mode").get(0).setChecked(true);
        j.submit(form);
        assertNotNull(j.jenkins.getView("foo"));

        // do it again and verify an error
        try {
            j.submit(form);
            fail("shouldn't be allowed to create two views of the same name.");
        } catch (FailingHttpStatusCodeException e) {
            assertEquals(400, e.getStatusCode());
        }
    }
예제 #29
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());
  }
  @Test
  public void testAll() throws Exception {
    HtmlPage page = (HtmlPage) this.client.getContentPage();

    try {
      // Welcome page

      assertTrue(page.asText().contains("Welcome to Forge"));

      // Create an Owner

      page = page.getAnchorByText("Owner").click();
      assertTrue(page.asText().contains("Search Owner entities"));
      page = page.getAnchorByText("Create New").click();

      HtmlForm form = page.getFormByName("create");
      assertTrue(page.asText().contains("Create a new Owner"));
      form.getInputByName("create:ownerBeanOwnerFirstName").setValueAttribute("Owner Firstname #1");
      form.getInputByName("create:ownerBeanOwnerLastName").setValueAttribute("Owner Lastname #1");
      page = page.getAnchorByText("Save").click();

      // Edit the Owner

      assertTrue(page.asText().contains("Search Owner entities"));
      HtmlTable table = (HtmlTable) page.getHtmlElementById("search:ownerBeanPageItems");
      assertEquals("Owner Firstname #1", table.getCellAt(1, 0).getTextContent());
      assertEquals("Owner Lastname #1", table.getCellAt(1, 1).getTextContent());

      page = page.getAnchorByText("Owner Firstname #1").click();
      assertTrue(page.asText().contains("View existing Owner"));
      assertEquals(
          "Owner Firstname #1",
          page.getHtmlElementById("ownerBeanOwnerFirstName").getTextContent());
      assertEquals(
          "Owner Lastname #1", page.getHtmlElementById("ownerBeanOwnerLastName").getTextContent());
      assertEquals("", page.getHtmlElementById("ownerBeanOwnerAddress").getTextContent());
      page = page.getAnchorByText("Edit").click();

      form = page.getFormByName("create");
      form.getInputByName("create:ownerBeanOwnerAddress").setValueAttribute("Owner Address #1");
      page = page.getAnchorByText("Save").click();
      assertTrue(page.asText().contains("View existing Owner"));
      assertEquals(
          "Owner Address #1", page.getHtmlElementById("ownerBeanOwnerAddress").getTextContent());

      page = page.getAnchorByText("View All").click();
      assertTrue(page.asText().contains("Search Owner entities"));

      // Create a Pet and associate it with the Owner

      page = page.getAnchorByText("Pet").click();
      assertTrue(page.asText().contains("Search Pet entities"));
      page = page.getAnchorByText("Create New").click();

      form = page.getFormByName("create");
      form.getInputByName("create:petBeanPetName").setValueAttribute("Pet #1");
      form.getInputByName("create:petBeanPetType").setValueAttribute("2");
      form.getInputByName("create:petBeanPetSendReminders").setChecked(true);
      form.getSelectByName("create:petBeanPetOwner").setSelectedAttribute("1", true);
      page = page.getAnchorByText("Save").click();

      // Click through from the Pet to the Owner

      table = (HtmlTable) page.getHtmlElementById("search:petBeanPageItems");
      assertEquals("Pet #1", table.getCellAt(1, 0).getTextContent());
      assertEquals("2", table.getCellAt(1, 1).getTextContent());
      DomNode booleanNode = table.getCellAt(1, 2).getChildNodes().get(0).getChildNodes().get(0);

      assertEquals("span", booleanNode.getNodeName());
      assertEquals("", booleanNode.getTextContent());
      assertEquals(
          "boolean-true", booleanNode.getAttributes().getNamedItem("class").getNodeValue());

      assertEquals(
          "Owner firstName: Owner Firstname #1, lastName: Owner Lastname #1, address: Owner Address #1",
          table.getCellAt(1, 3).getTextContent());

      page = page.getAnchorByText("Pet #1").click();
      assertTrue(page.asText().contains("View existing Pet"));
      page =
          page.getAnchorByText(
                  "Owner firstName: Owner Firstname #1, lastName: Owner Lastname #1, address: Owner Address #1")
              .click();
      assertTrue(page.asText().contains("View existing Owner"));

      // Create a new Owner

      page = page.getAnchorByText("Create New").click();
      form = page.getFormByName("create");
      form.getInputByName("create:ownerBeanOwnerFirstName").setValueAttribute("Owner Firstname #2");
      form.getInputByName("create:ownerBeanOwnerLastName").setValueAttribute("Owner Lastname #2");
      page = page.getAnchorByText("Save").click();

      table = (HtmlTable) page.getHtmlElementById("search:ownerBeanPageItems");
      assertEquals("Owner Firstname #1", table.getCellAt(1, 0).getTextContent());
      assertEquals("Owner Lastname #1", table.getCellAt(1, 1).getTextContent());
      assertEquals("Owner Firstname #2", table.getCellAt(2, 0).getTextContent());
      assertEquals("Owner Lastname #2", table.getCellAt(2, 1).getTextContent());

      // Search for a Pet by Owner

      page = page.getAnchorByText("Pet").click();
      assertTrue(page.asText().contains("Search Pet entities"));

      table = (HtmlTable) page.getHtmlElementById("search:petBeanPageItems");
      assertEquals("Pet #1", table.getCellAt(1, 0).getTextContent());

      form = page.getFormByName("search");
      form.getSelectByName("search:petBeanExampleOwner").setSelectedAttribute("3", true);
      page = page.getAnchorByText("Search").click();
      table = (HtmlTable) page.getHtmlElementById("search:petBeanPageItems");
      assertEquals("", table.getCellAt(1, 0).getTextContent());

      form = page.getFormByName("search");
      form.getSelectByName("search:petBeanExampleOwner").setSelectedAttribute("1", true);
      page = page.getAnchorByText("Search").click();
      page = page.getAnchorByText("Pet #1").click();

      // Delete a Pet

      assertTrue(page.asText().contains("View existing Pet"));
      page = page.getAnchorByText("Edit").click();
      assertTrue(page.asText().contains("Edit existing Pet"));
      page = page.getAnchorByText("Cancel").click();
      assertTrue(page.asText().contains("View existing Pet"));
      page = page.getAnchorByText("Edit").click();
      page = page.getAnchorByText("Delete").click();
      assertTrue(page.asText().contains("Search Pet entities"));
      table = (HtmlTable) page.getHtmlElementById("search:petBeanPageItems");
      assertEquals("", table.getCellAt(1, 0).getTextContent());
    } catch (Throwable t) {
      t.printStackTrace();
      throw new RuntimeException(t);
    } finally {
      System.out.println(page.asXml());
    }
  }