GWT SimplePager ImageButton testing included in Selenium

We use the GWT provided by SimplePager to provide navigation on a post / page through datasets. We want to check whether we correctly control the enabled state of the Next / Previous buttons. Although SimplePager allows us to specify allowed / disabled images for buttons, the "button" itself is an internal ImageButton class that extends Image , not a button. Therefore, the resulting HTML does not use the Button enabled / disabled attributes, but provides a different inline image for each state.

Is there any reasonable way to detect the inclusion states of the SimplePager navigation button in Selenium?

+7
source share
3 answers

In standard practice, you should create a custom component, for example, the "Image" button. I suggest you use ISFW , which provides the function of creating a custom component that can be used with annotation. In the component, you can specify the behavior according to AUT.

0
source

Record sample code for better formatting.

 public class ImageButton extends Component{ public ImageButtom (String loc){ super(locator); } @Override public boolean isEnabled() { //custom representation!... return this.getAttribute("class").contains("imgdisabled"); //return this.getCssValue("background").contains("imgdisabled"); //return this.getAttribute("src").contains("imgdisabled"); } } 

You can use this component, for example Webelement, on the test page.

 @FindBy(locator="locator") ImageButton prevButton; @FindBy(locator="locator") ImageButton nextButton; 

In test code

 page.prevButton.verifyEnabled(); page.prevButton.assertEnabled(); 
0
source

Looking at the source code of SimplePager, it looks like they are using a generator to create css styles, where the disabled state (and enabled state) has the css class applied to it (they delete this https://code.google.com/p/google- web-toolkit / source / browse / trunk / user / src / com / google / gwt / user / cellview / client / SimplePager.java? r = 9614 ).

So, if you can somehow access the actual set of Resources clients, you can call resources.simplePagerStyle().disabledButton() to get the string, which is the css class for the disabled button, and then you can use it as a locator in selenium. This can be very difficult, because the jvm running your selenium test may not be able to reference the compiled GWT code (i.e. the code that runs when debugging a GWT application).

Alternatively, you can subclass SimplePager instead of using the DEFAULT_RESOURCES client package, pass your own, and then you can control the class name used for the disabled button (creating your own Style class that simply wraps the existing one that you get from the original client package, but add the prefix or something to return value).

This is a bit dirty because the component is completely encapsulated and you are trying to get its insides.

0
source

All Articles