Saturday, June 4, 2011

Re: Simulating button click in GWT Unit test?

On 06/04/2011 06:51 AM, Ed wrote:
> I have to simulate a button click on a button that is created in a GWT
> Unit test (that extends from GWTTestCase).
> However, it's almost impossible to get a direct reference to the
> button to simulate the click directly on the button event.
>
> The button, however, has a unique id through the HTML tag id property.
> Is there away to find the button element and then simulate the button
> click in a GWT Unit test ?
>
> I am not sure how to do this.
> Finding the element through "Document.get().getElementById("bla")" I
> don't think works as RootPanel.get() doesn't contain the expected
> application elements but rather GWT Junit stuff...? :(
> And then how to simulate a button click on the found element :(...
>
> Please some advice?
> - Ed
>

Create a MouseOutEvent. You'll want to modify to fit your circumstances.
This includes locating "tb".

final Button tb;

/*
* Synthesize and fire an event
*/
final
NativeEvent evt = Document.get().createMouseOutEvent(1 /* detail */
, 0 /* screenX */
, 0 /* screenY */
, 0 /* clientX */
, 0 /* clientY */
, false /* ctrlKey */
, false /* altKey */
, false /* shiftKey */
, false /* metaKey */
, NativeEvent.BUTTON_LEFT /* button */
, null /* relatedTarget */);

tb.getElement().dispatchEvent(evt);

--
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