Search in sources :

Example 76 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project sling by apache.

the class MetricWebConsolePluginTest method webConsolePlugin.

@Test
public void webConsolePlugin() throws Exception {
    MetricRegistry reg1 = new MetricRegistry();
    reg1.meter("test1").mark(5);
    reg1.timer("test2").time().close();
    reg1.histogram("test3").update(743);
    reg1.counter("test4").inc(9);
    reg1.registerAll(new JvmAttributeGaugeSet());
    context.registerService(MetricRegistry.class, reg1, regProps("foo"));
    activatePlugin();
    StringWriter sw = new StringWriter();
    HttpServletResponse response = mock(HttpServletResponse.class);
    when(response.getWriter()).thenReturn(new PrintWriter(sw));
    plugin.doGet(mock(HttpServletRequest.class), response);
    WebClient client = new WebClient();
    WebResponse resp = new StringWebResponse(sw.toString(), WebClient.URL_ABOUT_BLANK);
    HtmlPage page = HTMLParser.parseHtml(resp, client.getCurrentWindow());
    assertTable("data-meters", page);
    assertTable("data-counters", page);
    assertTable("data-timers", page);
    assertTable("data-histograms", page);
    assertTable("data-gauges", page);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JvmAttributeGaugeSet(com.codahale.metrics.JvmAttributeGaugeSet) StringWebResponse(com.gargoylesoftware.htmlunit.StringWebResponse) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) StringWebResponse(com.gargoylesoftware.htmlunit.StringWebResponse) StringWriter(java.io.StringWriter) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) MetricRegistry(com.codahale.metrics.MetricRegistry) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebClient(com.gargoylesoftware.htmlunit.WebClient) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 77 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project nymph by Onnt.

the class HtmlUnit method getPage.

@SuppressWarnings("resource")
public String getPage(String path) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
    final WebClient webClient = new WebClient(BrowserVersion.CHROME);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
    webClient.getOptions().setJavaScriptEnabled(true);
    webClient.getOptions().setActiveXNative(false);
    webClient.getOptions().setCssEnabled(false);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.waitForBackgroundJavaScript(600 * 1000);
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    final HtmlPage page = webClient.getPage(path);
    webClient.waitForBackgroundJavaScript(1000 * 3);
    webClient.setJavaScriptTimeout(0);
    webClient.getOptions().setJavaScriptEnabled(true);
    return page.asXml();
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) NicelyResynchronizingAjaxController(com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Example 78 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project testcases by coheigea.

the class OIDCTest method login.

private static HtmlPage login(String url, WebClient webClient) throws IOException {
    webClient.getOptions().setJavaScriptEnabled(false);
    final HtmlPage idpPage = webClient.getPage(url);
    webClient.getOptions().setJavaScriptEnabled(true);
    Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText());
    // Test the SAML Version here
    DomNodeList<DomElement> results = idpPage.getElementsByTagName("input");
    String wresult = null;
    for (DomElement result : results) {
        if ("wresult".equals(result.getAttributeNS(null, "name"))) {
            wresult = result.getAttributeNS(null, "value");
            break;
        }
    }
    Assert.assertTrue(wresult != null && wresult.contains("urn:oasis:names:tc:SAML:2.0:cm:bearer"));
    final HtmlForm form = idpPage.getFormByName("signinresponseform");
    final HtmlSubmitInput button = form.getInputByName("_eventId_submit");
    return button.click();
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)

Example 79 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project testcases by coheigea.

the class FederationTest method login.

private static String login(String url, String user, String password, String idpPort) throws IOException {
    final WebClient webClient = new WebClient();
    webClient.getOptions().setUseInsecureSSL(true);
    webClient.getCredentialsProvider().setCredentials(new AuthScope("localhost", Integer.parseInt(idpPort)), new UsernamePasswordCredentials(user, password));
    webClient.getOptions().setJavaScriptEnabled(false);
    final HtmlPage idpPage = webClient.getPage(url);
    webClient.getOptions().setJavaScriptEnabled(true);
    Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText());
    final HtmlForm form = idpPage.getFormByName("signinresponseform");
    final HtmlSubmitInput button = form.getInputByName("_eventId_submit");
    final XmlPage rpPage = button.click();
    return rpPage.asXml();
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) AuthScope(org.apache.http.auth.AuthScope) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 80 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project workflow-cps-plugin by jenkinsci.

the class ReplayActionTest method rebuild.

@Issue("JENKINS-47339")
@Test
public void rebuild() throws Exception {
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            story.j.jenkins.setSecurityRealm(story.j.createDummySecurityRealm());
            GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
            gmas.add(Jenkins.READ, "dev3");
            gmas.add(Item.BUILD, "dev3");
            gmas.add(Item.READ, "dev3");
            story.j.jenkins.setAuthorizationStrategy(gmas);
            WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
            p.setDefinition(new CpsFlowDefinition("echo 'script to rebuild'", true));
            WorkflowRun b1 = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
            story.j.assertLogContains("script to rebuild", b1);
            WorkflowRun b2;
            {
                // First time around, verify that UI elements are present and functional.
                ReplayAction a = b1.getAction(ReplayAction.class);
                assertNotNull(a);
                assertFalse(canReplay(b1, "dev3"));
                assertTrue(canRebuild(b1, "dev3"));
                JenkinsRule.WebClient wc = story.j.createWebClient();
                wc.login("dev3");
                HtmlPage page = wc.getPage(b1, a.getUrlName());
                WebAssert.assertFormNotPresent(page, "config");
                HtmlForm form = page.getFormByName("rebuild");
                HtmlPage redirect = story.j.submit(form);
                assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString());
                story.j.waitUntilNoActivity();
                b2 = p.getBuildByNumber(2);
                assertNotNull(b2);
            }
            story.j.assertLogContains("script to rebuild", story.j.assertBuildStatusSuccess(b2));
            ReplayCause cause = b2.getCause(ReplayCause.class);
            assertNotNull(cause);
            assertEquals(1, cause.getOriginalNumber());
            assertEquals(b1, cause.getOriginal());
            assertEquals(b2, cause.getRun());
        }
    });
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Statement(org.junit.runners.model.Statement) RestartableJenkinsRule(org.jvnet.hudson.test.RestartableJenkinsRule) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)159 Test (org.junit.Test)114 WebClient (com.gargoylesoftware.htmlunit.WebClient)51 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)25 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)23 HtmlSpan (com.gargoylesoftware.htmlunit.html.HtmlSpan)21 File (java.io.File)17 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)15 Matchers.containsString (org.hamcrest.Matchers.containsString)13 IOException (java.io.IOException)11 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)10 FreeStyleProject (hudson.model.FreeStyleProject)9 URL (java.net.URL)9 Page (com.gargoylesoftware.htmlunit.Page)8 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)7 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)6 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)6 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)5 HtmlButton (com.gargoylesoftware.htmlunit.html.HtmlButton)5 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)5