diff --git a/test/pom.xml b/test/pom.xml index 0af213f6b9e67c3a3996d5dc4d441cda95c175bc..34495fd7788d31976b8f82d2075faf256d8d5d87 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -64,6 +64,16 @@ THE SOFTWARE. ${project.groupId} maven-plugin ${maven-plugin.version} + + + org.apache.httpcomponents + httpclient + + + org.apache.httpcomponents + httpcore + + org.jenkins-ci.plugins diff --git a/test/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFormUtil.java b/test/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFormUtil.java index e08177881c4deecc4556ea11281dc4b2f51feb74..9ad296633e3e09f897ce1e31c1bc7b7624cb2a10 100644 --- a/test/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFormUtil.java +++ b/test/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFormUtil.java @@ -38,14 +38,14 @@ public class HtmlFormUtil { * Plain {@link com.gargoylesoftware.htmlunit.html.HtmlForm#submit()} doesn't work correctly due to the use of YUI in Hudson. */ public static Page submit(final HtmlForm htmlForm) throws IOException { - final HtmlSubmitInput submitElement = getSubmitButton(htmlForm); + final HtmlButton submitElement = getSubmitButton(htmlForm); return submit(htmlForm, submitElement); } /** * Plain {@link com.gargoylesoftware.htmlunit.html.HtmlForm#submit()} doesn't work correctly due to the use of YUI in Hudson. */ - public static Page submit(HtmlForm htmlForm, HtmlSubmitInput submitElement) throws IOException { + public static Page submit(HtmlForm htmlForm, HtmlButton submitElement) throws IOException { if (submitElement != null) { // To make YUI event handling work, this combo seems to be necessary // the click will trigger _onClick in buton-*.js, but it doesn't submit the form @@ -63,13 +63,13 @@ public class HtmlFormUtil { /** * Returns all the <input type="submit"> elements in this form. */ - public static List getSubmitButtons(final HtmlForm htmlForm) throws ElementNotFoundException { - final List list = htmlForm.getElementsByAttribute("input", "type", "submit"); + public static List getSubmitButtons(final HtmlForm htmlForm) throws ElementNotFoundException { + final List list = htmlForm.getElementsByAttribute("input", "type", "submit"); // collect inputs from lost children for (final HtmlElement elt : htmlForm.getLostChildren()) { - if (elt instanceof HtmlSubmitInput) { - list.add((HtmlSubmitInput) elt); + if (elt instanceof HtmlButton) { + list.add((HtmlButton) elt); } } return list; @@ -78,14 +78,19 @@ public class HtmlFormUtil { /** * Gets the first <input type="submit"> element in this form. */ - public static HtmlSubmitInput getSubmitButton(final HtmlForm htmlForm) throws ElementNotFoundException { - return getSubmitButtons(htmlForm).get(0); + public static HtmlButton getSubmitButton(final HtmlForm htmlForm) throws ElementNotFoundException { + List submitButtons = getSubmitButtons(htmlForm); + if (!submitButtons.isEmpty()) { + return submitButtons.get(0); + } + return null; } - public static HtmlSubmitInput getButtonByCaption(final HtmlForm htmlForm, final String caption) throws ElementNotFoundException { + public static HtmlButton getButtonByCaption(final HtmlForm htmlForm, final String caption) throws ElementNotFoundException { for (HtmlElement b : htmlForm.getHtmlElementsByTagName("button")) { - if(b.getTextContent().trim().equals(caption)) - return (HtmlSubmitInput) b; + if(b instanceof HtmlButton && b.getTextContent().trim().equals(caption)) { + return (HtmlButton) b; + } } throw new ElementNotFoundException("button", "caption", caption); } diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index efb54899b36ce9385556a316d6537a6d6085e90d..8717c277047047918acdd95891bd5a86c1586247 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -1175,8 +1175,8 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { public HtmlPage submit(HtmlForm form, String name) throws Exception { for( HtmlElement e : form.getHtmlElementsByTagName("button")) { HtmlElement p = (HtmlElement)e.getParentNode().getParentNode(); - if(p.getAttribute("name").equals(name)) { - return (HtmlPage)HtmlFormUtil.submit(form, (HtmlSubmitInput) e); + if(e instanceof HtmlButton && p.getAttribute("name").equals(name)) { + return (HtmlPage)HtmlFormUtil.submit(form, (HtmlButton) e); } } throw new AssertionError("No such submit button with the name "+name); diff --git a/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java b/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java index 5e38f9066c32d56773e24222d1fd490f0148def2..20f4b87e40715fba97f50ab9894dce8b24b4cd66 100644 --- a/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java +++ b/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java @@ -1315,8 +1315,8 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction { public HtmlPage submit(HtmlForm form, String name) throws Exception { for( HtmlElement e : form.getHtmlElementsByTagName("button")) { HtmlElement p = (HtmlElement)e.getParentNode().getParentNode(); - if(p.getAttribute("name").equals(name)) { - return (HtmlPage)HtmlFormUtil.submit(form, (HtmlSubmitInput) e); + if(e instanceof HtmlButton && p.getAttribute("name").equals(name)) { + return (HtmlPage)HtmlFormUtil.submit(form, (HtmlButton) e); } } throw new AssertionError("No such submit button with the name "+name); diff --git a/test/src/test/java/hudson/bugs/LoginRedirectTest.java b/test/src/test/java/hudson/bugs/LoginRedirectTest.java index 033966cf18772e4fedc467d71fa164077e34c22a..c34a45c33897d93ec7d0bfc03ee88b1d46963ffe 100644 --- a/test/src/test/java/hudson/bugs/LoginRedirectTest.java +++ b/test/src/test/java/hudson/bugs/LoginRedirectTest.java @@ -51,7 +51,7 @@ public class LoginRedirectTest extends HudsonTestCase { wc.getOptions().setThrowExceptionOnFailingStatusCode(false); HtmlPage p = wc.goTo("/"); - System.out.println(p.getDocumentURI()); + //System.out.println(p.getDocumentURI()); assertEquals(200, p.getWebResponse().getStatusCode()); HtmlForm form = p.getFormByName("login"); form.getInputByName("j_username").setValueAttribute("alice");