Note that there are some explanatory texts on larger screens.

plurals
  1. POproblem writing HTMLUnit script for YUI form submit
    primarykey
    data
    text
    <p>I want to write a simple HTMLUnit test script for Jenkins (former Hudson). INFO: Jenkins uses the YUI Javascript library. The YUI library replaces the form submit with a custom button. The script just creates a new job in Jenkins.</p> <p>start Jenkins: java -jar jenkins.war</p> <p>Current versions of HTMLUnit do not support form.submit any more and require you to use button.click() for form submitting. Unfortunately this does not work for Jenkins (the sample below does not advance the page and create the job but stays on the new job page)</p> <p>I tried for some hours now to find a solution or workaround but so far I could not get the form submitted. Hopefully somebody has found a solution and let me know.</p> <p>Here is my sample code:</p> <pre><code>package example; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; public class jenkins3 { public static void main(String args[]) { // create a new job in jenkins // home final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6); try { final HtmlPage page1 = webClient.getPage("http://localhost:8080"); //assertEquals("Dashboard [Jenkins]", page1.getTitleText()); // new job final HtmlAnchor new_job = page1.getAnchorByText("New Job"); final HtmlPage page2 = new_job.click(); // job name HtmlTextInput name_field = (HtmlTextInput) page2.getElementById("name"); name_field.type("new job by htmlunit"); // radio button final HtmlInput radio_freestyle = (HtmlInput) page2.getByXPath("//input[@value='hudson.model.FreeStyleProject']").get(0); radio_freestyle.click(); Thread.sleep(10000); // OK button (submit form) final HtmlForm form = page2.getFormByName("createItem"); //final HtmlSubmitInput button = (HtmlSubmitInput) form.getByXPath("//button").get(0); final HtmlButton button = (HtmlButton) form.getByXPath("//button").get(0); final HtmlPage page3 = button.click(); // !!!!! Form submit does not workstacko //assertEquals("Dashboard [Jenkins]", page3.getTitleText()); } catch( Exception e ) { System.out.println( "General exception thrown:" + e.getMessage() ); e.printStackTrace(); } webClient.closeAllWindows(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload