Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » expandNode delays
expandNode delays [message #468499] Wed, 05 August 2009 13:02 Go to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
I have some problems with expandNode needing more time to complete in the
following statement before the select(String) is executed. I've tried
adding in the extra .select().click(), but it still sometimes fails.

bot.tree().expandNode("C").select("C Project").click();

I suppose I could split it up and add an arbitrary wait(1000) after the
expandNode(String), but it seems to me it might be better if
SWTBotTreeItem#expandNode(String) could have some way to determine that
the expansion has completed.

Maybe if the expandNode("String") and select("String") implemented a
waitUntilWidgetAppears, similar to what has already been done for
SWTWorkbenchBot#viewByTitle(String), then we could count on whatever is
the global timeout delay for it to fail, and wouldn't have to put in a
bunch of arbitrary waits(1000) statements.

If we can't do the waitUntilWidgetAppears, maybe we could add in a
SWTBotTreeItem#wait(long) implementation that returns SWTBotTreeItem so we
can do the waits without breaking up the statements, like below.

bot.tree().expandNode("C").wait(1000).select("C Project").click();
Re: expandNode delays [message #472330 is a reply to message #468499] Wed, 05 August 2009 15:36 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
While looking at the expandNode problem, I tried out the recursive
expandNode

bot.tree().expandNode("C1",true).expandNode("Debug").select();

I tried to expand recursively the project explorer view tree for the small
Hello World Mingw C stationery project. I came back after lunch and it
was still executing the statement above in the test. I don't know if
there are circular references in that tree, or if it just has a bunch of
data.

Maybe we should have a version, expandNode(String, boolean, int depth),to
limit the recursion depth.

Anyway, this form is dangerous, but I can see the use for some recursive
form.

I'm also curious why there is no recursive form of expandNode for
SWTBotTreeItem.
Re: expandNode delays [message #477133 is a reply to message #472330] Wed, 05 August 2009 23:38 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
It is quite possible that the UI thread froze up. Would you have any
logs at the time this happened. I doubt a hello world program would have
so much content in it that it is still scratching its head after you
come from lunch.

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr

On 6/8/09 01:06, Jay Norwood wrote:
> While looking at the expandNode problem, I tried out the recursive
> expandNode
>
> bot.tree().expandNode("C1",true).expandNode("Debug").select();
>
> I tried to expand recursively the project explorer view tree for the
> small Hello World Mingw C stationery project. I came back after lunch
> and it was still executing the statement above in the test. I don't know
> if there are circular references in that tree, or if it just has a bunch
> of data.
>
> Maybe we should have a version, expandNode(String, boolean, int
> depth),to limit the recursion depth.
> Anyway, this form is dangerous, but I can see the use for some recursive
> form.
>
> I'm also curious why there is no recursive form of expandNode for
> SWTBotTreeItem.
>
Re: expandNode delays [message #477134 is a reply to message #468499] Wed, 05 August 2009 23:40 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
Wait conditions in expandNode do make sense. Please file a bug and I'll
take a look at it sometime. Patches welcome :)

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr

On 5/8/09 22:32, Jay Norwood wrote:
> I have some problems with expandNode needing more time to complete in
> the following statement before the select(String) is executed. I've
> tried adding in the extra .select().click(), but it still sometimes fails.
> bot.tree().expandNode("C").select("C Project").click();
>
> I suppose I could split it up and add an arbitrary wait(1000) after the
> expandNode(String), but it seems to me it might be better if
> SWTBotTreeItem#expandNode(String) could have some way to determine that
> the expansion has completed.
>
> Maybe if the expandNode("String") and select("String") implemented a
> waitUntilWidgetAppears, similar to what has already been done for
> SWTWorkbenchBot#viewByTitle(String), then we could count on whatever is
> the global timeout delay for it to fail, and wouldn't have to put in a
> bunch of arbitrary waits(1000) statements.
>
> If we can't do the waitUntilWidgetAppears, maybe we could add in a
> SWTBotTreeItem#wait(long) implementation that returns SWTBotTreeItem so
> we can do the waits without breaking up the statements, like below.
>
> bot.tree().expandNode("C").wait(1000).select("C Project").click();
>
Re: expandNode delays [message #478775 is a reply to message #477133] Thu, 06 August 2009 15:13 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
Ketan Padegaonkar wrote:

> It is quite possible that the UI thread froze up. Would you have any
> logs at the time this happened. I doubt a hello world program would have
> so much content in it that it is still scratching its head after you
> come from lunch.

I stopped it several times in the debugger over a several minute time
period, and it was still expanding nodes. All those header files that get
included end up expanding. I'll create a log of the node that is being
expanded.

Anyway, there are cases where you might be dealing with a virtual tree
with generated node information, and so the recursive expand is dangerous
without some limit.
Re: expandNode delays [message #478804 is a reply to message #477134] Thu, 06 August 2009 21:35 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
I looked at the code a little bit, and see that
SWTBotTree.expandNode(String) does have a wait implemented in getTreeItem,
so there is the example.

SWTBotTree.select(String...), needs to be changed to call getTreeItem as a
last resort if its loop fails to find the node.

SWTBotTreeItem code needs to be updated to be like in SWTBotTree for
expandNode and for select, plus duplicate and use the waiting version of
getTreeItem from SWTBotTree.
Re: expandNode delays [message #478833 is a reply to message #478804] Fri, 07 August 2009 03:52 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
I tried that fix, and it got rid of all the flakey failures on expandNode
and select on the tree items. I can run my test now consistently with 0
set for PLAYBACK_DELAY.

I haven't looked at the recursive issue yet.
Re: expandNode delays [message #478837 is a reply to message #478833] Fri, 07 August 2009 04:14 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
As a result of fixing both the expandNode and select so they work with the
built-in waits, I'm able to then use this line below to check that the
executable has finished building in my test case. This gets rid of the
arbitrary 5 second delay that I had stuck in there to give it time to
build, and cut about 3.5 seconds off the single test.

bot.tree().expandNode("C1").expandNode("Debug").select("C1.exe -
[x86/le]");
Re: expandNode delays [message #478851 is a reply to message #478837] Fri, 07 August 2009 05:04 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
Could you share the change so I can add it to SWTBot ?

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr

On 7/8/09 13:44, Jay Norwood wrote:
> As a result of fixing both the expandNode and select so they work with
> the built-in waits, I'm able to then use this line below to check that
> the executable has finished building in my test case. This gets rid of
> the arbitrary 5 second delay that I had stuck in there to give it time
> to build, and cut about 3.5 seconds off the single test.
>
> bot.tree().expandNode("C1").expandNode("Debug").select("C1.exe -
> [x86/le]");
>
Re: expandNode delays [message #478892 is a reply to message #478851] Fri, 07 August 2009 07:41 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
Ok, I did that. I submitted this bug, and attached a zip with my proposed
fixes to it.

The changes also includes a proposed change to sleep(long) so that it can
be used in the chains like
expandNode(String).sleep(10).expandNode(String), which provides a way to
add a longer delay than whatever was the wait loop timeout limit.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=285984
Re: expandNode delays [message #478989 is a reply to message #478837] Fri, 07 August 2009 16:58 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
Jay Norwood wrote:

> As a result of fixing both the expandNode and select so they work with the
> built-in waits, I'm able to then use this line below to check that the
> executable has finished building in my test case. This gets rid of the
> arbitrary 5 second delay that I had stuck in there to give it time to
> build, and cut about 3.5 seconds off the single test.

> bot.tree().expandNode("C1").expandNode("Debug").select("C1.exe -
> [x86/le]");


I was too optimistic about use of the above statements for a file exists
test. There are still some times when the executable doesn't show up in
the tree. Perhaps file system updates are too lazy, or the project
explorer isn't being refreshed often enough.

This version works better, using the sleep, but still fails one of 10
times. That isn't reliable enough.

bot.tree().expandNode("C1").expandNode("Debug").sleep(1000).getTreeItem( "C1.exe
- [x86/le]");

A waiting fileExists(String fullpathname) would be useful, or perhaps a
getFileTreeItem("String") that would do a
bot.tree().contextMenu("Refresh") on the project directory tree prior to
retesting for the expected file.
Re: expandNode delays [message #479012 is a reply to message #478989] Fri, 07 August 2009 21:20 Go to previous messageGo to next message
Kay-Uwe Graw is currently offline Kay-Uwe Graw
Messages: 24
Registered: July 2009
Junior Member
Have a look at the attachment for bug 280641 which contains the class
RefreshForSubnodeCondition which does exactly that, doing a context menu
refresh on a parentnode until a specified subnode appears.

Kay
Re: expandNode delays [message #479034 is a reply to message #479012] Sat, 08 August 2009 08:52 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
Kay-Uwe Graw wrote:

> Have a look at the attachment for bug 280641 which contains the class
> RefreshForSubnodeCondition which does exactly that, doing a context menu
> refresh on a parentnode until a specified subnode appears.

> Kay


Yes, thanks, that looks like it has the potential to provide a solution to
the problem of the tree state update relying on some unknown refresh rate.
I suppose that just fires off an event requesting the refresh. I wonder
if the loop should wait for notification that the refresh event has
completed.

So instead of getFileTreeItem("String"), it should be something like
getTreeItemWithRefresh(String), and use your RefreshForSubnodeCondition.

The "Refresh" item isn't generic to all trees, so I suppose would throw an
exception from your wait loop. Is that how you intend an invalid
refreshContextMenuText to be handled?
Re: expandNode delays [message #479041 is a reply to message #477133] Sat, 08 August 2009 10:13 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
Ketan Padegaonkar wrote:

> It is quite possible that the UI thread froze up. Would you have any
> logs at the time this happened. I doubt a hello world program would have
> so much content in it that it is still scratching its head after you
> come from lunch.


Ok, I'm just getting back to this. I modified expandTreeItem to add some
logging as shown below, and captured the log. I logged it for around 7
minutes after the expand of the hello world project, and it was still
going after logging over 6000 children into a 1MB log. I don't see
anything that goes more than 10 levels deep, so the expansion doesn't
appear to have encountered a recursive loop. There's apparently just a
lot of debug info that is available.

I'll email you the log, if you want it.

Even though this case doesn't seem to have a loop, it is easy to imagine a
tree containing one. For example, any variable expansion tree of a
circular list, or any doubly-linked pair of objects.

I'm not sure it make sense to expand recursively without some limit on
nodes expanded ... maybe a limit on the count of nodes plus a restriction
that processing of any child list stops if any item is not visible.


--------------


private void expandTreeItem(TreeItem node) throws
WidgetNotFoundException {
nestingLevel++;
TreeItem[] items = node.getItems();
log.info(MessageFormat.format("children for level " + nestingLevel + "
:" + node.getText()));
for (TreeItem item : items) {
//node.getChecked();
log.info(MessageFormat.format(" child :"+ item.getText()));

expandNode(new SWTBotTreeItem(item));
}
nestingLevel--;
}
Re: expandNode delays [message #479050 is a reply to message #479034] Sat, 08 August 2009 11:32 Go to previous messageGo to next message
Kay-Uwe Graw is currently offline Kay-Uwe Graw
Messages: 24
Registered: July 2009
Junior Member
If no context menu item exist with the specified text it will throw a
standard WidgetNotFoundException. Of course, the wait condition should be
applied for a parent item with a refresh menu item in its context menu in
the first place and may not be useful for a generic use within the swtbot
classes.

Kay
Re: expandNode delays [message #479061 is a reply to message #477133] Sat, 08 August 2009 13:49 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
Ketan Padegaonkar wrote:

> It is quite possible that the UI thread froze up. Would you have any
> logs at the time this happened. I doubt a hello world program would have
> so much content in it that it is still scratching its head after you
> come from lunch.

I tested the following code inside the loop in
SWTBotTree#expandTreeItem(), which then exits the recursive expansion,
limited to the visible expanded nodes. That seems to me to be a
reasonable limit for this type of testing. It can be speeded up by moving
display and displayBounds calculation outside the loop and based on the
parent node.

Display display = item.getDisplay();
Rectangle displayBounds = display.getBounds();
Rectangle itemBounds = item.getBounds();
if (itemBounds.intersects(displayBounds) == false){
break;
}


One other item that I noticed while working with this ... The recursive
expansion currently expands by level, and expansion of each successive
child level can move other displayed nodes down in the display, and even
out of the display. Seems to me there should be a better full expand
solution without all the ripples.
Re: expandNode delays [message #479133 is a reply to message #479061] Sun, 09 August 2009 13:42 Go to previous messageGo to next message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
Jay Norwood wrote:

> One other item that I noticed while working with this ... The recursive
> expansion currently expands by level, and expansion of each successive
> child level can move other displayed nodes down in the display, and even
> out of the display. Seems to me there should be a better full expand
> solution without all the ripples.


In order to get rid of the recursive expand ripples, turn off display with
a setDisplay(false) during the expansion, then back on afterwards with
setDisplay(true) in the run() of the recursive
expandTree("String",boolean) in SWTBotTree. The modified code for run is:


public SWTBotTreeItem run() {
SWTBotTreeItem item;
try {
item = getTreeItem(nodeText);
item.widget.getParent().setRedraw(false);
expandNode(item);
item.widget.getParent().setRedraw(true);
} catch (WidgetNotFoundException e) {
throw new RuntimeException(e);
}
return item;
}
Re: expandNode delays [message #479220 is a reply to message #479061] Mon, 10 August 2009 06:18 Go to previous messageGo to next message
Kay-Uwe Graw is currently offline Kay-Uwe Graw
Messages: 24
Registered: July 2009
Junior Member
I wouldn't worry too much about how an automatic gui test looks. The point
of an automatic gui test is that you don't have to look at your
application yourself but the test is doing the 'looking'. You should just
look later at the report of the tests.

Kay
Re: expandNode delays [message #479411 is a reply to message #479133] Mon, 10 August 2009 18:04 Go to previous message
Jay Norwood is currently offline Jay Norwood
Messages: 112
Registered: July 2009
Senior Member
One additional improvement to the recursive expand is to turn off the
playback delay duringthe expand, since otherwise the playback delay gets
executed for every node that expands during the recursion, and can get
very long. I've included this in the latest proposal in

https://bugs.eclipse.org/bugs/show_bug.cgi?id=286055




public SWTBotTreeItem run() {
SWTBotTreeItem item;
long oldDelay = SWTBotPreferences.PLAYBACK_DELAY;
SWTBotPreferences.PLAYBACK_DELAY = 0;
try {
item = getTreeItem(nodeText);
item.widget.getParent().setRedraw(false);
expandNode(item);
item.widget.getParent().setRedraw(true);
} catch (WidgetNotFoundException e) {
throw new RuntimeException(e);
}
SWTBotPreferences.PLAYBACK_DELAY = oldDelay;
return item;
}
Previous Topic:Lack of tree collapse
Next Topic:Running SWTBot testcase with ant
Goto Forum:
  


Current Time: Mon Apr 21 03:25:52 EDT 2014

Powered by FUDForum. Page generated in 0.02808 seconds