Search in sources :

Example 56 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project javaee7-samples by javaee-samples.

the class FormTest method testGetWithCorrectCredentials.

@Test
public void testGetWithCorrectCredentials() throws Exception {
    loginForm.getInputByName("j_username").setValueAttribute("u1");
    loginForm.getInputByName("j_password").setValueAttribute("p1");
    HtmlSubmitInput submitButton = loginForm.getInputByName("submitButton");
    HtmlPage page2 = submitButton.click();
    assertEquals("Form-based Security - Success", page2.getTitleText());
}
Also used : HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Test(org.junit.Test)

Example 57 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project javaee7-samples by javaee-samples.

the class FormTest method setup.

@Before
public void setup() throws IOException {
    @SuppressWarnings("resource") WebClient webClient = new WebClient();
    HtmlPage page = webClient.getPage(base + "SecureServlet");
    loginForm = page.getForms().get(0);
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Before(org.junit.Before)

Example 58 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage 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)

Example 59 with HtmlPage

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

the class PromotedBuildActionTest method testDeletedPromotionProcess.

@Test
public void testDeletedPromotionProcess() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess foo = base.addProcess("foo");
    // promote a build
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    foo.promote(b1, new UserCause(), new ManualPromotionBadge());
    // now delete the promotion process
    p.removeProperty(base);
    p.addProperty(base = new JobPropertyImpl(p));
    assertTrue(base.getActiveItems().isEmpty());
    // make sure that the page renders OK without any error
    HtmlPage page = j.createWebClient().getPage(p);
    List<?> candidates = page.getByXPath("//IMG");
    for (Object candidate : candidates) {
        if (!(candidate instanceof HtmlImage)) {
            continue;
        }
        HtmlImage img = (HtmlImage) candidate;
        try {
            assertEquals("Failed to load " + img.getSrcAttribute(), 200, img.getWebResponse(true).getStatusCode());
        } catch (IOException e) {
            throw new AssertionError("Failed to load " + img.getSrcAttribute());
        }
    }
}
Also used : HtmlImage(com.gargoylesoftware.htmlunit.html.HtmlImage) UserCause(hudson.model.Cause.UserCause) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) FreeStyleBuild(hudson.model.FreeStyleBuild) IOException(java.io.IOException) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 60 with HtmlPage

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

the class ConfigurationDoCheckTest method testCheckInvalidProcessName.

@Issue("JENKINS-7972")
@Test
public void testCheckInvalidProcessName() throws Exception {
    FreeStyleProject down = j.createFreeStyleProject();
    FreeStyleProject p = j.createFreeStyleProject();
    JobPropertyImpl pp = new JobPropertyImpl(p);
    p.addProperty(pp);
    PromotionProcess proc = pp.addProcess("test/");
    assertEquals(1, pp.getItems().size());
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
    proc.icon = "star-blue";
    JenkinsRule.WebClient client = j.createWebClient();
    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = (HtmlPage) submit(client.getPage(p, "configure").getFormByName("config"));
    assertTrue(page.getVisibleText().contains("unsafe character"));
}
Also used : DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JavadocArchiver(hudson.tasks.JavadocArchiver) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) 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