Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Issue in waiting for tree expansion(Not able to wait during tree expansion)
Issue in waiting for tree expansion [message #635771] Wed, 27 October 2010 23:47 Go to next message
Ullas is currently offline Ullas
Messages: 10
Registered: September 2010
Location: Bangalore
Junior Member
Hi,

In my UI automation test, I wanted to have wait conditions for a tree expansion. My UI test progress thru expanding a tree structure and its sub nodes. A proper wait has to be provided in each expansion of node since it connects to a backend server to fetch the subnodes. So here I am trying alternate of sleep() command which is waitUntil(). But its not working for me. Please find below the syntax.

-------------
treeItem1.expand();

//sleep();

bot.waitUntil(new WaitForItemExpansion(treeItem1), 15000);

//bot.waitUntil(Conditions.widgetIsEnabled(treeItem1.getNode (0)), 15000);

swtLogger.info ("Folder expanded");
---------------

Here, as an alternate of sleep(), I tried the command in 4th line which is not working. I am waiting till I find a subnode in position 0. What is wrong here?

Then I tried to create a class WaitForItemExpansion which implements ICondition and then the test method of this class has the below syntax.

@Override
public boolean test() throws Exception {

//return treeItem1.isExpanded();

if (treeItem1.getNode(0)!= null)
return true;
else
return false;
}

Though the waitUntil() is executing the ICondition.test by checking the return boolean of isExpanded() or getNode(0) which I can see while debugging mode, the test simply NOT waiting when I execute the script in normal mode.

Please could you let me know what is wrong with this? Please share your thoughts if you have implemented the waitUntil() while expanding a tree.
Re: Issue in waiting for tree expansion [message #636652 is a reply to message #635771] Tue, 02 November 2010 06:55 Go to previous messageGo to next message
Tim S is currently offline Tim S
Messages: 7
Registered: August 2010
Junior Member
What actually happens behind the scenes when you use waitUntil() is that the test() method of your Condition object is called repeatedly until it returns true. So the first call to test() will probably fail, but one of the next calls should succeed.

Checking tree nodes in particular is quite tricky as I noticed from experience. If you expand the node too early, you may end up with an expanded node that has no child nodes, and even if nodes are added to it by your backend they will not be seen.

What I do to make sure you get your node in a determined state is the following:
boolean test() {
  if (item.select().isExpanded())
    item.collapse();
  item.expand();

  // fetch items here
}

This will first collapse the node if necessary, then expand it again.
Re: Issue in waiting for tree expansion [message #637445 is a reply to message #636652] Fri, 05 November 2010 09:27 Go to previous messageGo to next message
Mariot Chauvin is currently offline Mariot Chauvin
Messages: 174
Registered: July 2009
Senior Member
Thanks for the tip.
Could you contribute this to the wiki ?

Mariot


Le 02/11/2010 11:55, Tim S a écrit :
> What actually happens behind the scenes when you use waitUntil() is that
> the test() method of your Condition object is called repeatedly until it
> returns true. So the first call to test() will probably fail, but one of
> the next calls should succeed.
>
> Checking tree nodes in particular is quite tricky as I noticed from
> experience. If you expand the node too early, you may end up with an
> expanded node that has no child nodes, and even if nodes are added to it
> by your backend they will not be seen.
>
> What I do to make sure you get your node in a determined state is the
> following:
>
> boolean test() {
> if (item.select().isExpanded())
> item.collapse();
> item.expand();
>
> // fetch items here
> }
>
> This will first collapse the node if necessary, then expand it again.
Re: Issue in waiting for tree expansion [message #637679 is a reply to message #637445] Mon, 08 November 2010 05:23 Go to previous messageGo to next message
Tim S is currently offline Tim S
Messages: 7
Registered: August 2010
Junior Member
^^ I added it to the snippets page.
Re: Issue in waiting for tree expansion [message #637879 is a reply to message #637679] Tue, 09 November 2010 04:06 Go to previous messageGo to next message
Ullas is currently offline Ullas
Messages: 10
Registered: September 2010
Location: Bangalore
Junior Member
Hi Tim

Can you please elaborate your solution (the java code) in the test () method which I need to write when using WaitUntil(). Or where did you place this in the snippet page? whats the heading name?

Regards,
Ullas

[Updated on: Tue, 09 November 2010 04:07]

Report message to a moderator

Re: Issue in waiting for tree expansion [message #639442 is a reply to message #635771] Tue, 16 November 2010 09:57 Go to previous messageGo to next message
Tim S is currently offline Tim S
Messages: 7
Registered: August 2010
Junior Member
It's at the bottom of the snippets page.
Re: Issue in waiting for tree expansion [message #645279 is a reply to message #639442] Thu, 16 December 2010 07:39 Go to previous messageGo to next message
Ullas is currently offline Ullas
Messages: 10
Registered: September 2010
Location: Bangalore
Junior Member
Hi Tim,

I tried the above piece of code in my SWT Bot script and its seems it failing to wait during the tree expansion. Please find below the code,

treeItem1.expand(); //Folder expand
sleep(15000);

here I am trying to replace sleep with:

bot.waitUntil(new WaitForItemExpansion(treeItem1), 15000)

The class WaitForItemExpansion has the override method test as,

@Override
public boolean test() throws Exception {

if (treeNodeItem.select().isExpanded()) {
treeNodeItem.collapse();
treeNodeItem.expand();
return treeNodeItem.getItems().length > 0;
}
return false;
}

Could you let me know what is wrong with this?

Regards,
Ullas
Re: Issue in waiting for tree expansion [message #647466 is a reply to message #645279] Thu, 06 January 2011 10:11 Go to previous messageGo to next message
Tim S is currently offline Tim S
Messages: 7
Registered: August 2010
Junior Member
Ullas,

your code in test() differs from mine. It should be:
public boolean test() throws Exception {
  if (treeNodeItem.select().isExpanded())
    treeNodeItem.collapse();
  treeNodeItem.expand();
  return treeNodeItem.getItems().length > 0;
}

Note that there's no curly bracket after the if, and there's only 1 return statement.
Re: Issue in waiting for tree expansion [message #818962 is a reply to message #647466] Mon, 12 March 2012 06:17 Go to previous message
Roy Wood is currently offline Roy Wood
Messages: 4
Registered: March 2012
Junior Member
Some form of waitUntilRefresh for views would make life so so much easier.
Previous Topic:checkbox in table
Next Topic:SWTBotTreeItem#select() is not working as it should?
Goto Forum:
  


Current Time: Wed Jul 23 16:18:25 EDT 2014

Powered by FUDForum. Page generated in 0.04118 seconds