當前位置: 首頁>>代碼示例>>Java>>正文


Java HtmlForm類代碼示例

本文整理匯總了Java中com.gargoylesoftware.htmlunit.html.HtmlForm的典型用法代碼示例。如果您正苦於以下問題:Java HtmlForm類的具體用法?Java HtmlForm怎麽用?Java HtmlForm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HtmlForm類屬於com.gargoylesoftware.htmlunit.html包,在下文中一共展示了HtmlForm類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCreateNewDatastream

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
@Test
@Ignore("The htmlunit web client can't handle the HTML5 file API")
public void testCreateNewDatastream() throws IOException {

    final String pid = randomUUID().toString();

    // can't do this with javascript, because HTMLUnit doesn't speak the HTML5 file api
    final HtmlPage page = webClient.getPage(serverAddress);
    final HtmlForm form = (HtmlForm)page.getElementById("action_create");

    final HtmlInput slug = form.getInputByName("slug");
    slug.setValueAttribute(pid);

    final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
    type.getOptionByValue("binary").setSelected(true);

    final HtmlFileInput fileInput = (HtmlFileInput)page.getElementById("datastream_payload");
    fileInput.setData("abcdef".getBytes());
    fileInput.setContentType("application/pdf");

    final HtmlButton button = form.getFirstByXPath("button");
    button.click();

    final HtmlPage page1 = javascriptlessWebClient.getPage(serverAddress + pid);
    assertEquals(serverAddress + pid, page1.getTitleText());
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:27,代碼來源:FedoraHtmlResponsesIT.java

示例2: mockLogin

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
public String mockLogin(URL url, String username, String password) {
	try {
		HtmlPage page1 = webClient.getPage(url.getURLValue());  
		// find the login form
        HtmlForm form = page1.getForms().get(0);  
        
        // fill in the input
        HtmlInput hi = form.getInputByName("commit");
        HtmlTextInput textField = form.getInputByName("login");  
        HtmlPasswordInput pass = form.getInputByName("password");  
        
        textField.click();
        textField.setValueAttribute(username);  
        pass.click();
        pass.setValueAttribute(password);  
      
        // push the button
        HtmlPage page2 = hi.click();  
        return page2.asXml();

	} catch(IOException ioe)  {
		ioe.printStackTrace();
		return null;
	}
}
 
開發者ID:knshen,項目名稱:JSearcher,代碼行數:26,代碼來源:GithubLoginSimulator.java

示例3: editWikiPage

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
protected HtmlPage editWikiPage(/* mutable */ HtmlPage page, final String content, final String attributes, final String descriptionOfChange, final Boolean isNew) throws Exception {
  URL pageUrl = page.getWebResponse().getWebRequest().getUrl();
  final String newSign = isNew != null && isNew ? " - New" : "";
  if (isNew != null) {
    assertMatches("test - [A-Z].*?" + newSign, page.getTitleText());
  }
  page = clickEditLink(page);
  if (isNew != null) {
    assertMatches("test - [*][A-Z].*?" + newSign, page.getTitleText());
  }
  HtmlForm editForm = page.getFormByName("editForm");
  editForm.getTextAreaByName("content").setText(content == null ? "" : content);
  editForm.getTextAreaByName("attributes").setText(attributes == null ? "" : attributes);
  editForm.getInputByName("description").setValueAttribute(descriptionOfChange == null ? "" : descriptionOfChange);
  page = (HtmlPage) editForm.getButtonByName("save").click();

  @SuppressWarnings("unchecked")
  final List<HtmlInput> saveButtons = (List<HtmlInput>) page.getByXPath("//input[@type='submit' and @value='Save']");
  assertEquals(0, saveButtons.size());

  assertURL(pageUrl, page.getWebResponse().getWebRequest().getUrl());
  return page;
}
 
開發者ID:CoreFiling,項目名稱:reviki,代碼行數:24,代碼來源:WebTestSupport.java

示例4: testFormOk

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
/**
 * Retrieve a form and submit it making sure the CSRF hidden field is present
 *
 * @throws Exception an error occurs or validation fails.
 */
@Test
public void testFormOk() throws Exception {
    HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf");
    HtmlForm form = (HtmlForm) page1.getDocumentElement().getHtmlElementsByTagName("form").get(0);

    // Check hidden input field
    HtmlElement input = form.getHtmlElementsByTagName("input").get(1);
    assertTrue(input.getAttribute("type").equals("hidden"));
    assertTrue(input.getAttribute("name").equals(CSRF_PARAM));
    assertTrue(input.hasAttribute("value"));        // token

    // Submit form
    HtmlSubmitInput button = (HtmlSubmitInput) form.getHtmlElementsByTagName("input").get(0);
    HtmlPage page2 = button.click();
    Iterator<HtmlElement> it = page2.getDocumentElement().getHtmlElementsByTagName("h1").iterator();
    assertTrue(it.next().asText().contains("CSRF Protection OK"));
}
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:23,代碼來源:CsrfIT.java

示例5: testFormFail

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
/**
 * Retrieves a form, removes CSRF hidden field and attempts to submit. Should
 * result in a 403 error.
 *
 * @throws Exception an error occurs or validation fails.
 */
@Test
public void testFormFail() throws Exception {
    HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf");
    HtmlForm form = (HtmlForm) page1.getDocumentElement().getHtmlElementsByTagName("form").get(0);

    // Remove hidden input field to cause a CSRF validation failure
    HtmlElement input = form.getHtmlElementsByTagName("input").get(1);
    form.removeChild(input);

    // Submit form - should fail
    HtmlSubmitInput button = (HtmlSubmitInput) form.getHtmlElementsByTagName("input").get(0);
    try {
        button.click();
        fail("CSRF validation should have failed!");
    } catch (FailingHttpStatusCodeException e) {
        // falls through
    }
}
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:25,代碼來源:CsrfIT.java

示例6: getCallbackUrl

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
@Override
protected String getCallbackUrl(HtmlPage authorizationPage) throws Exception {

    HtmlInlineFrame frame = (HtmlInlineFrame) authorizationPage.getElementById("ptlogin_iframe");
    // log.info("------------------------###\n{}------------------------===\n", authorizationPage.asXml());
    HtmlPage loginPage = (HtmlPage) frame.getEnclosedPage();

    log.info("------------------------###\n{}------------------------===\n", loginPage.getUrl().toString());

    HtmlAnchor passwordLogin = (HtmlAnchor) loginPage.getElementById("switcher_plogin");
    passwordLogin.click();

    HtmlForm loginForm = loginPage.getFormByName("loginform");
    loginForm.getInputByName("u").setValueAttribute(USER_QQ);
    loginForm.getInputByName("p").setValueAttribute(USER_PASSWORD);
    HtmlSubmitInput button = (HtmlSubmitInput) loginPage.getElementById("login_button");
    HtmlPage page2 = button.click();
    page2 = button.click();
    log.info(
            "------------------------###\n callbackUrl : {}------------------------===\n{}[email protected]@@@\n",
            page2.getUrl().toString(), page2.asXml());
    return page2.getUrl().toString();
}
 
開發者ID:btpka3,項目名稱:pac4j-oauth-tencent,代碼行數:24,代碼來源:TestTencentClient.java

示例7: testConfigRoundtrip

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
public void testConfigRoundtrip() throws Exception {
    AmazonEC2Cloud orig = new AmazonEC2Cloud("us-east-1", true, "abc", "def", "us-east-1",
            "ghi", "3", Collections.<SlaveTemplate>emptyList());
    hudson.clouds.add(orig);
    WebClient wc = createWebClient();
    wc.setThrowExceptionOnScriptError(false); 
    wc.setThrowExceptionOnFailingAjax(false); 
    wc.setThrowExceptionOnFailingStatusCode(false); 
    HtmlPage page = wc.goTo("configure");
    HtmlForm form = page.getFormByName("config");
    Page result = form.submit(null);

    //submit(createWebClient().goTo("configure").getFormByName("config"));
    assertEqualBeans(orig, hudson.clouds.iterator().next(),
            "cloudName,region,useInstanceProfileForCredentials,accessId,secretKey,privateKey,instanceCap");
}
 
開發者ID:hudson3-plugins,項目名稱:ec2-plugin,代碼行數:17,代碼來源:AmazonEC2CloudTest.java

示例8: loadPage

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
public void loadPage() {
	try {
		// Store cookies
		cookieManager = webClient.getCookieManager();
		page = webClient.getPage(URL);

		HtmlForm form = page.getFormByName("processLogonForm");
		HtmlSubmitInput button = form.getInputByName("Login");
		HtmlTextInput user = form.getInputByName("userName");
		HtmlPasswordInput pass = form.getInputByName("password");

		user.setValueAttribute(username);
		pass.setValueAttribute(password);

		page = button.click();
		if (page.asXml().contains("*  Please try again.")) {
			loginSuc = false;
			return;
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:zeshan321,項目名稱:Project-D2L,代碼行數:24,代碼來源:D2LHook.java

示例9: testPreviewDiffBug

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
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.getButtonByName("preview").click();
  
  form = editPage.getFormByName(ID_EDIT_FORM);
  contentArea = form.getTextAreaByName("content");
  assertEquals(newContent + NEWLINE_TEXTAREA, contentArea.getText());
}
 
開發者ID:CoreFiling,項目名稱:reviki,代碼行數:20,代碼來源:TestEditing.java

示例10: testPreviewWithChangedAttributes

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
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.getButtonByName("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());
}
 
開發者ID:CoreFiling,項目名稱:reviki,代碼行數:23,代碼來源:TestEditing.java

示例11: testInvalidSessionIdHelper

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
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.getButtonByName(button).click();

  try {
    getAnchorByHrefContains(editPage, expectedContent);
    fail(failMsg);
  }
  catch (NoSuchElementException e) {
  }
}
 
開發者ID:CoreFiling,項目名稱:reviki,代碼行數:22,代碼來源:TestEditing.java

示例12: testUploadAndDownloadAttachment

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
public void testUploadAndDownloadAttachment() throws Exception {
  String name = uniqueWikiPageName("AttachmentsTest");
  HtmlPage page = editWikiPage(name, "Content", "", "", true);
  HtmlPage attachments = uploadAttachment(ATTACHMENT_UPLOAD_FILE_1, name);
  assertEquals("File 1.", getTextAttachmentAtEndOfLink(getAnchorByHrefContains(attachments, "file.txt")));

  // A link should have been added to the page.
  page = getWikiPage(name);
  assertEquals("File 1.", getTextAttachmentAtEndOfLink(getAnchorByHrefContains(page, "/attachments/file.txt")));

  attachments = clickAttachmentsLink(page, name);
  HtmlForm form = attachments.getFormByName("replaceAttachmentUpload");
  form.getInputByName("file").setValueAttribute(ATTACHMENT_UPLOAD_FILE_2);
  attachments = (HtmlPage) form.getInputByValue("Upload").click();
  assertEquals("File 2.", getTextAttachmentAtEndOfLink(getAnchorByHrefContains(page, "/attachments/file.txt")));

  HtmlAnchor previousRevision = (HtmlAnchor) attachments.getByXPath("//a[contains(@href, '?revision')]").get(0);
  assertEquals("File 1.", getTextAttachmentAtEndOfLink(previousRevision));
}
 
開發者ID:CoreFiling,項目名稱:reviki,代碼行數:20,代碼來源:TestAttachments.java

示例13: testUploadAndDeleteAttachment

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
public void testUploadAndDeleteAttachment() throws Exception {
  String name = uniqueWikiPageName("AttachmentsTest");
  HtmlPage page = editWikiPage(name, "Content", "", "", true);
  HtmlPage attachments = uploadAttachment(ATTACHMENT_UPLOAD_FILE_1, name);
  assertEquals("File 1.", getTextAttachmentAtEndOfLink(getAnchorByHrefContains(attachments, "file.txt")));

  page = getWikiPage(name);
  attachments = clickAttachmentsLink(page, name);
  HtmlForm deleteForm = attachments.getFormByName("deleteAttachment");
  attachments = deleteForm.getButtonByName("delete").click();

  // There shouldn't be any link directly to the attachment
  for(Object o: attachments.getByXPath("//a[contains(@href, 'file.txt')]")) {
    HtmlAnchor anchor = (HtmlAnchor) o;
    assertEquals(true, anchor.getHrefAttribute().contains("?revision"));
  }

  // Previous version should still be available
  HtmlAnchor previousRevision = (HtmlAnchor) attachments.getByXPath("//a[contains(@href, '?revision')]").get(0);
  assertEquals("File 1.", getTextAttachmentAtEndOfLink(previousRevision));
}
 
開發者ID:CoreFiling,項目名稱:reviki,代碼行數:22,代碼來源:TestAttachments.java

示例14: testErrorMessages

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
@Test
public void testErrorMessages() throws Exception {
  	String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL;
  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
  	Assert.assertNotNull(page);
 
  	HtmlForm form = page.getFormByName("KualiForm");
  	Assert.assertNotNull("Search form was missing from page.", form);
  	HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "System Scheduled Time Off - test");
  	// use past dates
    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2011");
    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.accruedDate", "04/01/2011");
    HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.scheduledTimeOffDate", "04/01/2011");
  	
  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
  	Assert.assertNotNull("Could not locate submit button", input);
  	HtmlElement element = page.getElementByName("methodToCall.route");
  	page = element.click();
  	Assert.assertTrue("page text does not contain:\n" + HrTestConstants.EFFECTIVE_DATE_ERROR, page.asText().contains(HrTestConstants.EFFECTIVE_DATE_ERROR));
  	Assert.assertTrue("page text does not contain:\n" + ACCRUED_DATE_PAST_ERROR, page.asText().contains(ACCRUED_DATE_PAST_ERROR));
  	Assert.assertTrue("page text does not contain:\n" + SCHEDULED_TO_DATE_PAST_ERROR, page.asText().contains(SCHEDULED_TO_DATE_PAST_ERROR));
}
 
開發者ID:kuali-mirror,項目名稱:kpme,代碼行數:23,代碼來源:SystemScheduledTimeOffMaintTest.java

示例15: testValidateLeaveCode

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入依賴的package包/類
@Test
//test for jiar1363
public void testValidateLeaveCode() throws Exception {
  	String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL;
  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
  	Assert.assertNotNull(page);
 
  	HtmlForm form = page.getFormByName("KualiForm");
  	Assert.assertNotNull("Search form was missing from page.", form); 	
  	
  	// add 150 days in the future, need to add dates instead of month 
  	// because if we happen to be running the test on the 31 of a month, some future months do not have 31st
  	LocalDate validDate = LocalDate.now().plusDays(150);
  	String validDateString = TKUtils.formatDate(validDate);
  	
  	HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", validDateString);
  	HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.earnCode", "testLCL"); 
    
    page = ((HtmlElement)page.getElementByName("methodToCall.route")).click();
    HtmlUnitUtil.createTempFile(page);
    Assert.assertTrue("page text does not contain:\n" + ERROR_LEAVE_CODE, page.asText().contains(ERROR_LEAVE_CODE));
}
 
開發者ID:kuali-mirror,項目名稱:kpme,代碼行數:23,代碼來源:SystemScheduledTimeOffMaintTest.java


注:本文中的com.gargoylesoftware.htmlunit.html.HtmlForm類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。