com.gargoylesoftware.htmlunit.html.HtmlTable Java Examples

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlTable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HTMLTableRowElement.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the index of the row within the enclosing thead, tbody or tfoot.
 * @return the index of the row within the enclosing thead, tbody or tfoot
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms534621.aspx">MSDN Documentation</a>
 * @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-79105901">
 * DOM Level 1</a>
 */
@JsxGetter
public int getSectionRowIndex() {
    DomNode row = getDomNodeOrDie();
    final HtmlTable table = ((HtmlTableRow) row).getEnclosingTable();
    if (table == null) { // a not attached document.createElement('TR')
        return -1;
    }
    int index = -1;
    while (row != null) {
        if (row instanceof HtmlTableRow) {
            index++;
        }
        row = row.getPreviousSibling();
    }
    return index;
}
 
Example #2
Source File: HTMLTableRowElement.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the index of the row within the enclosing thead, tbody or tfoot.
 * @return the index of the row within the enclosing thead, tbody or tfoot
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms534621.aspx">MSDN Documentation</a>
 * @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-79105901">
 * DOM Level 1</a>
 */
@JsxGetter
public int getSectionRowIndex() {
    DomNode row = getDomNodeOrDie();
    final HtmlTable table = ((HtmlTableRow) row).getEnclosingTable();
    if (table == null) { // a not attached document.createElement('TR')
        return -1;
    }
    int index = -1;
    while (row != null) {
        if (row instanceof HtmlTableRow) {
            index++;
        }
        row = row.getPreviousSibling();
    }
    return index;
}
 
Example #3
Source File: PropertyTable.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a new instance of {@link PropertyTable}.
 *
 * @param page
 *         the whole details HTML page
 * @param property
 *         the property tab to extract
 */
@SuppressFBWarnings("BC")
public PropertyTable(final HtmlPage page, final String property) {
    super(page);

    title = getTitleOfTable(page, property);

    DomElement propertyElement = page.getElementById(property);
    assertThat(propertyElement).isInstanceOf(HtmlTable.class);

    HtmlTable table = (HtmlTable) propertyElement;
    List<HtmlTableRow> tableHeaderRows = table.getHeader().getRows();
    assertThat(tableHeaderRows).hasSize(1);

    HtmlTableRow header = tableHeaderRows.get(0);
    List<HtmlTableCell> cells = header.getCells();
    assertThat(cells).hasSize(3);

    propertyName = cells.get(0).getTextContent();
    assertThat(cells.get(1).getTextContent()).isEqualTo("Total");
    assertThat(cells.get(2).getTextContent()).isEqualTo("Distribution");

    List<HtmlTableBody> bodies = table.getBodies();
    assertThat(bodies).hasSize(1);
    List<HtmlTableRow> contentRows = bodies.get(0).getRows();

    for (HtmlTableRow row : contentRows) {
        List<HtmlTableCell> rowCells = row.getCells();
        rows.add(new PropertyRow(rowCells));
    }
}
 
Example #4
Source File: HTMLTableRowElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of the row within the parent table.
 * @return the index of the row within the parent table
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms534377.aspx">MSDN Documentation</a>
 */
@JsxGetter
public int getRowIndex() {
    final HtmlTableRow row = (HtmlTableRow) getDomNodeOrDie();
    final HtmlTable table = row.getEnclosingTable();
    if (table == null) { // a not attached document.createElement('TR')
        return -1;
    }
    return table.getRows().indexOf(row);
}
 
Example #5
Source File: HTMLTableElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the tbody's in the table.
 * @return the tbody's in the table
 */
@JsxGetter
public Object getTBodies() {
    final HtmlTable table = (HtmlTable) getDomNodeOrDie();
    return new HTMLCollection(table, false) {
        @Override
        protected List<DomNode> computeElements() {
            return new ArrayList<>(table.getBodies());
        }
    };
}
 
Example #6
Source File: HTMLTableRowElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of the row within the parent table.
 * @return the index of the row within the parent table
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms534377.aspx">MSDN Documentation</a>
 */
@JsxGetter
public int getRowIndex() {
    final HtmlTableRow row = (HtmlTableRow) getDomNodeOrDie();
    final HtmlTable table = row.getEnclosingTable();
    if (table == null) { // a not attached document.createElement('TR')
        return -1;
    }
    return table.getRows().indexOf(row);
}
 
Example #7
Source File: HTMLTableElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the tbody's in the table.
 * @return the tbody's in the table
 */
@JsxGetter
public Object getTBodies() {
    final HtmlTable table = (HtmlTable) getDomNodeOrDie();
    return new HTMLCollection(table, false) {
        @Override
        protected List<DomNode> computeElements() {
            return new ArrayList<DomNode>(table.getBodies());
        }
    };
}
 
