Is there a working example of entering HTMLUnit and a few clicks

Javascript testing support available

 
package htmlunitpoc;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;

/**
 *
 * @author 
 */
public class HtmlPoc {

    /**
     * @param args the command line arguments
     */
   public static void main(String[] args) throws Exception {

        WebClient wc = new WebClient();
                HtmlPage page = (HtmlPage) wc.getPage("http://www.google.com");
                HtmlForm form = page.getFormByName("f");
                HtmlSubmitInput button = (HtmlSubmitInput) form.getInputByName("btnG");
                HtmlPage page2 = (HtmlPage) button.click();

    }


}

but I get:

November 17, 2010 15:41:14 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Outdated content type failed: "text / javascript". BUILD SUCCESSFUL (total time: 4 seconds)

Which does not help, since it does not work like Unit test, and shows Pass / Fail, etc.

I am using netbeans 6.9.1

+3
source share
1 answer

, unit test. HtmlUnit , , " ", - Java, .

:

import junit.framework.TestCase;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;

public class HtmlPoc
    extends TestCase
{
   public void test()
      throws Exception
    {
        WebClient wc = new WebClient();
        HtmlPage page = (HtmlPage) wc.getPage("http://www.google.com");
        HtmlForm form = page.getFormByName("f");
        HtmlSubmitInput button = (HtmlSubmitInput) form.getInputByName("btnG");
        HtmlPage page2 = (HtmlPage) button.click();
        assertNotNull( page2 ) ;
    }
}
+1

Source: https://habr.com/ru/post/1775511/


All Articles