Gable, David wrote:
> ...
> This is probably a failure in my understanding. As I said, I'll try out
> the demos to see if I can get them working. Thanks for all your help.
below are the very simple unit tests (in fact they were normally just
for my private use) I wrote to test HtmlUnit on DWR Demo site. I don't
now if they still work or not: DWR demo sites seems to have problems
currently and returns http 503 errors.
Marc.
------------------
import junit.framework.TestCase;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.ClickableElement;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSelect;
public class DWRTest extends TestCase {
public void testDynamicallyUpdatingText() throws Exception
{
final WebClient c = new WebClient();
final HtmlPage page = (HtmlPage)
c.getPage("
http://getahead.org/dwr/examples/text");
final ClickableElement queryServerButton = (ClickableElement)
page.getByXPath("//input[starts-with(.., 'Query Server')]").get(0);
queryServerButton.click();
final HtmlElement replyNode = page.getHtmlElementById("reply");
System.out.println(replyNode.asText());
Thread.sleep(2000);
System.out.println(replyNode.asText());
final ClickableElement includePageButton = (ClickableElement)
page.getByXPath("//input[@value = 'Include Page']").get(0);
final HtmlElement forwardNode = page.getHtmlElementById("forward");
includePageButton.click();
System.out.println(forwardNode.asText());
Thread.sleep(2000);
System.out.println(forwardNode.asText());
}
public void testDynamicFormEditing() throws Exception
{
final WebClient c = new WebClient();
final HtmlPage page = (HtmlPage)
c.getPage("
http://getahead.org/dwr/examples/form");
final HtmlElement nameNode = page.getHtmlElementById("name");
System.out.println(nameNode.asText());
Thread.sleep(2000);
System.out.println(nameNode.asText());
}
public void testDynamicallyEditingATable() throws Exception
{
final WebClient c = new WebClient();
final HtmlPage page = (HtmlPage)
c.getPage("
http://getahead.org/dwr/examples/table");
final HtmlElement tableBodyNode = page.getHtmlElementById("peoplebody");
System.out.println(tableBodyNode.asText());
Thread.sleep(2000);
System.out.println(tableBodyNode.asText());
}
public void testDynamicAddressEntry() throws Exception
{
final WebClient c = new WebClient();
final HtmlPage page = (HtmlPage)
c.getPage("
http://getahead.org/dwr/examples/address");
final HtmlInput postcode = (HtmlInput)
page.getHtmlElementById("postcode");
postcode.setValueAttribute("LE16 7TR");
final HtmlInput line2 = (HtmlInput) page.getHtmlElementById("line2");
System.out.println(line2.asText());
Thread.sleep(2000);
System.out.println(line2.asText());
}
/**
* big numbers not received
* @throws Exception
*/
public void testDynamicallyPopulatingASelectionList() throws Exception
{
final WebClient c = new WebClient();
final HtmlPage page = (HtmlPage)
c.getPage("
http://getahead.org/dwr/examples/lists");
final HtmlCheckBoxInput bigNumber = (HtmlCheckBoxInput)
page.getHtmlElementById("bigselect");
Thread.sleep(2000);
bigNumber.click();
final HtmlSelect select = (HtmlSelect) page.getHtmlElementById("numlist");
System.out.println(select.asText());
Thread.sleep(2000);
System.out.println(select.asXml());
}
public void testInFormServerSideValidation() throws Exception
{
final WebClient c = new WebClient();
final HtmlPage page = (HtmlPage)
c.getPage("
http://getahead.org/dwr/examples/validation");
final HtmlInput url = (HtmlInput) page.getHtmlElementById("url");
url.setValueAttribute("bla");
final HtmlElement urlValidationInfo =
page.getHtmlElementById("url-error");
System.out.println(urlValidationInfo.asText());
Thread.sleep(2000);
System.out.println(urlValidationInfo.asText());
}
public void testSimpleChatApplication() throws Exception
{
final WebClient c = new WebClient();
final HtmlPage page = (HtmlPage)
c.getPage("
http://getahead.org/dwr/examples/chat");
Thread.sleep(2000);
final HtmlInput message = (HtmlInput) page.getHtmlElementById("text");
message.setValueAttribute("from htmlunit");
final ClickableElement sendButton = (ClickableElement)
page.getByXPath("//input[@value = 'Send']").get(0);
sendButton.click();
final HtmlElement chat = page.getHtmlElementById("chatlog");
System.out.println(chat.asText());
Thread.sleep(2000);
System.out.println(chat.asText());
}
/**
* pb!
* @throws Exception
*/
public void testSerializingXML() throws Exception
{
final WebClient c = new WebClient(BrowserVersion.MOZILLA_1_0);
final HtmlPage page = (HtmlPage)
c.getPage("
http://getahead.org/dwr/examples/xml");
Thread.sleep(2000);
final HtmlInput message = (HtmlInput) page.getHtmlElementById("textXOM");
message.setValueAttribute("from htmlunit");
final ClickableElement sendXOMButton = (ClickableElement)
page.getByXPath("//input[@value = 'Get XOM Document']").get(0);
sendXOMButton.click();
final HtmlElement reply = page.getHtmlElementById("replyXOM");
System.out.println(reply.asText());
Thread.sleep(2000);
System.out.println(reply.asText());
}
}
------------------
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>
http://get.splunk.com/_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user