use of com.gargoylesoftware.htmlunit.html.HtmlForm 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.HtmlForm 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.HtmlForm 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());
}
});
}
use of com.gargoylesoftware.htmlunit.html.HtmlForm in project workflow-cps-plugin by jenkinsci.
the class ReplayActionTest method editSimpleDefinition.
@Test
public void editSimpleDefinition() throws Exception {
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'first script'", false));
// Start off with a simple run of the first script.
WorkflowRun b1 = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("first script", b1);
// Now will replay with a second script.
WorkflowRun b2;
{
// First time around, verify that UI elements are present and functional.
ReplayAction a = b1.getAction(ReplayAction.class);
assertNotNull(a);
assertTrue(a.isEnabled());
HtmlPage page = story.j.createWebClient().getPage(b1, a.getUrlName());
HtmlForm form = page.getFormByName("config");
HtmlTextArea text = form.getTextAreaByName("_.mainScript");
assertEquals("echo 'first script'", text.getText());
text.setText("echo 'second script'");
// TODO loaded scripts
HtmlPage redirect = story.j.submit(form);
assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString());
story.j.waitUntilNoActivity();
b2 = p.getBuildByNumber(2);
assertNotNull(b2);
}
// Subsequently can use the faster whitebox method.
story.j.assertLogContains("second script", story.j.assertBuildStatusSuccess(b2));
ReplayCause cause = b2.getCause(ReplayCause.class);
assertNotNull(cause);
assertEquals(1, cause.getOriginalNumber());
assertEquals(b1, cause.getOriginal());
assertEquals(b2, cause.getRun());
// Replay #2 as #3. Note that the diff is going to be from #1 → #3, not #2 → #3.
WorkflowRun b3 = (WorkflowRun) b2.getAction(ReplayAction.class).run("echo 'third script'", Collections.<String, String>emptyMap()).get();
story.j.assertLogContains("third script", story.j.assertBuildStatusSuccess(b3));
String diff = b3.getAction(ReplayAction.class).getDiff();
assertThat(diff, containsString("-echo 'first script'"));
assertThat(diff, containsString("+echo 'third script'"));
System.out.println(diff);
// Make a persistent edit to the script and run, just to make sure there is no lingering effect.
p.setDefinition(new CpsFlowDefinition("echo 'fourth script'", false));
story.j.assertLogContains("fourth script", story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
});
}
use of com.gargoylesoftware.htmlunit.html.HtmlForm in project workflow-job-plugin by jenkinsci.
the class WorkflowJobTest method disabled.
@Issue("JENKINS-27299")
@Test
public void disabled() throws Exception {
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
assertFalse(p.isDisabled());
assertTrue(p.isBuildable());
JenkinsRule.WebClient wc = j.createWebClient();
j.submit(wc.getPage(p).<HtmlForm>getHtmlElementById("disable-project"));
assertTrue(p.isDisabled());
assertFalse(p.isBuildable());
HtmlForm form = wc.getPage(p, "configure").getFormByName("config");
HtmlCheckBoxInput checkbox = form.getInputByName("disable");
assertTrue(checkbox.isChecked());
checkbox.setChecked(false);
j.submit(form);
assertFalse(p.isDisabled());
wc.getPage(new WebRequest(wc.createCrumbedUrl(p.getUrl() + "disable"), HttpMethod.POST));
assertTrue(p.isDisabled());
assertNull(p.scheduleBuild2(0));
assertThat(new CLICommandInvoker(j, "enable-job").invokeWithArgs("p"), CLICommandInvoker.Matcher.succeededSilently());
assertFalse(p.isDisabled());
}
Aggregations