Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How to determine button is available or not
How to determine button is available or not [message #716648] Thu, 18 August 2011 01:45 Go to next message
Joanna  is currently offline Joanna
Messages: 12
Registered: May 2011
Junior Member
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 04:46 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
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 10:08 Go to previous messageGo to next message
Benjamin Ratiarisolo is currently offline Benjamin Ratiarisolo
Messages: 16
Registered: January 2010
Location: Paris, France
Junior Member
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,


--
Benjamin Ratiarisolo
IBM ODM Decision Server Rules - Software Developer
IBM Software - France Lab
Re: How to determine button is available or not [message #721182 is a reply to message #718118] Thu, 01 September 2011 06:38 Go to previous message
Joanna  is currently offline Joanna
Messages: 12
Registered: May 2011
Junior Member
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: Mon Sep 22 10:34:42 GMT 2014

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

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