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);
}
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();
}
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();
}
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();
}
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());
}
});
}
Aggregations