Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Key Press: Enter
Key Press: Enter [message #45050] Wed, 22 July 2009 23:59 Go to next message
Michael Wiederhold is currently offline Michael WiederholdFriend
Messages: 10
Registered: July 2009
Junior Member
Ketan,

I have been writing a test case with SWTBot and one of the requirements is
to type a keyboard shortcut CTRL + SHFT + Enter. I can successfully press
the first two keys, but am unable to press the Enter key because in the
SWT class there is not equivalent for SWT.ENTER. Below are a few lines of
code I have written. Any Suggestions on how I can test the pressing of the
Enter key?

KeyStroke ctrl = KeyStroke.getInstance(SWT.CTRL, 0);
KeyStroke shift = KeyStroke.getInstance(SWT.SHIFT, 0);
//KeyStroke ret = KeyStroke.getInstance(0, SWT.???);
bot.sleep(2000);
//k.pressShortcut(ctrl, shift, ret);

Thanks,
Mike
Re: Key Press: Enter [message #45062 is a reply to message #45050] Thu, 23 July 2009 04:18 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Keystrokes.CR and Keystrokes.LF is what you're looking for.

Some more keystrokes here:

http://github.com/ketan/swtbot/blob/9f2a3beb6dc00e8827fe127e ec589a80bcdfe6b6/org.eclipse.swtbot.swt.finder/src/org/eclip se/swtbot/swt/finder/keyboard/Keystrokes.java

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr


On 23/7/09 05:29, Michael Wiederhold wrote:
> Ketan,
>
> I have been writing a test case with SWTBot and one of the requirements
> is to type a keyboard shortcut CTRL + SHFT + Enter. I can successfully
> press the first two keys, but am unable to press the Enter key because
> in the SWT class there is not equivalent for SWT.ENTER. Below are a few
> lines of code I have written. Any Suggestions on how I can test the
> pressing of the Enter key?
> KeyStroke ctrl = KeyStroke.getInstance(SWT.CTRL, 0);
> KeyStroke shift = KeyStroke.getInstance(SWT.SHIFT, 0);
> //KeyStroke ret = KeyStroke.getInstance(0, SWT.???);
> bot.sleep(2000);
> //k.pressShortcut(ctrl, shift, ret);
>
> Thanks,
> Mike
>
Re: Key Press: Enter [message #485767 is a reply to message #45062] Mon, 14 September 2009 21:29 Go to previous messageGo to next message
M. K. is currently offline M. K.Friend
Messages: 9
Registered: September 2009
Junior Member
Hi, I have a SWTBot test where I open the editor, type in text, and then save the file. The data ends up on one single line. I would like to insert a "press Enter" after each text line in the loop sequence so I end up with 10 records in the file.

I have tried incorporating the suggestion here, but can't seem to get it right. It completely ignores the keystrokes. Could someone please let me know what I'm missing?

SWTBotEditor edit = bot.editorByTitle(dataset);
SWTBotEclipseEditor textEditor = edit.toTextEditor();
KeyStroke enter = KeyStroke.getInstance(SWT.CR, 0);
KeyStroke lf = KeyStroke.getInstance(SWT.LF, 0);
for(int l=1; l<11; l++) {
textEditor.typeText("test line " + l + enter + lf);
}
bot.sleep(5000);
bot.editorByTitle(dataset).saveAndClose();

Thanks,

Michelle
Re: Key Press: Enter [message #485787 is a reply to message #485767] Tue, 15 September 2009 02:06 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
That is incorrect usage of the api. The correct usage would be:

textEditor.typeText("test line " + l + "\n");

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr

On 15/09/09 2:59 AM, M. K. wrote:
> Hi, I have a SWTBot test where I open the editor, type in text, and then
> save the file. The data ends up on one single line. I would like to
> insert a "press Enter" after each text line in the loop sequence so I
> end up with 10 records in the file.
> I have tried incorporating the suggestion here, but can't seem to get it
> right. It completely ignores the keystrokes. Could someone please let me
> know what I'm missing?
>
> SWTBotEditor edit = bot.editorByTitle(dataset);
> SWTBotEclipseEditor textEditor = edit.toTextEditor();
> KeyStroke enter = KeyStroke.getInstance(SWT.CR, 0);
> KeyStroke lf = KeyStroke.getInstance(SWT.LF, 0);
> for(int l=1; l<11; l++) {
> textEditor.typeText("test line " + l + enter + lf);
> }
> bot.sleep(5000);
> bot.editorByTitle(dataset).saveAndClose();
>
> Thanks,
>
> Michelle
>
Re: Key Press: Enter [message #485920 is a reply to message #485787] Tue, 15 September 2009 14:38 Go to previous message
M. K. is currently offline M. K.Friend
Messages: 9
Registered: September 2009
Junior Member
Thanks again for your quick response, Ketan. After I had posted my question I kept trying to get this to work. I found this code was also successful without using the KeyStroke specification:

textEditor.typeText("test line " + l);
textEditor.pressShortcut(SWT.CR, SWT.LF);

Michelle
Previous Topic:Table items background color doesn't work
Next Topic:Is SWTbot supposed to work with Eclipse 3.3.2?
Goto Forum:
  


Current Time: Sat Apr 20 06:10:26 GMT 2024

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

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

Back to the top