PDA

View Full Version : TreePanel selection with Selenium?



jadrake75
6 Jul 2009, 4:19 PM
Does anyone know how to select a node from a treepanel with Selenium?

I have gotten it to select the "row" in the tree, but I have a click listener setup to filter a table based on tree selection that is not getting fired. I used the DOM inspector/event tracker in Firefox and it appears that it is MOUSE DOWN, MOUSE UP and CLICK that are emitted.


private String getNodeLocator( String text ) {
return"//div[contains(@class,'x-tree3-el')]/span[contains(@class,'x-tree3-node-text') and normalize-space(.)='" + text +"']";
}

public void setNode( String text ) {
...

String locator = getNodeLocator(text);
selenium.mouseDown(locator);
selenium.mouseUp(locator);
selenium.click(locator);
...
}

The_Jackal
28 Jul 2009, 6:12 PM
I wait for the onlick to be added to the tree: http://extjs.com/forum/showthread.php?t=74136

Hope this helps - I'm using Tree, not TreePanel, but I think the theory is the same...

jadrake75
29 Jul 2009, 2:59 PM
I don't have my system in front of me and I will take a look tonight. I should mention... this worked fine when it was a Tree, it was after conversion to a TreePanel (since Tree is deprecated....) ... I have a clumsy temporary workaround. My tree nodes when clicked filter (on selection) the right side. But if you right-click the element it brings up a context menu. This I do have working in Selenium, so I am selecting my "view" link from the context menu..... still ugly (and no end of frustration....)

Thanks for the link to the thread, I'll read through and see if I see something that can apply.

jadrake75
31 Jul 2009, 9:13 PM
Well it turned out the issue was on my end and finally I was able to resolve this. I used the gwt-log "windowLogger" and a big selenium pause to see if my listener was getting called and what the results of the values I needed were.

My code was checking that the click event was not a right-mouse click and that the location of the click was on the node text (and not on the node expansion). This way selecting the expand node did not cause the filter to fire (which performs a query in a separate grid). It turned out, that calling


selenium.click( locator );

effectively invokes the click with location of "0,0", and since my code was checking that the click location was > the location plus width of the joint element (the expand +) ... ie. on the text, the event was never getting fired.

The solution was simply to click with a location offset, such that the click occurs in the text (inside in the span) when in Selenium:


selenium.click( locator, "2,2");

This would also explain for me, while the context menu appeared in the top-left corner of my viewport when run from selenium, since it is probably displaying where the click location was rather than relative to the locator.

Thanks for your help Jackal. I guess I am not the only one using Selenium to help capture regressions and functionality!

-Jason

-Jason

The_Jackal
1 Aug 2009, 5:14 AM
Glad I could contribute. I've had an issue with clicking on nodes to expand them when they are off screen (as Selenium has reduced the size of my window). With tree panels, expanding a off screen node doesn't render the child nodes. Have to work out if this is a bg or not :)

Carl.

jadrake75
1 Aug 2009, 8:57 AM
Good to know. I currently run my app in two modes. Test and "production" (it is my hobby app so my production is just residing on my Linux server in the basement). When Jetty starts in dev or test (ie. from eclipse), I execute code on engine startup which loads a sampling of the production data from which I can safely selenium test against without touching the production data. Only once my selenium tests pass and I check in does Hudson pick it up compile and deploy to the production server. The other benefit here is it forces me to make sure I have tests before I submit (I found I'd use my production data for testing manually elsewise....)

Since I am only using a subset of data I haven't run into scrolling in the treepanel yet. I suppose you could write a selenium routine to scroll the panel if the node is not found and scrolling is present, then check again, and scroll until you can no longer scroll. Kind of ugly, but it might be by design to not add the elements to the DOM until shown (performance reasons). Perhaps they could add a flag to the TreePanel to do this no matter what to assist with test cases.

-Jason

The_Jackal
1 Aug 2009, 1:16 PM
It great you can rely on Selenium in this way! I think for full integration testing webdriver or Selenium is essential. Due to the time it takes to test, I try and avoid calls to "pause" can try to use the Wait class with a condition to be satisfied. So far I have no calls to pause :)

With the tree panel I'm wondering what happens if you call expand all... will off screen nodes not render then? Have to test is when I'm back in the office.

sven
1 Aug 2009, 1:20 PM
Only the holdingcontainer will render. The image/textnodes wont be there. They are only there for visible nodes (for performance reasons)

The_Jackal
1 Aug 2009, 1:22 PM
Also to click on the text in the span I use a click locator like



//div[@id="myTreeId"]/ul/li/div/span/text()[.="TextOfTheNode"]


(I'm not looking at the code, but it's similar to this).

The_Jackal
1 Aug 2009, 2:20 PM
Sven, what happen if I have a tree scrollable panel and I expand all node then the user scolls? Will they see empty nodes?

sven
1 Aug 2009, 2:31 PM
No, they get rendered while scrolling. Take a look at the fasttree example

The_Jackal
2 May 2011, 7:18 PM
Sending an end and then a home key press will render all nodes so then it doesn't matter if the node you want is not on the screen:

selenium.focus("somelocator...");
selenium.keyPress("somelocator...", "35"); // end
selenium.keyPress("somelocator...", "36"); // home