Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Why is a menu item disabled when using SWTBot?
Why is a menu item disabled when using SWTBot? [message #558874] Tue, 14 September 2010 17:00 Go to next message
Mohsen Vakilian is currently offline Mohsen VakilianFriend
Messages: 6
Registered: May 2010
Junior Member
I've posted a question about SWTBot ( http://stackoverflow.com/questions/3706225/why-is-a-menu-ite m-disabled-when-using-swtbot) with the same title as this thread to stackoverflow. Please feel free to either reply to this message or post your answers on stackoverflow.com.
icon5.gif  Re: Why is a menu item disabled when using SWTBot? [message #559514 is a reply to message #558874] Thu, 16 September 2010 23:26 Go to previous messageGo to next message
Mohsen Vakilian is currently offline Mohsen VakilianFriend
Messages: 6
Registered: May 2010
Junior Member
The following is my piece of code that tries to invoke the extract method refactoring. Please let me know if you find anything wrong with the way I'm having SWTBot invoke this refactoring. The whole test class is available at our repository.

@Test
public void shouldExtractMethod() throws Exception {
	SWTBotEclipseEditor editor= bot.editorByTitle(TEST_NAME + ".java").toTextEditor();
	editor.setFocus();
	// editor.selectLine(5);
	editor.selectRange(5, 2, 37 - 9);
	System.out.println(editor.getSelection());
	System.out.println(editor.cursorPosition());
	SWTBotMenu extractMethodMenuItem= bot.menu("Refactor").menu("Extract Method...");
	//FIXME: The following assertion fails.
	assertTrue(extractMethodMenuItem.isEnabled());
	extractMethodMenuItem.click();
	// editor.pressShortcut(Keystrokes.SHIFT, Keystrokes.ALT,
	// KeyStroke.getInstance("M"));
	bot.shell("Extract Method").activate();
	bot.textWithLabel("Method name:").setText("m");
	bot.button("OK").click();
	bot.sleep(200000);
}
Re: Why is a menu item disabled when using SWTBot? [message #559516 is a reply to message #558874] Thu, 16 September 2010 23:52 Go to previous messageGo to next message
Gabriel Petrovay is currently offline Gabriel PetrovayFriend
Messages: 42
Registered: July 2009
Member
Mohsen Vakilian wrote on Tue, 14 September 2010 13:00
I've posted a question about SWTBot ( http://stackoverflow.com/questions/3706225/why-is-a-menu-ite m-disabled-when-using-swtbot) with the same title as this thread to stackoverflow. Please feel free to either reply to this message or post your answers on stackoverflow.com.


Hi,

I also posted something similar (some options on property pages are disabled) here: http://www.eclipse.org/forums/index.php?t=msg&th=175593
Re: Why is a menu item disabled when using SWTBot? [message #559553 is a reply to message #558874] Fri, 17 September 2010 07:26 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

are you sure that your menu shouldn't be disabled?
You can check the activeWhen option on the menu/handler.
On the screenshot is the menu really disabled?

regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
icon5.gif  Re: Why is a menu item disabled when using SWTBot? [message #559726 is a reply to message #559553] Fri, 17 September 2010 17:16 Go to previous messageGo to next message
Mohsen Vakilian is currently offline Mohsen VakilianFriend
Messages: 6
Registered: May 2010
Junior Member
Yes, I'm sure the menu item shouldn't be disabled, because when I follow the script manually, the menu item is enabled.

I've uploaded the screenshot taken by SWTBot at http://i51.tinypic.com/annb75.jpg

SWTBot doesn't open the menus. So, we cannot tell from the screenshot if the "extract method" refactoring is enabled. But, the failure of the following assertion shows that this menu item is actually disabled.

assertTrue(extractMethodMenuItem.isEnabled());
Re: Why is a menu item disabled when using SWTBot? [message #559759 is a reply to message #559514] Fri, 17 September 2010 22:52 Go to previous messageGo to next message
Mohsen Vakilian is currently offline Mohsen VakilianFriend
Messages: 6
Registered: May 2010
Junior Member
Just wanted to mention that our SWTBot test has moved to a new location. So, if you need to take a look at the whole source code to debug it, please refer to the new location.
Re: Why is a menu item disabled when using SWTBot? [message #630466 is a reply to message #559726] Sat, 02 October 2010 23:52 Go to previous messageGo to next message
Mohsen Vakilian is currently offline Mohsen VakilianFriend
Messages: 6
Registered: May 2010
Junior Member
We haven't heard back from anyone about ways to troubleshoot our problem. So, we decided to update you about our progress.

We've been able to fire other refactorings like Extract Constant and Inline constant using SWTBot.

We believe that the problem with invoking the Extract Method refactoring through SWTBot is that it's the only (AFAIK) refactoring that has an enabled/disabled state from the Refactor menu. It tries to check if something is actually selected in the text editor before it enables itself from the menu. Somehow the way SWTBot selects the text in the editor does not communicate it back properly to the Extract Method action item. We believe that this is the problem.
Re: Why is a menu item disabled when using SWTBot? [message #631106 is a reply to message #630466] Wed, 06 October 2010 08:29 Go to previous messageGo to next message
Petar Petrov is currently offline Petar PetrovFriend
Messages: 10
Registered: July 2009
Junior Member
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

> We haven't heard back from anyone about ways to troubleshoot our
> problem. So, we decided to update you about our progress.
>
> We've been able to fire other refactorings like Extract Constant and
> Inline constant using SWTBot.
>
> We believe that the problem with invoking the Extract Method
> refactoring through SWTBot is that it's the only (AFAIK) refactoring
> that has an enabled/disabled state from the Refactor menu. It tries to
> check if something is actually selected in the text editor before it
> enables itself from the menu. Somehow the way SWTBot selects the text
> in the editor does not communicate it back properly to the Extract
> Method action item. We believe that this is the problem.
>
Re: Why is a menu item disabled when using SWTBot? [message #631238 is a reply to message #631106] Wed, 06 October 2010 15:51 Go to previous message
Eclipse UserFriend
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
Previous Topic:Direct Edit a GEF edit part with TextFlow
Next Topic:how to click a Coolbar item in SWTbot
Goto Forum:
  


Current Time: Thu Apr 25 00:47:01 GMT 2024

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

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

Back to the top