Example #8
Source File: AbstractOIDCTest.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
private static String getClientIdByName(String clientName, HtmlPage registeredClientsPage) {
    final HtmlTable table = registeredClientsPage.getHtmlElementById("registered_clients");
    for (final HtmlTableRow row : table.getRows()) {
        if (clientName.equals(row.getCell(0).asText())) {
            final String clientId = row.getCell(1).asText();
            assertNotNull(clientId);
            return clientId;
        }
    }
    throw new IllegalArgumentException("Client '" + clientName + "' not found");
}
 
Example #9
Source File: AbstractOIDCTest.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
private static void loginToClientsPageAndDeleteClient(String servletContext) throws IOException {
    // Login to the client page successfully
    try (WebClient webClient = setupWebClientIDP("alice", "ecila")) {
        final UriBuilder clientsUrl = oidcEndpointBuilder(servletContext, "/console/clients/{path}");
        HtmlPage registeredClientsPage = login(clientsUrl.resolveTemplate("path", ""), webClient);

        // Get the client identifier
        HtmlTable table = registeredClientsPage.getHtmlElementById("registered_clients");
        String clientId = table.getCellAt(1, 1).asText();
        assertNotNull(clientId);
        String clientId2 = table.getCellAt(2, 1).asText();
        assertNotNull(clientId2);

        // Now go to the specific client page
        registeredClientsPage =
            deleteClient(webClient.getPage(clientsUrl.resolveTemplate("path", clientId).build().toURL()));

        // Check we have one more registered clients
        table = registeredClientsPage.getHtmlElementById("registered_clients");
        assertEquals(2, table.getRowCount());

        // Now delete the other client
        registeredClientsPage =
            deleteClient(webClient.getPage(clientsUrl.resolveTemplate("path", clientId2).build().toURL()));

        // Check we have no more registered clients
        table = registeredClientsPage.getHtmlElementById("registered_clients");
        assertEquals(1, table.getRowCount());
    }
}
 
Example #10
Source File: AbstractOIDCTest.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testCreatedClients() throws Exception {
    // Login to the client page successfully
    try (WebClient webClient = setupWebClientIDP("alice", "ecila")) {
        final HtmlPage registeredClientsPage = login(oidcEndpointBuilder("/console/clients"), webClient);
        final String bodyTextContent = registeredClientsPage.getBody().getTextContent();
        assertTrue(bodyTextContent.contains("Registered Clients"));

        // Get the new client identifier
        HtmlTable table = registeredClientsPage.getHtmlElementById("registered_clients");

        // 2 clients
        assertEquals(table.getRows().size(), 3);

        // Now check the first client
        String clientId = table.getCellAt(1, 1).asText();
        assertNotNull(clientId);

        // Check the Date
        String date = table.getCellAt(1, 2).asText();
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.US);
        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        assertEquals(dateFormat.format(new Date()), date);

        // Check the redirect URI
        String redirectURI = table.getCellAt(1, 3).asText().trim(); // <br/>
        assertTrue(REDIRECT_URL.equals(redirectURI));
    }
}
 
Example #11
Source File: AbstractOIDCTest.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testEditClient() throws Exception {
    try (WebClient webClient = setupWebClientIDP("alice", "ecila")) {
        HtmlPage registeredClientPage = login(oidcEndpointBuilder("/console/clients/" + publicClientId),
            webClient);

        final HtmlPage editClientPage = registeredClientPage.getAnchorByText("public-client").click();

        final HtmlForm form = editClientPage.getForms().get(0);

        // Set new client values
        final HtmlTextInput clientNameInput = form.getInputByName("client_name");
        final String newClientName = "public-client-modified";
        clientNameInput.setValueAttribute(newClientName);
        final HtmlSelect clientTypeSelect = form.getSelectByName("client_type");
        assertTrue(clientTypeSelect.isDisabled());
        final HtmlTextInput redirectURIInput = form.getInputByName("client_redirectURI");
        assertEquals(REDIRECT_URL, redirectURIInput.getText());
        final HtmlTextInput clientAudienceURIInput = form.getInputByName("client_audience");
        assertEquals("https://ws.apache.org", clientAudienceURIInput.getText());
        final HtmlTextInput clientLogoutURI = form.getInputByName("client_logoutURI");
        assertEquals(LOGOUT_URL, clientLogoutURI.getText());

        registeredClientPage = form.getButtonByName("submit_button").click();
        assertNotNull(registeredClientPage.getAnchorByText(newClientName));

        final HtmlPage registeredClientsPage = registeredClientPage.getAnchorByText("registered Clients").click();

        HtmlTable table = registeredClientsPage.getHtmlElementById("registered_clients");
        assertEquals("2 clients", table.getRows().size(), 3);
        boolean updatedClientFound = false;
        for (final HtmlTableRow row : table.getRows()) {
            if (newClientName.equals(row.getCell(0).asText())) {
                updatedClientFound = true;
                break;
            }
        }
        assertTrue(updatedClientFound);
    }
}
 
