Saturday, November 27, 2010

Re: newbie trying to use htmlunit & gwt 2.1 to test greet example

At 04:36 AM 11/27/2010, you wrote:
>You aren't finding any buttons because HTML doesn't have a <button>
>tag. Use one of the methods described under "Finding a specific
>element" at this page: http://htmlunit.sourceforge.net/gettingStarted.html.
>I generally find myself needing xpath sooner or later.

the tests below all pass.

i have: <button id="xxx" type="button">Click Me!</button> in the
html, so it finds that one. but it does not find any of the dynamic
ones that i made with: final Button b = new Button(commandId); in the
clinet code.

so i am still puzzled.

thanks


package hw;

import org.junit.*;
import static org.junit.Assert.*;
import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.*;

public class BasicHtmlUnitRPCTestCase {

@BeforeClass public static void setUpBeforeClass() throws Exception {

}
static final String
url="http://127.0.0.1:8888/Reasy.html?gwt.codesvr=127.0.0.1:9997";
@AfterClass public static void tearDownAfterClass() throws
Exception {}

@Before public void setUp() throws Exception {}

@After public void tearDown() throws Exception {}

@Test public void testVanilla() throws Exception {
System.out.println("testVanilla");
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage(url);
final DomNodeList<HtmlElement> buttons =
page.getElementsByTagName("button");
assertTrue(buttons.size() >= 1);
}

@Test public void testNicelyResynchronizingAjaxController()
throws Exception {
System.out.println("testNicelyResynchronizingAjaxController");
final WebClient webClient = new WebClient();
webClient.setAjaxController(new
NicelyResynchronizingAjaxController());
final HtmlPage page = webClient.getPage(url);
final DomNodeList<HtmlElement> buttons =
page.getElementsByTagName("button");
assertTrue(buttons.size() >= 1);
}

@Test public void testwaitForBackgroundJavaScript() throws Exception {
System.out.println("testwaitForBackgroundJavaScript");
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage(url);
webClient.waitForBackgroundJavaScript(10000);
final DomNodeList<HtmlElement> buttons =
page.getElementsByTagName("button");
assertTrue(buttons.size() >= 1);
}
@Test public void
testwaitForBackgroundJavaScriptStartingBefore() throws Exception {
System.out.println("testwaitForBackgroundJavaScriptStartingBefore");
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage(url);
webClient.waitForBackgroundJavaScript(10000);
final DomNodeList<HtmlElement> buttons =
page.getElementsByTagName("button");
assertTrue(buttons.size() >= 1);
}

@Test public void testWait() throws Exception {
System.out.println("testWait");
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage(url);
Thread.sleep(10000);
final DomNodeList<HtmlElement> buttons =
page.getElementsByTagName("button");
assertTrue(buttons.size() >= 1);
}

@Test public void testWaitForCondition() throws Exception {
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage(url);
DomNodeList<HtmlElement> buttons =
page.getElementsByTagName("button");
for (int i = 0; i < 20; i++) {
buttons = page.getElementsByTagName("button");
System.out.println(buttons.size());
if (buttons.size() >= 1) {
break;
}
synchronized (page) {
page.wait(1000);
}
}
assertTrue(buttons.size() >= 1);
}

}

---
co-chair http://ocjug.org/

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment