niloc132 / gxt-driver

Other
5 stars 7 forks source link

Tree model class doesn't support GwtWidget.find(...) #12

Open PeterWippermann opened 8 years ago

PeterWippermann commented 8 years ago

I noticed that no Finder had been implemented for org.senchalabs.gwt.gwtdriver.gxt.models.Tree. With no specific with-methods, I decided to provide the WebElement:

String componentTabLabel = "Component";
TabPanel leftTabPanel = GwtWidget.find(TabPanel.class, driver).withItem(componentTabLabel).done();
WebElement treeElement = leftTabPanel.getElement().findElement(By.id(ComponentTree.ID_TREE));
Tree componentTree = leftTabPanel.find(Tree.class).withElement(treeElement).done();

. However, this fails early since the generic find-method throws a ClassCastException from GwtWidget.class; line 155: Class<T> finderType = (Class<T>) t.getActualTypeArguments()[0];

This in turn is caused by the abscence of a specific finder. Compare public class Tree extends GwtWidget<GwtWidgetFinder<Tree>> to public class Button extends GwtWidget<ButtonFinder>

I understand to a certain degree that you didn't want to implement the model to full extend, but I think at least the basic methods like find() should work.

niloc132 commented 8 years ago

Good catch. Do consider as a workaround (and also the difference in size/readability/intent) changing

Tree componentTree = leftTabPanel.find(Tree.class).withElement(treeElement).done();

to

Tree componentTree = new Tree(leftTabPanel.getDriver(), treeElement);

or just

Tree componentTree = new Tree(driver, treeElement);

If you already have the root element, calling leftTabPanel.find doesn't make a ton of sense, you aren't going to use that parent except to share its driver anyway.

Additionally, be very careful about using IDs in your gwt code - the entire purpose of this tool is to avoid the development/testing hazards that can come from doing that. If the tree is the primary content of that tab, find the tree as the first Tree inside the tab content.

PeterWippermann commented 8 years ago

Hi @niloc132 , thanks for your advise. But does your answer mean that you don't want to get Tree.find() fixed? :-/

niloc132 commented 8 years ago

This will be fixed, it is definitely a bug. I've heard reports of that generics manipulation failing in other ways, but this is the first time I've seen a reproducible case.

PeterWippermann commented 8 years ago

:+1: :smiley: