Search in sources :

Example 1 with HtmlElement

use of com.gargoylesoftware.htmlunit.html.HtmlElement in project selenium_java by sergueik.

the class WhenBrowsingReportsList method checkReportHyperlinks.

private void checkReportHyperlinks(final HtmlTableRow row) {
    List<HtmlElement> elements = row.getCell(0).getHtmlElementsByTagName("a");
    Assert.assertEquals("Unexpected number of anchor elements for report icon", 1, elements.size());
    final HtmlAnchor iconAnchor = (HtmlAnchor) elements.get(0);
    elements = row.getCell(1).getHtmlElementsByTagName("a");
    Assert.assertEquals("Unexpected number of anchor elements for report title", 1, elements.size());
    final HtmlAnchor titleAnchor = (HtmlAnchor) elements.get(0);
    Assert.assertEquals("Hyperlinks must not be different between report icon and report title", iconAnchor.getHrefAttribute(), titleAnchor.getHrefAttribute());
}
Also used : HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement)

Example 2 with HtmlElement

use of com.gargoylesoftware.htmlunit.html.HtmlElement in project selenium_java by sergueik.

the class AbstractJenkinsPage method getElement.

public HtmlElement getElement(final HtmlElement container, final String tagName, final String textContent) {
    LOGGER.log(Level.INFO, String.format("Looking into container '%s' for element '%s' with content '%s'", container, tagName, textContent));
    final List<HtmlElement> elements = container.getElementsByTagName(tagName);
    HtmlElement retval = null;
    // find the save button (it has no predictable id)
    for (final HtmlElement element : elements) {
        if (element.getTextContent().trim().equalsIgnoreCase(textContent)) {
            retval = element;
            break;
        }
    }
    LOGGER.log(Level.INFO, String.format("Found %s", retval));
    return retval;
}
Also used : HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement)

Example 3 with HtmlElement

use of com.gargoylesoftware.htmlunit.html.HtmlElement in project selenium_java by sergueik.

the class JenkinsConfigurationPage method getSecurityMatrix.

private HtmlTable getSecurityMatrix() {
    // enable security
    final HtmlElement useSecurity = configForm.getInputByName("_.useSecurity");
    try {
        useSecurity.click();
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
    // use matrix-based security
    final List<HtmlInput> authorizationInputs = configForm.getInputsByName("authorization");
    HtmlInput useMatrixSecurityRadioBtn = null;
    for (final HtmlInput input : authorizationInputs) {
        if (input.getValueAttribute().equals("3")) {
            useMatrixSecurityRadioBtn = input;
            break;
        }
    }
    try {
        useMatrixSecurityRadioBtn.click();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return (HtmlTable) configForm.getOwnerDocument().getElementById("hudson-security-GlobalMatrixAuthorizationStrategy");
}
Also used : HtmlTable(com.gargoylesoftware.htmlunit.html.HtmlTable) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) IOException(java.io.IOException) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput)

Example 4 with HtmlElement

use of com.gargoylesoftware.htmlunit.html.HtmlElement in project JSCover by tntim96.

the class HtmlServerUnloadedJSProxyOnlyInstrumentRegTest method shouldIncludeUnloadJSInSavedReport.

@Test
public void shouldIncludeUnloadJSInSavedReport() throws Exception {
    File jsonFile = new File(reportDir + "/jscoverage.json");
    if (jsonFile.exists())
        jsonFile.delete();
    HtmlPage page = webClient.getPage("http://localhost:9001/jscoverage.html?index.html");
    page.getHtmlElementById("summaryTab").click();
    webClient.waitForBackgroundJavaScript(2000);
    assertEquals("75%", page.getElementById("summaryTotal").getTextContent());
    verifyCoverage(page, "/level1/level1.js", "75%", "50%", "N/A");
    page.getHtmlElementById("storeTab").click();
    webClient.waitForBackgroundJavaScript(500);
    HtmlElement storeButton = page.getHtmlElementById("storeButton");
    storeButton.click();
    webClient.waitForBackgroundJavaScript(2000);
    String result = page.getElementById("storeDiv").getTextContent();
    assertThat(result, containsString("Coverage data stored at " + new File(reportDir).getPath()));
    String json = ioUtils.toString(jsonFile);
    assertThat(json, not(containsString("/root.js")));
    assertThat(json, containsString("/level1/level1.js"));
    assertThat(json, containsString("/level1/level2/level2.js"));
    String url = "file:///" + new File(reportDir + "/jscoverage.html").getAbsolutePath();
    page = webClient.getPage(url);
    webClient.waitForBackgroundJavaScript(1000);
    assertEquals("37%", page.getElementById("summaryTotal").getTextContent());
    assertEquals("25%", page.getElementById("branchSummaryTotal").getTextContent());
    assertEquals("0%", page.getElementById("functionSummaryTotal").getTextContent());
    verifyCoverage(page, "/level1/level1.js", "75%", "50%", "N/A");
    verifyCoverage(page, "/level1/level2/level2.js", "0%", "0%", "0%");
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 5 with HtmlElement

use of com.gargoylesoftware.htmlunit.html.HtmlElement in project promoted-builds-plugin by jenkinsci.

the class ManualConditionBug22005 method testPromotionProcessViaWebClient.

@Test
public void testPromotionProcessViaWebClient() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    ExtensionList<Descriptor> list = j.jenkins.getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    createPromotionProcess(base, "PROM0");
    createPromotionProcess(base, "PROM1");
    createPromotionProcess(base, "PROM2");
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    assertNull(b1.getAction(ManualApproval.class));
    HtmlPage page = j.createWebClient().getPage(b1, "promotion");
    // Approve Promotion
    List<HtmlForm> forms = ManualConditionTest.getFormsByName(page, "approve");
    assertFalse(forms.isEmpty());
    assertEquals(3, forms.size());
    for (HtmlForm form : forms) {
        submit(form);
    }
    // reload promotions page
    page = j.createWebClient().getPage(b1, "promotion");
    forms = ManualConditionTest.getFormsByName(page, "build");
    for (HtmlForm form : forms) {
        List<HtmlElement> parameters = ManualConditionTest.getFormParameters(form);
        assertEquals(2, parameters.size());
    }
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) Descriptor(hudson.model.Descriptor) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Test(org.junit.Test)

Aggregations

HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)13 Test (org.junit.Test)6 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)4 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)3 Descriptor (hudson.model.Descriptor)3 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)3 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)3 File (java.io.File)3 IOException (java.io.IOException)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 FreeStyleBuild (hudson.model.FreeStyleBuild)2 FreeStyleProject (hudson.model.FreeStyleProject)2 ParameterDefinition (hudson.model.ParameterDefinition)2 StringParameterDefinition (hudson.model.StringParameterDefinition)2 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)2 Promotion (hudson.plugins.promoted_builds.Promotion)2 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)2 ArrayList (java.util.ArrayList)2 WebDriverException (org.openqa.selenium.WebDriverException)2