Mapping ui:field in GWT to generated code
Asked Answered
E

1

7

I'm trying to get some automated UI testing going on a GWT application and I'm having trouble finding a way to track UI elements.

For example, I have the following:

<g:Button text="Submit" ui:field="submitButton" enabled="true" />

which generates:

<button class="gwt-Button" type="button">Submit</button>

Its a compiler error to set both ui:field and id (id is considered deprecated anyway) so the problem is that I have no easy way to select my submit button using something like selenium.

Is anyone aware of a way I can map the

ui:field="sumbitButton"

to the generated HTML?

Emilia answered 8/3, 2011 at 3:56 Comment(0)
E
8

After further investigation I've discovered that you can enable debugIds which are ment for testing purposes. If you add:

<inherits name="com.google.gwt.user.Debug"/>

to your *.gwt.xml file you can then set debugId on your ui elements as such:

<g:Button text="Submit" ui:field="submitButton" enabled="true" debugId="submitButton"/>

and also in the codebehind by using the ensure debug id method

submitButton.ensureDebugId("submitButton");
Emilia answered 9/3, 2011 at 1:23 Comment(4)
Hey. How are you clicking on this button with selenium? I tried few things, and I'm having problems with making selenium click the button!Arabelle
I wasn't using selenium, but since this simply sets the Id on the element you should be able to select it in selenium based on Id.Emilia
Bear in mind that the generated debug id will be gwt-debug-submitButtonHorntail
Put DebugInfo.setDebugIdPrefix("") in your onModuleLoad() to remove the gwt-debug- prefix from all IDs.Goodson

© 2022 - 2024 — McMap. All rights reserved.