Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » [Solved] InputDialog - buttons not found
[Solved] InputDialog - buttons not found [message #509171] Thu, 21 January 2010 10:11 Go to next message
div is currently offline div
Messages: 4
Registered: January 2010
Junior Member
Hi,

I'm trying to access an input dialog (org.eclipse.jface.dialogs.InputDialog) with SWTBot. But the OK / Cancel buttons are not found. Is the input dialog supported by SWTBot?

What I tried:
bot.button("OK").click();

Exception:
Caused by: org.eclipse.swtbot.swt.finder.widgets.TimeoutException: Timeout after: 5000 ms.: Could not find widget matching: (of type 'Button' and with mnemonic 'OK' and with style 'SWT.PUSH')


I also tried:
SWTBotButton button = new SWTBotButton((Button) bot.widget(withMnemonic("OK")));
button.click();

But that caused the exception:
Caused by: org.eclipse.swtbot.swt.finder.widgets.TimeoutException: Timeout after: 5000 ms.: Could not find widget matching: with mnemonic 'OK'


The InputDialog is invoked like this:

InputDialog x = new InputDialog(parentshell, title, message, initVal, null);
x.open();
(the parentshell is the global shell (IWorkbenchWindow.getShell()))

Any ideas or hints what may be the cause of this?
Thanks!

[Updated on: Mon, 25 January 2010 03:28]

Report message to a moderator

Re: InputDialog - buttons not found [message #509265 is a reply to message #509171] Thu, 21 January 2010 09:28 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
div0@gmx.net wrote:
> Hi,
>
> I'm trying to access an input dialog
> (org.eclipse.jface.dialogs.InputDialog) with SWTBot. But the OK / Cancel
> buttons are not found. Is the input dialog supported by SWTBot?
>
> What I tried:
> bot.button("OK").click();
>
> Exception:
> Caused by: org.eclipse.swtbot.swt.finder.widgets.TimeoutException:
> Timeout after: 5000 ms.: Could not find widget matching: (of type
> 'Button' and with mnemonic 'OK' and with style 'SWT.PUSH')
>
>
> I also tried:
> SWTBotButton button = new SWTBotButton((Button)
> bot.widget(withMnemonic("OK"))); button.click();
>
> But that caused the exception: Caused by:
> org.eclipse.swtbot.swt.finder.widgets.TimeoutException: Timeout after:
> 5000 ms.: Could not find widget matching: with mnemonic 'OK'
>
>
> The InputDialog is invoked like this:
>
> InputDialog x = new InputDialog(parentshell, title, message, initVal,
> null);
> x.open();
> (the parentshell is the global shell (IWorkbenchWindow.getShell()))
>
> Any ideas or hints what may be the cause of this?
> Thanks!
>

I do think they are supported, since they are not native dialog. It's
only a custom made shell with some widget in it. Are you sure that the
button's label is "OK"? I'd try "Ok" just to be sure; I think the 'K'
should be lower-case. If that doesn't solve the problem, I'd try this to
see if you get a WidgetNotFound:

SWTBotShell shell = bot.shell(title);

if this fails, then its probably that your input dialog is not open. If
this doesn't fail, I'd do this:

bot.widget(allOf(widgetOfType(Button.class), withMnemonic("OK")));

Then again, if you try this make sure you have the good mnemonic. If
this doesn't work... well it should work :P

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

*Because performance matters.*
Re: InputDialog - buttons not found [message #509289 is a reply to message #509171] Thu, 21 January 2010 15:53 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
You may want to try:

bot.shell("Your input dialog title").activate();

before clicking on the button. If swtbot tries to find the button before
the input dialog opens, then it's looking for the button in the current
active shell.

-- Ketan

On 1/21/10 7:11 AM, div0@gmx.net wrote:
> Hi,
>
> I'm trying to access an input dialog
> (org.eclipse.jface.dialogs.InputDialog) with SWTBot. But the OK / Cancel
> buttons are not found. Is the input dialog supported by SWTBot?
>
> What I tried:
> bot.button("OK").click();
>
> Exception:
> Caused by: org.eclipse.swtbot.swt.finder.widgets.TimeoutException:
> Timeout after: 5000 ms.: Could not find widget matching: (of type
> 'Button' and with mnemonic 'OK' and with style 'SWT.PUSH')
>
>
> I also tried:
> SWTBotButton button = new SWTBotButton((Button)
> bot.widget(withMnemonic("OK"))); button.click();
>
> But that caused the exception: Caused by:
> org.eclipse.swtbot.swt.finder.widgets.TimeoutException: Timeout after:
> 5000 ms.: Could not find widget matching: with mnemonic 'OK'
>
>
> The InputDialog is invoked like this:
>
> InputDialog x = new InputDialog(parentshell, title, message, initVal,
> null);
> x.open();
> (the parentshell is the global shell (IWorkbenchWindow.getShell()))
>
> Any ideas or hints what may be the cause of this?
> Thanks!
>
Re: InputDialog - buttons not found [message #509357 is a reply to message #509265] Fri, 22 January 2010 03:52 Go to previous messageGo to next message
div is currently offline div
Messages: 4
Registered: January 2010
Junior Member
Hi Pascal, hi Ketan,

thanks for your replies. I think the problem has to do with the shell. I tried to get the shell (SWTBotShell shell = bot.shell(title)) but got a widget not found exception.
I also added bot.activeShell().getText() right before and after the command that opens die InputDialog. The active shell was always the same one (the main RCP workbench shell).

When I iterate over bot.shells() I can't find the InputDialog shell either. It's strange, because I see the dialog on screen, so it has to be there somewhere Confused

Regards,
Re: InputDialog - buttons not found [message #509500 is a reply to message #509171] Fri, 22 January 2010 11:09 Go to previous messageGo to next message
div is currently offline div
Messages: 4
Registered: January 2010
Junior Member
I got the chronology wrong. The commands to click a button were not executed while the InputDialog was active.

from my test class:

System.out.println("Active shell: "+bot.activeShell().getText());
SWTBotGefEditor editor = bot.gefEditor("Editor");
editor.activateTool("Part1");
editor.mouseMoveLeftClick(200, 200);
System.out.println("Active shell: "+bot.activeShell().getText());
bot.button("OK").click();

The InputDialog is shown when a part is droped to the editor.
The second println is executed not until the InputDialog is closed (manually).
So the bot.button(...).click(); commands are not executed while the dialog is active. The dialog blocks the test somehow.
Re: InputDialog - buttons not found [message #509513 is a reply to message #509500] Fri, 22 January 2010 06:38 Go to previous messageGo to next message
Mariot Chauvin is currently offline Mariot Chauvin
Messages: 174
Registered: July 2009
Senior Member
Hi,

mouseMoveLeftClick should launch the click asynchronously :

public void mouseMoveLeftClick(final int xPosition, final int yPosition) {
UIThreadRunnable.asyncExec(new VoidResult() {
...
...
}
}

The modification was made the 10 December (revision 452), so maybe you use an older version of SWTBot ?

Regards,
Mariot

div a écrit :
> I got the chronology wrong. The commands to click a button were not
> executed while the InputDialog was active.
>
> from my test class:
>
> System.out.println("Active shell: "+bot.activeShell().getText());
> SWTBotGefEditor editor = bot.gefEditor("Editor");
> editor.activateTool("Part1");
> editor.mouseMoveLeftClick(200, 200); System.out.println("Active shell:
> "+bot.activeShell().getText()); bot.button("OK").click();
>
> The InputDialog is shown when a part is droped to the editor.
> The second println is executed not until the InputDialog is closed
> (manually).
> So the bot.button(...).click(); commands are not executed while the
> dialog is active. The dialog blocks the test somehow.
Re: InputDialog - buttons not found [message #509725 is a reply to message #509171] Mon, 25 January 2010 03:28 Go to previous message
div is currently offline div
Messages: 4
Registered: January 2010
Junior Member
Hi Mariot,

thanks a lot! I've used rev 433. I just updated to 467 and it works like a charm!

Regards,
Previous Topic:test org.rcpmail using ant not work
Next Topic:PressShortcut
Goto Forum:
  


Current Time: Wed Aug 20 04:59:54 EDT 2014

Powered by FUDForum. Page generated in 0.02479 seconds