From: Jim L. <jli...@ad...> - 2004-03-19 18:55:19
|
I'm an HtmlUnit newbie, completely. Definitely excited about the potential of HtmlUnit, as we are using JUnit quite successfully, and Silk is being used by QA. We need web-level testing controlled and regularly run by our programmers, and I'm hoping that HtmlUnit will do the trick. =20 BTW, another guy here was messing with Cactus, but found it difficult to use. I don't know many details, but are people on this list using Cactus successfully, or have you found it a pain in the neck? =20 Anyway, I found that just getting started was a little harder than expected. First, there was no complete file, just fragments. It was not clear which URL class was to be used (Eclipse found org.apache.catalina.util.URL and java.util.URL). It wasn't clear if we should extend TestCase or womething else. Then, when I ran the fragment, I got the ScriptException - fortunately, I found the fix several months into the archive. And finally, the title on the page had changed, so the test didn't work. =20 Does anyone know why I can't run javascript from the page? Is it the google ads again, as in the October '03 thread? Or something I am doing wrong, like only using the minimally required jars? =20 Finally, I think it would be helpful to post an entire minimal file that people could use to get started. Here is one: =20 // Change the package for your development environment package com.advisorsoftware.webtier.htmlunit; =20 =20 import java.net.URL; =20 import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlPage; =20 import junit.framework.TestCase; =20 /** * @author jlindsay * The purpose of this class is to get HtmlUnit running. Note that you must=20 * have the set of HtmlUnit required jars in your classpath, along with junit.jar, * for this to work. */ public class TestHtmlUnit extends TestCase { public void testHomePage()=20 throws Exception=20 { final WebClient webClient =3D new WebClient(); final URL url =3D new = URL("http://htmlunit.sourceforge.net"); =20 webClient.setJavaScriptEnabled(false); final HtmlPage page =3D (HtmlPage)webClient.getPage(url); =20 assertEquals( "htmlunit - Welcome to HtmlUnit", page.getTitleText()); } } =20 =20 |