Skip to main content



      Home
Home » Eclipse Projects » SWTBot » How to determine button is available or not
How to determine button is available or not [message #716648] Wed, 17 August 2011 21:45 Go to next message
Eclipse UserFriend
Hi~
I want to use SWTBot as nightly automation test tool, but i encountered an issue. In our test, for some case a dialog box with 2 buttons will popup, for some case they will not popup, if dialog popups, we need click on a button and continue. Currently i tried to use if(bot.button("Yes").isVisible()) to determine whether there is dialog box or not, but WidgetNotFoundException came up, anyone knows how to handle this case?
Re: How to determine button is available or not [message #718030 is a reply to message #716648] Tue, 23 August 2011 00:46 Go to previous messageGo to next message
Eclipse UserFriend
On 8/17/11 6:45 PM, Joanna wrote:
> Hi~
> I want to use SWTBot as nightly automation test tool, but i encountered
> an issue. In our test, for some case a dialog box with 2 buttons will
> popup, for some case they will not popup, if dialog popups, we need
> click on a button and continue. Currently i tried to use
> if(bot.button("Yes").isVisible()) to determine whether there is dialog
> box or not, but WidgetNotFoundException came up, anyone knows how to
> handle this case?

For any dialogs or popup windows that come up, a good way to make sure
they have focus is to perform shell.activate() before performing any
further actions on the shell.

-- Ketan
Re: How to determine button is available or not [message #718118 is a reply to message #718030] Tue, 23 August 2011 06:08 Go to previous messageGo to next message
Eclipse UserFriend
In addition to Ketan's advice, I think your test API/code should actually handle and discriminate both cases, but this means that in your test scenarios you know when/if the dialog will pop-up or not.

If not, i.e. if the dialog randomly pops-up during your tests (weird BTW), then you can try the following:


  • Iterates on the SWTBot shells to check if one of them is matching the pop-up dialog title. Something like the below code might work:
    Quote:

    ...
    String name = ...; // YOUR POP_UP DIALOG'S TITLE
    SWTBot bot = ...;
    for (SWTBotShell shell : bot.shells()) {
    if (shell.getText() != null && shell.getText().equals(name)) {
    // HANDLE CASE WHEN DIALOG POPS UP HERE
    ...
    break;
    }
    ...
    }

  • Catch the WidgetNotFoundException and do nothing in the catch block. I am not really in favor of this one as it will delay your test execution, plus you don't know if you enter the catch block because the dialog didn't pop-up or of another reason.


Hope this helps,
Re: How to determine button is available or not [message #721182 is a reply to message #718118] Thu, 01 September 2011 02:38 Go to previous message
Eclipse UserFriend
Thanks Ketan and Benjamin, i will try it~
Previous Topic:Keystrokes on SWTBotShell
Next Topic:How to access to a SWTBotTreeItem CellRenderer?
Goto Forum:
  


Current Time: Sun Jul 13 10:49:51 EDT 2025

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

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

Back to the top