use of com.gargoylesoftware.htmlunit.html.HtmlFileInput in project faces by jakartaee.
the class Spec1555IT method testSingleSelection.
private void testSingleSelection(String form) throws Exception {
HtmlPage page = webClient.getPage(webUrl + "spec1555IT.xhtml");
HtmlFileInput input = page.getHtmlElementById(form + ":input");
assertEquals("Multiple attribute is NOT set", "", input.getAttribute("multiple"));
File file = generateTempFile("file", "bin", 123);
input.setValueAttribute(file.getAbsolutePath());
page = page.getHtmlElementById(form + ":submit").click();
assertEquals("Value attribute is NOT set", "", page.getHtmlElementById(form + ":input").getAttribute("value"));
HtmlElement messages = page.getHtmlElementById("messages");
assertEquals("There is 1 message", 1, messages.getChildElementCount());
DomElement message = messages.getChildElements().iterator().next();
assertEquals("Uploaded file has been received", "field: singleSelection, name: " + file.getName() + ", size: " + file.length(), message.asNormalizedText());
}
use of com.gargoylesoftware.htmlunit.html.HtmlFileInput in project faces by jakartaee.
the class Spec1555IT method addValueAttribute.
/**
* HtmlUnit's HtmlFileInput doesn't support submitting multiple values.
* The below is a work-around, found on https://stackoverflow.com/a/19654060
*/
private static void addValueAttribute(HtmlFileInput input, String valueAttribute) {
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute(null, null, "type", null, "file");
attributes.addAttribute(null, null, "name", null, input.getNameAttribute());
HtmlFileInput cloned = (HtmlFileInput) new HtmlUnitNekoHtmlParser().getFactory("input").createElementNS(input.getPage(), null, "input", attributes);
input.getParentNode().appendChild(cloned);
cloned.setValueAttribute(valueAttribute);
}
use of com.gargoylesoftware.htmlunit.html.HtmlFileInput in project faces by jakartaee.
the class Spec1556IT method testRenderingOfAcceptAttribute.
/**
* @see HtmlInputFile#getAccept()
* @see https://github.com/jakartaee/faces/issues/1556
*/
@Test
public void testRenderingOfAcceptAttribute(String form) throws Exception {
HtmlPage page = webClient.getPage(webUrl + "spec1556IT.xhtml");
HtmlFileInput inputFileWithoutAccept = page.getHtmlElementById("form:inputFileWithoutAccept");
assertEquals("Unspecified 'accept' attribute on h:inputFile is NOT rendered", "", inputFileWithoutAccept.getAttribute("accept"));
HtmlFileInput inputFileWithAccept = page.getHtmlElementById("form:inputFileWithAccept");
assertEquals("Specified 'accept' attribute on h:inputFile is rendered", "image/*", inputFileWithAccept.getAttribute("accept"));
// It's for Mojarra also explicitly tested on h:inputText because they share the same renderer.
HtmlTextInput inputTextWithoutAccept = page.getHtmlElementById("form:inputTextWithoutAccept");
assertEquals("Unspecified 'accept' attribute on h:inputText is NOT rendered", "", inputTextWithoutAccept.getAttribute("accept"));
HtmlTextInput inputTextWithAccept = page.getHtmlElementById("form:inputTextWithAccept");
assertEquals("Specified 'accept' attribute on h:inputText is NOT rendered", "", inputTextWithAccept.getAttribute("accept"));
// NOTE: HtmlUnit doesn't support filtering files by accept attribute. So the upload part is not tested to keep it simple (it's nonetheless already tested in Spec1555IT).
}
use of com.gargoylesoftware.htmlunit.html.HtmlFileInput in project htmlunit by HtmlUnit.
the class HTMLInputElement method getFiles.
/**
* Returns the {@code files} property.
* @return the {@code files} property
*/
@JsxGetter
public Object getFiles() {
final HtmlInput htmlInput = getDomNodeOrDie();
if (htmlInput instanceof HtmlFileInput) {
final FileList list = new FileList(((HtmlFileInput) htmlInput).getFiles());
list.setParentScope(getParentScope());
list.setPrototype(getPrototype(list.getClass()));
return list;
}
if (getBrowserVersion().hasFeature(HTMLINPUT_FILES_UNDEFINED)) {
return Undefined.instance;
}
return null;
}
use of com.gargoylesoftware.htmlunit.html.HtmlFileInput in project htmlunit by HtmlUnit.
the class HTMLFormElement2Test method fileInput_fireOnChange.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("onchange")
public void fileInput_fireOnChange() throws Exception {
final String html = "<html><body>\n" + "<form>\n" + " <input type='file' name='myFile' id='myFile' onchange='alert(\"onchange\")'/>\n" + "</form>\n" + "</body></html>";
final List<String> collectedAlerts = new ArrayList<>();
final HtmlPage page = loadPage(html, collectedAlerts);
final HtmlFileInput fileInput = page.getHtmlElementById("myFile");
fileInput.focus();
fileInput.setAttribute("value", "dummy.txt");
assertEquals(getExpectedAlerts(), collectedAlerts);
}
Aggregations