Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » bot.waitUntil does not work as expected when running swtbot through ant
bot.waitUntil does not work as expected when running swtbot through ant [message #550686] Wed, 04 August 2010 03:12 Go to next message
No real name is currently offline No real name
Messages: 2
Registered: August 2010
Junior Member
Hi All,

We have a custom Eclipse application. I recently started using SWTBot to test it. When I launch the test from within the workbench, everything works as expected, but when I run the same test using the ant script, I see a difference in behavior.

In the test, I import a project and then select it using the left click button. On selecting the project, there is an upgrade process (custom to my app) which needs to finish before the next line of code is run. In order to achieve that, I use the following code -

bot.viewByTitle("List of Projects").setFocus();

Composite packageExplorerComposite = (Composite) bot.activeView().getWidget();
Tree swtTree = (Tree) bot.widget(widgetOfType(Tree.class), packageExplorerComposite);

SWTBotTree tree = new SWTBotTree(swtTree); SWTBotTree selectProject = tree.select(projectName);

bot.waitUntil(Conditions.widgetIsEnabled(tree.select(project Name)));
tree.select(projectName).expandNode(projectName);
bot.waitUntil(Conditions.widgetIsEnabled(tree.select(project Name).expandNode(projectName)));

This seems to work fine...it waits for the project to load completely before moving on, but when I run the test from the ant script, (I am using the default library.xml that comes with the org.eclipse.swtbot.eclipse.junit4.headless plugin), it looks like it does not wait for the project to finish loading and proceeds to the following code and ends up failing.

Is there something else that needs to be done when calling the test through the ant script?

Thanks in advance.
Re: bot.waitUntil does not work as expected when running swtbot through ant [message #550889 is a reply to message #550686] Wed, 04 August 2010 10:34 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
On 10-08-04 03:12 AM, deepali_pathak@hotmail.com wrote:
> Hi All,
>
> We have a custom Eclipse application. I recently started using SWTBot to
> test it. When I launch the test from within the workbench, everything
> works as expected, but when I run the same test using the ant script, I
> see a difference in behavior.
>
> In the test, I import a project and then select it using the left click
> button. On selecting the project, there is an upgrade process (custom to
> my app) which needs to finish before the next line of code is run. In
> order to achieve that, I use the following code -
> bot.viewByTitle("List of Projects").setFocus();
>
> Composite packageExplorerComposite = (Composite)
> bot.activeView().getWidget();
> Tree swtTree = (Tree) bot.widget(widgetOfType(Tree.class),
> packageExplorerComposite);
> SWTBotTree tree = new SWTBotTree(swtTree); SWTBotTree selectProject =
> tree.select(projectName);
>
> bot.waitUntil(Conditions.widgetIsEnabled(tree.select(project Name)));
> tree.select(projectName).expandNode(projectName);
> bot.waitUntil(Conditions.widgetIsEnabled(tree.select(project
> Name).expandNode(projectName)));
>
> This seems to work fine...it waits for the project to load completely
> before moving on, but when I run the test from the ant script, (I am
> using the default library.xml that comes with the
> org.eclipse.swtbot.eclipse.junit4.headless plugin), it looks like it
> does not wait for the project to finish loading and proceeds to the
> following code and ends up failing.
>
> Is there something else that needs to be done when calling the test
> through the ant script?
>
> Thanks in advance.



First of all, let's clarify a little the code there to make it easier to
understand:

> bot.viewByTitle("List of Projects").setFocus();
>
> Composite packageExplorerComposite = (Composite)
> bot.activeView().getWidget();
> Tree swtTree = (Tree) bot.widget(widgetOfType(Tree.class),
> packageExplorerComposite);
> SWTBotTree tree = new SWTBotTree(swtTree); SWTBotTree selectProject =
> tree.select(projectName);
>
> bot.waitUntil(Conditions.widgetIsEnabled(tree.select(project Name)));
> tree.select(projectName).expandNode(projectName);
> bot.waitUntil(Conditions.widgetIsEnabled(tree.select(project
> Name).expandNode(projectName)));

SWTBotView view = bot.viewByTitle("List of Projects");
view.setFocus();

SWTBotTree tree = view.bot().tree();
tree.select(projectName);

bot.waitUntil(Conditions.widgetIsEnabled(tree));
SWTBotTreeItem projectItem = tree.expandNode(projectName);
bot.waitUntil(Conditions.widgetIsEnabled(projectItem));

Isn't that clearer?

Now, for your actual problem: there isn't any difference for SWTBot
between launching from ant or launching from Eclipse. Hell, SWTBot
doesn't even know how it was launched. The launching part is handled by
Eclipse itself.

That being said, you have to make sure that both configuration are the
same. You can't expect SWTBot to work properly if your configuration
from ant is missing some key point of your workbench launch configuration.

Also, saying:

> it looks like it
> does not wait for the project to finish loading and proceeds to the
> following code and ends up failing

doesn't mean much to me... but I'll try!

So, when you do: tree.select(projectName); you expect your application
to do some upgrade routine on the project, is that correct? So am I
right to believe that you expect the following instruction to wait for
the "upgrade" to finish
(bot.waitUntil(Conditions.widgetIsEnabled(tree));) ? If that's the case,
I suppose it is only a coincidence that it works in the workbench,
because that instruction waits for the tree widget to be enabled, which
it should be if the view is active... or I might be missing some
information to properly help you. Also, from my own experience, I never
encountered a Tree or TreeItem that wasn't enabled...

What's the expected behavior of the application when you select the
project? Does the upgrade run on the UI thread and it freezes the
application (with maybe a progress dialog), or does it run in the
background and the user can continue working with the application? I
(we) need to know what really is going on in your application to
properly help you, because the code you provided seems to me that it
doesn't do much.

One last bit: does the code run on Windows or Linux? The workbench
launch and the ant launch are run on the same OS? Which version of
SWTBot? Which version of Eclipse? These are all information that could
help us help you.

Hope this helps
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: bot.waitUntil does not work as expected when running swtbot through ant [message #550946 is a reply to message #550889] Wed, 04 August 2010 12:34 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 2
Registered: August 2010
Junior Member
Hi Pascal,

Thanks for the reply.

I am new to SWTBot and the code being used could be erroneous. I would look into the configuration settings but
for the other part, yes, when the project is imported and selected, then the upgrade happens. This upgrade runs in the UI thread and there is a progress dialog that comes up. (Am I allowed to attach screen shots?)

What I saw while running from workbench is that the tree.select() (which launches the upgrade in my application) is an aynchronous call.
For my test, I really need it to behave as a synchronous call because whatever is following that depends upon the upgrade to be finished.

I could not find a way to achieve that other than using the bot.waitUntil(Conditions.widgetIsEnabled(projectItem)). But as you are suggesting, if this is not doing what i think it is, then I do not really know how it is working in the workbench.

So, I guess my real problem is to wait for the upgrade (tree.select()) to finish before going on. What would be the best way to achieve that?

Also, the code is running on Windows XP for both the workbench and ant launch. I am using SWTBot for Eclipse 3.5 (Galileo) and JUnit 4.

On a side note, from my workbench, I have the option selected "Run in UI thread". Is this the default when launching from the ant too? I could not find a place in the ant configuration to set this.

Thanks much,
Deepali
Re: bot.waitUntil does not work as expected when running swtbot through ant [message #550968 is a reply to message #550946] Wed, 04 August 2010 13:33 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
On 10-08-04 12:34 PM, deepali_pathak@hotmail.com wrote:
> Hi Pascal,
>
> Thanks for the reply.
>
> I am new to SWTBot and the code being used could be erroneous. I would
> look into the configuration settings but
> for the other part, yes, when the project is imported and selected, then
> the upgrade happens. This upgrade runs in the UI thread and there is a
> progress dialog that comes up. (Am I allowed to attach screen shots?)
>
> What I saw while running from workbench is that the tree.select() (which
> launches the upgrade in my application) is an aynchronous call.
> For my test, I really need it to behave as a synchronous call because
> whatever is following that depends upon the upgrade to be finished.
>
> I could not find a way to achieve that other than using the
> bot.waitUntil(Conditions.widgetIsEnabled(projectItem)). But as you are
> suggesting, if this is not doing what i think it is, then I do not
> really know how it is working in the workbench.
>
> So, I guess my real problem is to wait for the upgrade (tree.select())
> to finish before going on. What would be the best way to achieve that?
>
> Also, the code is running on Windows XP for both the workbench and ant
> launch. I am using SWTBot for Eclipse 3.5 (Galileo) and JUnit 4.
>
> On a side note, from my workbench, I have the option selected "Run in UI
> thread". Is this the default when launching from the ant too? I could
> not find a place in the ant configuration to set this.
>
> Thanks much,
> Deepali

Allright! You were on the good track, but mistakes happen. You did the
good thing by trying to use bot.waitUntil(), but you used the wrong
condition ;)

You see, the call tree.select() returns immediately since it is
asynchrous. You can't use such an expression in a waitUntil expression;
you are not waiting for the expression tree.select() (or it's effects)
to complete. In fact, tree.select() returns a SWTBotTree (the same as
"tree", in fact) and by calling
bot.waitUntil(Conditions.widgetIsEnabled(tree.select(project Name))) as
you first did you are waiting until the widget "tree" is enabled, which
is clearly not your intent. You which to wait until your upgrade process
is done. Fortunately for you, there is a dialog we can use for that;
since the dialog closes when the upgrade is finished, we simply have to
wait until the dialog closes:

bot.waitUntil(shellCloses(bot.activeShell()));

This would do the trick, but only if you're lucky; it might be possible
that the "active shell" is the main shell (Eclipse's) when this line is
called, so you would wait indefinetly. There's plenty of way to remedy
this, such as:
1- bot.waitUntil(shellCloses(bot.shell("Updating...")));

2- bot.waitUntil(shellIsActive("Updating..."));
bot.waitWhile(shellIsActive("Updating..."));

3- bot.waitUntil(shellIsActive("Updating..."));
bot.waitUntil(shellCloses(bot.shell("Updating...")));

4- bot.waitUntil(shellIsActive("Updating..."));
bot.waitUntil(shellCloses(bot.activeShell()));

All are roughly equivalent, but I prefer the first one since it's more
compact. It works because bot.shell() does a kind of implicit
waitUntil(shellIsActive("Updating..."))

> then I do not
> really know how it is working in the workbench.

I'm guessing it might be related to SWTBot's multi-threaded nature. But
I might be wrong.

> On a side note, from my workbench, I have the option selected "Run in UI
> thread". Is this the default when launching from the ant too? I could
> not find a place in the ant configuration to set this.

Hmmmmm, this might explain why it works (or doesn't work with ant) :P
Are you using SWTBot launch configuration or PDE JUnit launch
configuration? If you are using PDE's, this option must be UNCHECKED or
you might run into a deadlock. SWTBot launch configuration simply ignore
this option and always runs in a non-UI thread. This is also the
behavior from ant.
Whichever you are using, uncheck the option and then test if it works
with the workbench launch. If it doesn't work anymore, you got your
reason right here: not the same configuration from ant and workbench.

p.s.: If you are indeed using PDE's and wish to have more information on
why it worked in the workbench, I can provide you with some explanation,
but I don't want to pollute here since it might not be the reason...

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: bot.waitUntil does not work as expected when running swtbot through ant [message #550970 is a reply to message #550968] Wed, 04 August 2010 13:39 Go to previous message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
On 8/4/10 10:33 AM, Pascal Gelinas wrote:

Thanks a lot for the elaborate explanation!

> p.s.: If you are indeed using PDE's and wish to have more information on
> why it worked in the workbench, I can provide you with some explanation,
> but I don't want to pollute here since it might not be the reason...

Since this comes up quite a bit, I've documented it on the FAQ:
http://goo.gl/zpF6 and http://goo.gl/swLj

--
Ketan
http://ketan.padegaonkar.name | http://eclipse.org/swtbot
Previous Topic:Scroll in an editor
Next Topic:What Widget is that?
Goto Forum:
  


Current Time: Thu Aug 21 22:06:33 EDT 2014

Powered by FUDForum. Page generated in 0.01604 seconds