Search in sources :

Example 6 with HtmlLabel

use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project security by jakartaee.

the class BaseHtmlUnitClient method getLabelsContaining.

/**
 * In a given htmlpage(root) look for and return the children label elements
 * that contain a given string.
 *
 * @param root
 *          - the HtmlPage to search.
 * @param myLabel
 *          - The contents on which to search for.
 *
 * @return - A List of HtmlLabels.
 */
protected List<HtmlLabel> getLabelsContaining(HtmlPage root, String myLabel) {
    List<HtmlLabel> result = new ArrayList<HtmlLabel>();
    List<HtmlLabel> labels = root.getDocumentElement().getHtmlElementsByTagName("label");
    for (HtmlLabel label : labels) {
        if (label.asText().contains(myLabel)) {
            result.add(label);
        }
    }
    if ((result.size() == 0)) {
        result = null;
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel)

Example 7 with HtmlLabel

use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project jenkins by jenkinsci.

the class ViewTest method testGetProperties.

@Test
public void testGetProperties() throws Exception {
    View view = listView("foo");
    Thread.sleep(100000);
    HtmlForm f = j.createWebClient().getPage(view, "configure").getFormByName("viewConfig");
    ((HtmlLabel) DomNodeUtil.selectSingleNode(f, ".//LABEL[text()='Test property']")).click();
    j.submit(f);
    assertNotNull("View should contain ViewPropertyImpl property.", view.getProperties().get(PropertyImpl.class));
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel) Test(org.junit.Test)

Example 8 with HtmlLabel

use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project faces by jakartaee.

the class BaseHtmlUnitClient method getLabelsContaining.

/**
 * In a given htmlpage(root) look for and return the children label elements
 * that contain a given string.
 *
 * @param root
 *          - the HtmlPage to search.
 * @param myLabel
 *          - The contents on which to search for.
 *
 * @return - A List of HtmlLabels.
 */
protected List<HtmlLabel> getLabelsContaining(HtmlPage root, String myLabel) {
    List<HtmlLabel> result = new ArrayList<HtmlLabel>();
    List<HtmlLabel> labels = root.getDocumentElement().getHtmlElementsByTagName("label");
    for (HtmlLabel label : labels) {
        if (label.asText().contains(myLabel)) {
            result.add(label);
        }
    }
    if ((result.size() == 0)) {
        result = null;
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel)

Example 9 with HtmlLabel

use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project faces by jakartaee.

the class Spec1238IT method testSearchExpression.

public void testSearchExpression() throws Exception {
    HtmlPage page = webClient.getPage(webUrl + "spec1238.xhtml");
    webClient.waitForBackgroundJavaScript(60000);
    HtmlLabel label = (HtmlLabel) page.getHtmlElementById("label");
    HtmlTextInput input = (HtmlTextInput) page.getHtmlElementById("input");
    Assert.assertEquals(label.getAttribute("for"), input.getId());
    Assert.assertTrue(input.getAttribute("onchange").contains("@this input2"));
}
Also used : HtmlTextInput(com.gargoylesoftware.htmlunit.html.HtmlTextInput) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel)

Example 10 with HtmlLabel

use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project faces by jakartaee.

the class URLClient method manycheckboxRenderEncodeTest.

/*
   * @class.setup_props: webServerHost; webServerPort; ts_home;
   */
/**
 * @testName: manycheckboxRenderEncodeTest
 *
 * @assertion_ids: PENDING
 *
 * @test_Strategy: Validate the rendering of jakarta.faces.SelectMany.Checkbox
 *                 case 1: - Only the id attribute is defined and two
 *                 checkboxes. Verify that - the correct number of checkboxes
 *                 are rendered - none of the checkboxes are checked - the
 *                 value attributes for each option are correctly rendered.
 *                 case 2: - Attributes for id, enabledClass, and
 *                 disabledClass are defined. Verify that - each option is
 *                 rendered as enabled or disabled as appropriate, and - each
 *                 option is rendered with the correct style class. case 3: -
 *                 Attributes for id, value, and class are defined. case 4,5:
 *                 - ensure the disabled attribute is handled using html
 *                 attribute minimization (only the attribute name is rendered
 *                 when value is true, and nothing rendered when false) case
 *                 6,7: - ensure the readonly attribute is handled using html
 *                 attribute minimization (only the attribute name is rendered
 *                 when value is true, and nothing rendered when false) case
 *                 8,9,10: - Ensure that the layout attribute is handled
 *                 correctly. When not specified make sure the checkboxes are
 *                 going horizontally. Then test for the two expected values.
 *                 pageDirection(vertically) or lineDirection(horizontally).
 *                 case 11: - Ensure that the border attribute is rendered
 *                 correctly in the checkboxes enclosing "
 *                 <Table>
 *                 " element. case 12: - Unsure that the following is Render
 *                 correctly when using the binding attribute. - the correct
 *                 number of checkboxes are rendered - none of the checkboxes
 *                 are checked - the value attributes for each option are
 *                 correctly rendered.
 *
 * @since 1.2
 */
public void manycheckboxRenderEncodeTest() throws Fault {
    StringBuilder messages = new StringBuilder(128);
    Formatter formatter = new Formatter(messages);
    HtmlPage page = getPage(CONTEXT_ROOT + "/faces/encodetest.xhtml");
    // ----------------------------------------------------------- checkbox1
    HtmlInput checkbox10 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox1:0");
    HtmlInput checkbox11 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox1:1");
    // Validate checkbox10 & checkbox11
    if (!validateExistence(checkbox10.getId(), "input", checkbox10, formatter) && !validateExistence(checkbox11.getId(), "input", checkbox11, formatter)) {
        handleTestStatus(messages);
        return;
    }
    // Make sure no checkbox buttons are checked
    String[] inputedOptions = { checkbox10.getCheckedAttribute(), checkbox11.getCheckedAttribute() };
    for (int ii = 0; ii < inputedOptions.length; ii++) {
        if (inputedOptions[ii].equals("checked")) {
            String failedbutton = "checkbox" + ii;
            formatter.format("checkbox button should not be checked " + failedbutton);
            handleTestStatus(messages);
            return;
        }
    }
    // Test value attribute for checkbox10
    if (!"true".equals(checkbox10.getValueAttribute())) {
        formatter.format("Expected the value attribute of checkbox '%s', " + "to be '%s', but instead found '%s'", checkbox10.getId(), "true", checkbox10.getValueAttribute());
    }
    // Test value attribute for checkbox11
    if (!"false".equals(checkbox11.getValueAttribute())) {
        formatter.format("Expected the value attribute of checkbox '%s' " + "to be '%s', but instead found '%s'", checkbox11.getId(), "true", checkbox11.getValueAttribute());
    }
    // ----------------------------------------------------------- checkbox2
    HtmlInput checkbox20 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox2:0");
    HtmlInput checkbox21 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox2:1");
    if (!validateExistence(checkbox20.getId(), "input", checkbox20, formatter) && !validateExistence(checkbox21.getId(), "input", checkbox21, formatter)) {
        handleTestStatus(messages);
        return;
    }
    // Get the labels for checkboxes 2:0 & 2:1 for testing class att.
    HtmlLabel label20 = (HtmlLabel) getLabelIncludingFor(page, "label", checkbox20.getId());
    HtmlLabel label21 = (HtmlLabel) getLabelIncludingFor(page, "label", checkbox21.getId());
    if (!checkbox20.isDisabled()) {
        formatter.format("Expected checkbox '%s', to be '%s'", checkbox20.getId(), "disabled");
    }
    if (!"Color: red;".equals(label20.getAttribute("class"))) {
        formatter.format("Expected the value of the class attribute for" + "'%s, to be '%s', but instead found '%s'", checkbox20.getId(), "Color: red;", checkbox20.getAttribute("class"));
    }
    if (checkbox21.isDisabled()) {
        formatter.format("Expected checkbox '%s', to be '%s'", checkbox21.getId(), "enabled");
    }
    if (!"text".equals(label21.getAttribute("class"))) {
        formatter.format("Expected the value of the class attribute for" + " checkbox '%s', to be '%s', but instead found '%s'", checkbox21.getId(), "text", checkbox21.getAttribute("class"));
    }
    // ----------------------------------------------------------- checkbox3
    HtmlInput checkbox30 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox3:0");
    // Get the parent table element, it holds the classstyle attibute.
    HtmlTable parent30 = (HtmlTable) checkbox30.getEnclosingElement("table");
    if (!validateExistence(checkbox30.getId(), "input", checkbox30, formatter)) {
        handleTestStatus(messages);
        return;
    }
    if (!"text".equals(parent30.getAttribute("class"))) {
        formatter.format("Expected the rendered value of the class " + "attribute to be '%s', for the enclosing table element of " + " checkbox '%s', but instead found '%s'.%n", "text", checkbox30.getId(), parent30.getAttribute("class"));
    }
    // ----------------------------------------------------------- checkbox4
    HtmlInput checkbox40 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox4:0");
    if (!validateExistence(checkbox40.getId(), "input", checkbox40, formatter)) {
        handleTestStatus(messages);
        return;
    }
    if (!"disabled".equals(checkbox40.getDisabledAttribute())) {
        formatter.format("(checkbox40) Expected the disabled attribute " + "for checkbox '%s', to be rendered as '%s', instead " + "found '%s'.%n", checkbox40.getId(), "disabled", checkbox40.getDisabledAttribute());
    }
    // ----------------------------------------------------------- checkbox5
    HtmlInput checkbox50 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox5:0");
    if (!validateExistence(checkbox50.getId(), "input", checkbox50, formatter)) {
        handleTestStatus(messages);
        return;
    }
    if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(checkbox50.getDisabledAttribute())) {
        formatter.format("(checkbox50) Expected the disabled attribute " + "for checkbox '%s', not to be rendered when the disabled " + "attribute was specified as false in the JSP%n.", checkbox50.getId());
    }
    // ----------------------------------------------------------- checkbox6
    HtmlInput checkbox60 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox6:0");
    if (!validateExistence(checkbox60.getId(), "input", checkbox60, formatter)) {
        handleTestStatus(messages);
        return;
    }
    if (!"readonly".equals(checkbox60.getAttribute("readonly"))) {
        formatter.format("Expected the readonly attribute for checkbox " + "'%s', to be rendered as '%s', instead found '%s' %n.", checkbox60.getId(), "readonly", checkbox60.getAttribute("readonly"));
    }
    // ----------------------------------------------------------- checkbox7
    HtmlInput checkbox70 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox7:0");
    if (!validateExistence(checkbox70.getId(), "input", checkbox70, formatter)) {
        handleTestStatus(messages);
        return;
    }
    if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(checkbox70.getAttribute("readonly"))) {
        formatter.format("Expected the readonly attribute for checkbox " + "'%s', not to be rendered when the readonly attribute " + "was specified as false in the JSP %n.", checkbox60.getId());
    }
    // ----------------------------------------------------------- checkbox8
    HtmlInput checkbox80 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox8:0");
    // Get the Enclosing Table Row.
    HtmlTableRow tablerow80 = (HtmlTableRow) checkbox80.getEnclosingElement("tr");
    if (!validateExistence(checkbox80.getId(), "input", checkbox80, formatter)) {
        handleTestStatus(messages);
        return;
    }
    // Validate the default layout will be horizontal.
    if (!(2 == tablerow80.getCells().size())) {
        formatter.format("Expected the default layout(horizontal) of the " + "checkboxes in checkbox '%s', for this you need more" + " then one cell <td></td> per table row. %n", checkbox80.getId());
    }
    // ----------------------------------------------------------- checkbox9
    HtmlInput checkbox90 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox9:0");
    // Get the Enclosing Table Row.
    HtmlTableRow tablerow90 = (HtmlTableRow) checkbox90.getEnclosingElement("tr");
    if (!validateExistence(checkbox90.getId(), "input", checkbox90, formatter)) {
        handleTestStatus(messages);
        return;
    }
    // Validate the default layout will be horizontal.
    if (!(2 == tablerow90.getCells().size())) {
        formatter.format("Expected the default layout(horizontal) of the " + "checkboxes in checkbox '%s', for this you need more" + " then one cell <td></td> per table row. %n", checkbox90.getId());
    }
    // ---------------------------------------------------------- checkbox10
    HtmlInput checkbox100 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox10:0");
    // Get the Enclosing Table Row.
    HtmlTableRow tablerow100 = (HtmlTableRow) checkbox100.getEnclosingElement("tr");
    if (!validateExistence(checkbox100.getId(), "input", checkbox100, formatter)) {
        handleTestStatus(messages);
        return;
    }
    // Validate the layout will be vertical.
    if (!(1 == tablerow100.getCells().size())) {
        int realcell100 = tablerow100.getCells().size();
        formatter.format("(checkbox100) Expected vertical layout of the " + "checkboxes there should have been only one cell " + "<td></td> per table row. %n" + "REALLY HAVE: " + realcell100);
    }
    // ---------------------------------------------------------- checkbox11
    HtmlInput checkbox110 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox11:0");
    // Get the Enclosing Table Row.
    HtmlTable table110 = (HtmlTable) checkbox110.getEnclosingElement("table");
    if (!validateExistence(checkbox110.getId(), "input", checkbox110, formatter)) {
        handleTestStatus(messages);
        return;
    }
    // Validate the border attribute
    int bwidth = 11;
    if (bwidth != Integer.parseInt(table110.getBorderAttribute())) {
        formatter.format("(checkbox110) Expected default layout" + "(horizontal) of the checkboxes there should have been " + "more then one cell <td></td> per table row. %n");
    }
    // ---------------------------------------------------------- checkbox12
    HtmlInput checkbox120 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox12:0");
    HtmlInput checkbox121 = (HtmlInput) getElementOfTypeIncludingId(page, "input", "form:checkbox12:1");
    // Validate checkbox120 & checkbox121
    if (!validateExistence(checkbox120.getId(), "input", checkbox120, formatter) && !validateExistence(checkbox121.getId(), "input", checkbox121, formatter)) {
        handleTestStatus(messages);
        return;
    }
    // Make sure no checkbox buttons are checked
    String[] isSelected = { checkbox120.getCheckedAttribute(), checkbox121.getCheckedAttribute() };
    for (int ii = 0; ii < isSelected.length; ii++) {
        if (isSelected[ii].equals("checked")) {
            String failedbutton = "checkbox" + ii;
            formatter.format("checkbox button should not be checked " + failedbutton);
            handleTestStatus(messages);
            return;
        }
    }
    // Test value attribute for checkbox120
    if (!"no".equals(checkbox120.getValueAttribute())) {
        formatter.format("Unexpected value for the 'value' attribute of " + "ManyCheckbox '%s'. %n" + "Expected: '%s' %n" + "Received: '%s' %n", checkbox120.getId(), "no", checkbox120.getValueAttribute());
    }
    // Test value attribute for checkbox121
    if (!"yes".equals(checkbox121.getValueAttribute())) {
        formatter.format("Unexpected value for the 'value' attribute of " + "ManyCheckbox '%s'. %n" + "Expected: '%s' %n" + "Received: '%s' %n", checkbox121.getId(), "yes", checkbox121.getValueAttribute());
    }
    handleTestStatus(messages);
}
Also used : HtmlTableRow(com.gargoylesoftware.htmlunit.html.HtmlTableRow) HtmlTable(com.gargoylesoftware.htmlunit.html.HtmlTable) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Formatter(java.util.Formatter) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel)

Aggregations

HtmlLabel (com.gargoylesoftware.htmlunit.html.HtmlLabel)19 ArrayList (java.util.ArrayList)9 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)6 Formatter (java.util.Formatter)5 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)4 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)3 Test (org.junit.Test)3 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)2 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)2 HtmlTable (com.gargoylesoftware.htmlunit.html.HtmlTable)2 HtmlTableRow (com.gargoylesoftware.htmlunit.html.HtmlTableRow)2 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ScriptResult (com.gargoylesoftware.htmlunit.ScriptResult)1 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)1 Window (com.gargoylesoftware.htmlunit.javascript.host.Window)1 Document (com.gargoylesoftware.htmlunit.javascript.host.dom.Document)1 IOException (java.io.IOException)1