Skip to main content



      Home
Home » Eclipse Projects » SWTBot » Difference of click() in the test thread vs. wrapping its execution in syncExec()?
Difference of click() in the test thread vs. wrapping its execution in syncExec()? [message #1410601] Thu, 21 August 2014 03:05 Go to next message
Eclipse UserFriend
This test fails (always):

test() {
  bot.contextMenu("My Menu").click();
  assertTrue(sideEffectOfClickingOnMenu());
}

Wheras this modification seems to work:

test() {
  UIThreadRunnable.syncExec() {
    bot.contextMenu("My Menu").click();
  }
  assertTrue(sideEffectOfClickingOnMenu());
}


What is the difference?

If I add a delay before the assertion the test passes as well:
test() {
  bot.contextMenu("My Menu").click();
  bot.sleep(50);
  assertTrue(sideEffectOfClickingOnMenu());
}
Re: Difference of click() in the test thread vs. wrapping its execution in syncExec()? [message #1410617 is a reply to message #1410601] Thu, 21 August 2014 04:01 Go to previous messageGo to next message
Eclipse UserFriend
When you hit click or whatever UI action, events are sent
asynchronously, just like they are in real life. When you're clicking
manually, it takes some milliseconds before a pop-up is shown as a
response (for example), so it seems immediate to you.
But for a Java program, some milliseconds is far from being immediate,
so that when the next instruction (assert) is run, the event has not
been processed yet, and the state of the application is probably not
changed yet.

That's why checks should be asynchronous as well. I suggest you replace
you assert by a bot.waitUnit(condition) and put your check in condition.
That will asynchronously check for your condition multiple times until
it gets evaluated to true, and if nothing ever happens, it will fail
gracefully similarly to an assert.
Note that since the finders are asynchronous, you can chain most SWTBot
instructions such as 'bot.button("open blah").click();
bot.shell("blah").close()' and bot.shell("blah") won't fail as it will
wait for the widget to appear.

HTH
--
Mickael Istria
My job: http://www.jboss.org/tools
My blog: http://mickaelistria.wordpress.com
My Tweets: http://twitter.com/mickaelistria
Re: Difference of click() in the test thread vs. wrapping its execution in syncExec()? [message #1410631 is a reply to message #1410617] Thu, 21 August 2014 04:49 Go to previous message
Eclipse UserFriend
Thanks, Mickael and sorry if that question was already asked a few posts earlier.

I believe it is a bit of work to get familiar with how UI testing works when switching from pure unit testing...

Mickael Istria wrote on Thu, 21 August 2014 10:01
When you hit click or whatever UI action, events are sent
asynchronously, just like they are in real life. When you're clicking
manually, it takes some milliseconds before a pop-up is shown as a
response (for example), so it seems immediate to you.
But for a Java program, some milliseconds is far from being immediate,
so that when the next instruction (assert) is run, the event has not
been processed yet, and the state of the application is probably not
changed yet.

That's why checks should be asynchronous as well. I suggest you replace
you assert by a bot.waitUnit(condition) and put your check in condition.
That will asynchronously check for your condition multiple times until
it gets evaluated to true, and if nothing ever happens, it will fail
gracefully similarly to an assert.
Note that since the finders are asynchronous, you can chain most SWTBot
instructions such as 'bot.button("open blah").click();
bot.shell("blah").close()' and bot.shell("blah") won't fail as it will
wait for the widget to appear.

HTH
--
Mickael Istria
My job: http://www.jboss.org/tools
My blog: http://mickaelistria.wordpress.com
My Tweets: http://twitter.com/mickaelistria

Previous Topic:Execute async() followed by sync()
Next Topic:metacity sometimes makes SWTBot tests fail in Jenkins
Goto Forum:
  


Current Time: Mon May 12 02:24:40 EDT 2025

Powered by FUDForum. Page generated in 0.03366 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top