|
|
|
|
|
|
|
|
Re: Why is a menu item disabled when using SWTBot? [message #631238 is a reply to message #631106] |
Wed, 06 October 2010 11:51  |
Eclipse User |
|
|
|
Originally posted by: nchen.illinois.edu
On 2010-10-06 03:29:17 -0500, Petar Petrov said:
> Hello Mohsen,
>
> SWTBotEclipseEditor.selectRange() and selectLine() methods are
> asynchronous so you should have a wait condition immediately after the
> select which checks for the cursor position before doing anything else
> (like clicking a context menu) - the cursor should be positioned at the
> beginning of the selection. An example code from one of our tests:
>
> programEditor.selectLine(3);
> waitForCursorPosition(programEditor, 3, 0);
> programEditor.pressShortcut(Keystrokes.DELETE);
>
> Thanks!
> Petar P
Hi Petar
Thanks for the response. We have tried it (and maybe I'm doing
something wrong below) but that still does not allow the Extract Method
refactoring to be invoked. As Mohsen mentioned, this is the only
refactoring that we have encountered so far that cannot be selected
using the way we have below.
Here is the relevant code snippet:
@Override
protected void prepareRefactoring() {
final SWTBotEclipseEditor editor= bot.editorByTitle(TEST_FILE_NAME +
".java").toTextEditor();
// Extract Method Refactoring
editor.setFocus();
final int cursorLinePosition= 5;
final int cursorColumnBeginPosition= 8;
int cursorColumnEndPosition= 36;
editor.selectRange(cursorLinePosition, cursorColumnBeginPosition,
cursorColumnEndPosition - cursorColumnBeginPosition);
DefaultCondition condition= new DefaultCondition() {
@Override
public boolean test() throws Exception {
return editor.cursorPosition().line == cursorLinePosition;
}
@Override
public String getFailureMessage() {
return "Cannot update cursor position in editor";
}
};
bot.waitUntil(condition, 5000, 100);
System.out.println("Cursor position:" + editor.cursorPosition());
SWTBotMenu refactorMenu= bot.menu("Refactor");
assertTrue(refactorMenu.isEnabled());
SWTBotMenu extractMethodMenuItem= refactorMenu.menu("Extract Method...");
assertTrue(extractMethodMenuItem.isEnabled());
extractMethodMenuItem.click();
}
The System.out.println("Cursor position:" + editor.cursorPosition());
shows that the cursor is at the right position but the
assertTrue(extractMethodMenuItem.isEnabled()) statement still fails.
Am I using the waitUntil(...) method wrongly?
Thank you.
--
Nick Chen
|
|
|
Powered by
FUDForum. Page generated in 0.10892 seconds