Example #12
Source File: AbstractOIDCTest.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testRegisteredClientsAsBob() throws Exception {
    // Login to the client page successfully
    try (WebClient webClient = setupWebClientIDP("bob", "bob")) {
        final HtmlPage registeredClientsPage = login(oidcEndpointBuilder("/console/clients"), webClient);
        final String bodyTextContent = registeredClientsPage.getBody().getTextContent();
        assertTrue(bodyTextContent.contains("Registered Clients"));

        // Get the new client identifier
        HtmlTable table = registeredClientsPage.getHtmlElementById("registered_clients");

        // no clients
        assertEquals(table.getRows().size(), 1);
    }
}
 
Example #13
Source File: HTMLElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
private Object getOffsetParentInternal(final boolean returnNullIfFixed) {
    DomNode currentElement = getDomNodeOrDie();

    if (currentElement.getParentNode() == null) {
        return null;
    }

    final HTMLElement htmlElement = currentElement.getScriptableObject();
    if (returnNullIfFixed && "fixed".equals(htmlElement.getStyle().getStyleAttribute(
            StyleAttributes.Definition.POSITION, true))) {
        return null;
    }

    final ComputedCSSStyleDeclaration style = htmlElement.getWindow().getComputedStyle(htmlElement, null);
    final String position = style.getPositionWithInheritance();
    final boolean staticPos = "static".equals(position);

    while (currentElement != null) {

        final DomNode parentNode = currentElement.getParentNode();
        if (parentNode instanceof HtmlBody
            || (staticPos && parentNode instanceof HtmlTableDataCell)
            || (staticPos && parentNode instanceof HtmlTable)) {
            return parentNode.getScriptableObject();
        }

        if (parentNode != null && parentNode.getScriptableObject() instanceof HTMLElement) {
            final HTMLElement parentElement = parentNode.getScriptableObject();
            final ComputedCSSStyleDeclaration parentStyle =
                        parentElement.getWindow().getComputedStyle(parentElement, null);
            final String parentPosition = parentStyle.getPositionWithInheritance();
            if (!"static".equals(parentPosition)) {
                return parentNode.getScriptableObject();
            }
        }

        currentElement = currentElement.getParentNode();
    }

    return null;
}
 
Example #14
Source File: HTMLElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
private Object getOffsetParentInternal(final boolean returnNullIfFixed) {
    DomNode currentElement = getDomNodeOrDie();

    if (currentElement.getParentNode() == null) {
        return null;
    }

    Object offsetParent = null;
    final HTMLElement htmlElement = (HTMLElement) currentElement.getScriptableObject();
    if (returnNullIfFixed && "fixed".equals(htmlElement.getStyle().getStyleAttribute(
            StyleAttributes.Definition.POSITION, true))) {
        return null;
    }

    final ComputedCSSStyleDeclaration style = htmlElement.getWindow().getComputedStyle(htmlElement, null);
    final String position = style.getPositionWithInheritance();
    final boolean staticPos = "static".equals(position);

    final boolean useTables = staticPos;

    while (currentElement != null) {

        final DomNode parentNode = currentElement.getParentNode();
        if (parentNode instanceof HtmlBody
            || (useTables && parentNode instanceof HtmlTableDataCell)
            || (useTables && parentNode instanceof HtmlTable)) {
            offsetParent = parentNode.getScriptableObject();
            break;
        }

        if (parentNode != null && parentNode.getScriptableObject() instanceof HTMLElement) {
            final HTMLElement parentElement = (HTMLElement) parentNode.getScriptableObject();
            final ComputedCSSStyleDeclaration parentStyle =
                        parentElement.getWindow().getComputedStyle(parentElement, null);
            final String parentPosition = parentStyle.getPositionWithInheritance();
            final boolean parentIsStatic = "static".equals(parentPosition);
            if (!parentIsStatic) {
                offsetParent = parentNode.getScriptableObject();
                break;
            }
        }

        currentElement = currentElement.getParentNode();
    }

    return offsetParent;
}
 
Example #15
Source File: AbstractOIDCTest.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
private static String getClientSecret(final HtmlPage registeredClientPage, String clientId) throws IOException {
    final HtmlTable table = registeredClientPage.getHtmlElementById("client");
    assertEquals(clientId, table.getCellAt(1, 0).asText());
    return table.getCellAt(1, 2).asText();
}