Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » swtBotEclipseEditor.typeText issue
swtBotEclipseEditor.typeText issue [message #38248] Thu, 04 June 2009 19:21 Go to next message
Asif is currently offline AsifFriend
Messages: 11
Registered: July 2009
Junior Member
editor.typeText("file \"f1\"\n"); throws the following exception. Please
see the code given below. I'm Using Eclipse 3.4 with JDK 1.6.

------------------------------------------------------------ ------------------
java.lang.ExceptionInInitializerError
at
org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeCharacte r(Keyboard.java:100)
at
org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Key board.java:89)
at
org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Key board.java:77)
at
org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText.typeT ext(SWTBotStyledText.java:286)
at
org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText.typeT ext(SWTBotStyledText.java:270)
at
org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEdito r.typeText(SWTBotEclipseEditor.java:335)
at
com.sun.jbi.qe.gui.ide.eclipse.helper.SWTBotHelper.editFile( SWTBotHelper.java:184)
at
com.sun.jbi.qe.gui.ide.fuji.test.TestSampleDialog.testEditFi le(TestSampleDialog.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:130)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at
org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main( RemotePluginTestRunner.java:64)
at
org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U ITestApplication.java:123)
at
org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:68)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException: keyboard layout GB not
available.
at
org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getKey boardLayout(KeyboardLayout.java:89)
at
org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getDef aultKeyboardLayout(KeyboardLayout.java:75)
at
org.eclipse.swtbot.swt.finder.keyboard.Keystrokes.<clinit>(Keystrokes.java:110)
... 29 more

------------------------------------------------------------ ------------------
The code is as follows:
fileOpen(projectName, filePath, fileName); //Opens the specified file.
SWTBotEclipseEditor editor = bot.editor(fileName);
editor.navigateTo(1, 0);
bot.sleep(1000);
editor.typeText("file \"f1\"\n");

editor.typeText throws the above exception. Is this a bug in swtBot or
I'm missing any jar files? Any idea?


Thanks
Asif.
Re: swtBotEclipseEditor.typeText issue [message #38283 is a reply to message #38248] Fri, 05 June 2009 03:55 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Asif wrote:

> editor.typeText("file "f1"n"); throws the following exception. Please
> see the code given below. I'm Using Eclipse 3.4 with JDK 1.6.
> Caused by: java.lang.IllegalArgumentException: keyboard layout GB not
> available.

http://github.com/ketan/swtbot/blob/master/org.eclipse.swtbo t.swt.finder.test/src/org/eclipse/swtbot/swt/finder/keyboard /KeyboardLayoutTest.java#L28

Also SWTBotPreferences#KEYBOARD_LAYOUT.

-- Ketan
Re: swtBotEclipseEditor.typeText issue [message #38921 is a reply to message #38283] Mon, 15 June 2009 16:38 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
I have the exact same problem. I'm trying to type in a textbox using
Keyboard keyboard = KeyboardFactory.getDefaultKeyboard(text.widget, null);
keyboard.typeText(typedText);

I have defined my own keyboard layout in my package com.foo.bar, named
EN_CA.keyboard, and I set SWTBotPreferences.KEYBOARD_LAYOUT to
com.foo.bar.EN_CA. When I try to use the keyboard, an
IllegalArgumentException is thrown with the message: keyboard layout
com.foo.bar.EN_CA not available. I have looked deep into the code and
none of the class loader used to locate the resource can resolve my
package name. My test class is also located in com.foo.bar.

I have also tried to set the KEYBOARD_LAYOUT field to EN_CA, but I get
the same error message (minus the package, of course).

I'm using the 2.0.329-dev version under Eclipse 3.4 on Linux and I've
set the native keyboard with setxkbmap ca (which is EN_CA)

Here is the full stack trace:

java.lang.ExceptionInInitializerError
at
org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeCharacte r(Keyboard.java:100)
at
org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Key board.java:89)
at
org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Key board.java:77)
at
com.nuecho.plugin.robot.test.ScenarioUITest.editStepGroup(Sc enarioUITest.java:232)
at
com.nuecho.plugin.robot.test.ScenarioUITest.createDummyScena rio(ScenarioUITest.java:131)
at
com.nuecho.plugin.robot.test.ScenarioUITest.setUp(ScenarioUI Test.java:59)
at junit.framework.TestCase.runBare(TestCase.java:132)
at
org.eclipse.swtbot.swt.finder.SWTBotTestCase.runBare(SWTBotT estCase.java:228)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at
com.nuecho.plugin.framework.swtbot.AbstractUITest.run(Abstra ctUITest.java:369)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at
org.junit.internal.runners.OldTestClassRunner.run(OldTestCla ssRunner.java:76)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:45)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at
org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main( RemotePluginTestRunner.java:64)
at
org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U ITestApplication.java:123)
at
org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:68)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.IllegalArgumentException: keyboard layout
com.nuecho.plugin.robot.test.EN_CA not available.
at
org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getKey boardLayout(KeyboardLayout.java:89)
at
org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getDef aultKeyboardLayout(KeyboardLayout.java:75)
at
org.eclipse.swtbot.swt.finder.keyboard.Keystrokes.<clinit>(Keystrokes.java:110)
... 25 more



Any ideas?

P
Re: swtBotEclipseEditor.typeText issue [message #38946 is a reply to message #38921] Mon, 15 June 2009 19:37 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
On 15/6/09 22:08, Pascal Gelinas wrote:
> I have the exact same problem. I'm trying to type in a textbox using
> Keyboard keyboard = KeyboardFactory.getDefaultKeyboard(text.widget, null);
> keyboard.typeText(typedText);
>
> I have defined my own keyboard layout in my package com.foo.bar, named
> EN_CA.keyboard, and I set SWTBotPreferences.KEYBOARD_LAYOUT to
> com.foo.bar.EN_CA. When I try to use the keyboard, an
> IllegalArgumentException is thrown with the message: keyboard layout
> com.foo.bar.EN_CA not available. I have looked deep into the code and
> none of the class loader used to locate the resource can resolve my
> package name. My test class is also located in com.foo.bar.

It seems the problem is due to the fact that swtbot does not 'see'
packages in your plugin. You need to make your plugin a friend of
swtbot's swt.finder plugin by adding the following in your plugin manifest:

Eclipse-RegisterBuddy: org.eclipse.swtbot.swt.finder

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr
Re: swtBotEclipseEditor.typeText issue [message #38968 is a reply to message #38946] Tue, 16 June 2009 13:30 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Thanks, that solved the issue.

I'm still having problem using the keyboard: whenever I do a key
combination with the ALT key, it fails silently without giving errors.
For example, if I want to type @ on my keyboard, the key combination is
ALT + 2. I have the line @ alt + 2 in my keyboard and I try
keyboard.typeText("@"); All it does is, well, nothing. Altough my other
key combination are recognized, those with alt are never typed. I tried
all 3 keyboard strategies and none works. I don't know if its related,
but Hans Schwaebli made a comment in bug # 273624 claiming that ctrl +
alt + q combination was not working.

I also had another problem with another key combination: shift + <. I
have those two lines in my keyboard file:
> shift + <
< <
When I try to type a > with the AWT strategy, I get an invalid key code
error. It works with the SWT strategy though. I don't think anything
could be done to solve the problem with the AWT strategy, because the
stack trace stops in a native method:
> java.lang.IllegalArgumentException: Invalid key code
> at sun.awt.X11.XRobotPeer.keyPressImpl(Native Method)
> at sun.awt.X11.XRobotPeer.keyPress(XRobotPeer.java:61)
> at java.awt.Robot.keyPress(Robot.java:220)
> at org.eclipse.swtbot.swt.finder.keyboard.AWTKeyboardStrategy.p ressKey(AWTKeyboardStrategy.java:44)
> at org.eclipse.swtbot.swt.finder.keyboard.AbstractKeyboardStrat egy.pressKeys(AbstractKeyboardStrategy.java:56)
> at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.pressKeys(Ke yboard.java:157)
> at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.pressShortcu t(Keyboard.java:123)
> at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeCharacte r(Keyboard.java:100)
> at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Key board.java:89)
> at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Key board.java:77)
> at com.nuecho.plugin.robot.test.ScenarioUITest.editStepGroup(Sc enarioUITest.java:324)
> at com.nuecho.plugin.robot.test.ScenarioUITest.createDummyScena rio(ScenarioUITest.java:201)
> at com.nuecho.plugin.robot.test.ScenarioUITest.setUp(ScenarioUI Test.java:63)
> at junit.framework.TestCase.runBare(TestCase.java:132)
> at org.eclipse.swtbot.swt.finder.SWTBotTestCase.runBare(SWTBotT estCase.java:228)
> at junit.framework.TestResult$1.protect(TestResult.java:110)
> at junit.framework.TestResult.runProtected(TestResult.java:128)
> at junit.framework.TestResult.run(TestResult.java:113)
> at junit.framework.TestCase.run(TestCase.java:124)
> at com.nuecho.plugin.framework.swtbot.AbstractUITest.run(Abstra ctUITest.java:369)
> at junit.framework.TestSuite.runTest(TestSuite.java:232)
> at junit.framework.TestSuite.run(TestSuite.java:227)
> at org.junit.internal.runners.OldTestClassRunner.run(OldTestCla ssRunner.java:76)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:45)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
> at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main( RemotePluginTestRunner.java:64)
> at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U ITestApplication.java:123)
> at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:68)
> at java.lang.Thread.run(Thread.java:595)
>


here is the full keyboard file:
! shift + 1
" shift + 2
/ shift + 3
$ shift + 4
% shift + 5
? shift + 6
& shift + 7
* shift + 8
( shift + 9
) shift + 0
_ shift + -
+ shift + =
: shift + ;
' shift + ,
| shift + #
> shift + <
[ alt + ^
] alt + ¸
{ alt + `
} alt + <
@ alt + 2
\ alt + #
` `
- -
= =
; ;
, ,
.. .
# #
< <
^ ^
¸ ¸
Re: swtBotEclipseEditor.typeText issue [message #38984 is a reply to message #38968] Tue, 16 June 2009 15:28 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
This happens because the strategy may not understand a particular
keycode. All keys need to be translated to keycodes that the OS can
understand.

Certain characters's ascii code directly map to the keycode, alphabets
and numbers on the US keyboard *generally* fall in this category.

There are obviously exceptions to this, the only one I am aware of at
the moment is the backtick(`) which maps to KeyEvent.VK_BACK_QUOTE and
not its own ascii code.

Out of curiosity are you on a canadian french keyboard layout[1] ? And
by Alt key do you mean AltGr -- from wikipedia, this maps to CTRL+ALT[2]?

I'm unfortunately not using that keyboard and may not be able to provide
much useful information, but my feeling is that the keycode being sent
via AWTKeyboardStrategy#pressKey() is something that is incorrect.

Could you also try the following snippet to provide more info:

myTextBox.setFocus();
k = KeyboardFactory.getAWTKeyboard(); // or the other keyboard strategies
k.pressShortcut(SWT.ALT|SWT.CTRL, '2'); // alt gr = CTRL+ALT

[1] - http://en.wikipedia.org/wiki/Keyboard_layout#Canadian_French
[2] - http://en.wikipedia.org/wiki/AltGr_key#History

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


On 16/6/09 19:00, Pascal Gelinas wrote:
> Thanks, that solved the issue.
>
> I'm still having problem using the keyboard: whenever I do a key
> combination with the ALT key, it fails silently without giving errors.
> For example, if I want to type @ on my keyboard, the key combination is
> ALT + 2. I have the line @ alt + 2 in my keyboard and I try
> keyboard.typeText("@"); All it does is, well, nothing. Altough my other
> key combination are recognized, those with alt are never typed. I tried
> all 3 keyboard strategies and none works. I don't know if its related,
> but Hans Schwaebli made a comment in bug # 273624 claiming that ctrl +
> alt + q combination was not working.
>
> I also had another problem with another key combination: shift + <. I
> have those two lines in my keyboard file:
> > shift + <
> < <
> When I try to type a > with the AWT strategy, I get an invalid key code
> error. It works with the SWT strategy though. I don't think anything
> could be done to solve the problem with the AWT strategy, because the
> stack trace stops in a native method:
>> java.lang.IllegalArgumentException: Invalid key code
>> at sun.awt.X11.XRobotPeer.keyPressImpl(Native Method)
>> at sun.awt.X11.XRobotPeer.keyPress(XRobotPeer.java:61)
>> at java.awt.Robot.keyPress(Robot.java:220)
>> at
>> org.eclipse.swtbot.swt.finder.keyboard.AWTKeyboardStrategy.p ressKey(AWTKeyboardStrategy.java:44)
>>
>> at
>> org.eclipse.swtbot.swt.finder.keyboard.AbstractKeyboardStrat egy.pressKeys(AbstractKeyboardStrategy.java:56)
>>
>> at
>> org.eclipse.swtbot.swt.finder.keyboard.Keyboard.pressKeys(Ke yboard.java:157)
>>
>> at
>> org.eclipse.swtbot.swt.finder.keyboard.Keyboard.pressShortcu t(Keyboard.java:123)
>>
>> at
>> org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeCharacte r(Keyboard.java:100)
>>
>> at
>> org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Key board.java:89)
>>
>> at
>> org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Key board.java:77)
>>
>> at
>> com.nuecho.plugin.robot.test.ScenarioUITest.editStepGroup(Sc enarioUITest.java:324)
>>
>> at
>> com.nuecho.plugin.robot.test.ScenarioUITest.createDummyScena rio(ScenarioUITest.java:201)
>>
>> at
>> com.nuecho.plugin.robot.test.ScenarioUITest.setUp(ScenarioUI Test.java:63)
>> at junit.framework.TestCase.runBare(TestCase.java:132)
>> at
>> org.eclipse.swtbot.swt.finder.SWTBotTestCase.runBare(SWTBotT estCase.java:228)
>>
>> at junit.framework.TestResult$1.protect(TestResult.java:110)
>> at junit.framework.TestResult.runProtected(TestResult.java:128)
>> at junit.framework.TestResult.run(TestResult.java:113)
>> at junit.framework.TestCase.run(TestCase.java:124)
>> at
>> com.nuecho.plugin.framework.swtbot.AbstractUITest.run(Abstra ctUITest.java:369)
>>
>> at junit.framework.TestSuite.runTest(TestSuite.java:232)
>> at junit.framework.TestSuite.run(TestSuite.java:227)
>> at
>> org.junit.internal.runners.OldTestClassRunner.run(OldTestCla ssRunner.java:76)
>>
>> at
>> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:45)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>>
>> at
>> org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main( RemotePluginTestRunner.java:64)
>>
>> at
>> org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U ITestApplication.java:123)
>>
>> at
>> org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:68)
>>
>> at java.lang.Thread.run(Thread.java:595)
>>
>
>
> here is the full keyboard file:
> ! shift + 1
> " shift + 2
> / shift + 3
> $ shift + 4
> % shift + 5
> ? shift + 6
> & shift + 7
> * shift + 8
> ( shift + 9
> ) shift + 0
> _ shift + -
> + shift + =
> : shift + ;
> ' shift + ,
> | shift + #
> > shift + <
> [ alt + ^
> ] alt + ¸
> { alt + `
> } alt + <
> @ alt + 2
> \ alt + #
> ` `
> - -
> = =
> ; ;
> , ,
> .. .
> # #
> < <
> ^ ^
> ¸ ¸
Re: swtBotEclipseEditor.typeText issue [message #39146 is a reply to message #38984] Tue, 16 June 2009 17:42 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Kevin Barnes from the SWT team pointed to this bug that you may find
interesting:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=159108

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


On 16/6/09 20:58, Ketan Padegaonkar wrote:
> This happens because the strategy may not understand a particular
> keycode. All keys need to be translated to keycodes that the OS can
> understand.
>
> Certain characters's ascii code directly map to the keycode, alphabets
> and numbers on the US keyboard *generally* fall in this category.
>
> There are obviously exceptions to this, the only one I am aware of at
> the moment is the backtick(`) which maps to KeyEvent.VK_BACK_QUOTE and
> not its own ascii code.
>
> Out of curiosity are you on a canadian french keyboard layout[1] ? And
> by Alt key do you mean AltGr -- from wikipedia, this maps to CTRL+ALT[2]?
>
> I'm unfortunately not using that keyboard and may not be able to provide
> much useful information, but my feeling is that the keycode being sent
> via AWTKeyboardStrategy#pressKey() is something that is incorrect.
>
> Could you also try the following snippet to provide more info:
>
> myTextBox.setFocus();
> k = KeyboardFactory.getAWTKeyboard(); // or the other keyboard strategies
> k.pressShortcut(SWT.ALT|SWT.CTRL, '2'); // alt gr = CTRL+ALT
>
> [1] - http://en.wikipedia.org/wiki/Keyboard_layout#Canadian_French
> [2] - http://en.wikipedia.org/wiki/AltGr_key#History
>
Re: swtBotEclipseEditor.typeText issue [message #39207 is a reply to message #38984] Tue, 16 June 2009 20:32 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Ketan Padegaonkar wrote:

> There are obviously exceptions to this, the only one I am aware of at
> the moment is the backtick(`) which maps to KeyEvent.VK_BACK_QUOTE and
> not its own ascii code.

It seems like most of the special characters don't map their ascii code
to their AWT keycode. For example, # maps to KeyEvent.VK_NUMBER_SIGN (0x208)

> Out of curiosity are you on a canadian french keyboard layout[1] ? And
> by Alt key do you mean AltGr -- from wikipedia, this maps to CTRL+ALT[2]?

I have a standard US layout keyboard but I change the native support to
make the keys map to a canadian french keyboard. And I meant the ALT, I
had no idea about the AltGr. I've changed alt for ctrl + alt in my
keyboard file.

> I'm unfortunately not using that keyboard and may not be able to provide
> much useful information, but my feeling is that the keycode being sent
> via AWTKeyboardStrategy#pressKey() is something that is incorrect.

I took a look in AWTKeyboardStrategy and I think this line is missing in
the static block (in 2.0.0.329-dev):
addModifierKeyMapping(SWT.CTRL | SWT.ALT, KeyEvent.VK_ALT_GRAPH);

without that line, I get an IllegalArgumentException: Could not
understand keystroke CTRL+ALT+

I've taken the liberty to make a local copy of the class on which I
could make some tests. I've added the key mapping (and some more for the
special characters as mentioned above) and it types 2 instead of @. Same
thing happens with the SWT strategy and the Mock fail silently.

> Could you also try the following snippet to provide more info:
>
> myTextBox.setFocus();
> k = KeyboardFactory.getAWTKeyboard(); // or the other keyboard strategies
> k.pressShortcut(SWT.ALT|SWT.CTRL, '2'); // alt gr = CTRL+ALT

All 4 strategies (Mock, SWT, AWT and mine) fail silently, without typing
anything. I'm beginning to suspect a platform specific issue: even when
I use ctrl+alt+2 on my keyboard it doesn't do anything (and AltGr+2
works), and I've asked a colleague that works under windows and the
ctrl+alt works for him. I'm going to do some tests on Windows and see
what happens.

P
Re: swtBotEclipseEditor.typeText issue [message #39238 is a reply to message #39207] Wed, 17 June 2009 05:33 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
I tried typing a '#' using on my standard US mac keyboard, and it seems
to work fine with the defaults.

I've created a high priority bug for this:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=280562

Please add yourself to cc on that bug so I can track this better. The
following information will help:
- swtbot version
- eclipse version
- platform OS/WS/arch
- jdk version

Cheers!

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


On 17/6/09 02:02, Pascal Gelinas wrote:
> Ketan Padegaonkar wrote:
>
>> There are obviously exceptions to this, the only one I am aware of at
>> the moment is the backtick(`) which maps to KeyEvent.VK_BACK_QUOTE and
>> not its own ascii code.
>
> It seems like most of the special characters don't map their ascii code
> to their AWT keycode. For example, # maps to KeyEvent.VK_NUMBER_SIGN
> (0x208)
>
>> Out of curiosity are you on a canadian french keyboard layout[1] ? And
>> by Alt key do you mean AltGr -- from wikipedia, this maps to CTRL+ALT[2]?
>
> I have a standard US layout keyboard but I change the native support to
> make the keys map to a canadian french keyboard. And I meant the ALT, I
> had no idea about the AltGr. I've changed alt for ctrl + alt in my
> keyboard file.
>
>> I'm unfortunately not using that keyboard and may not be able to
>> provide much useful information, but my feeling is that the keycode
>> being sent via AWTKeyboardStrategy#pressKey() is something that is
>> incorrect.
>
> I took a look in AWTKeyboardStrategy and I think this line is missing in
> the static block (in 2.0.0.329-dev):
> addModifierKeyMapping(SWT.CTRL | SWT.ALT, KeyEvent.VK_ALT_GRAPH);
>
> without that line, I get an IllegalArgumentException: Could not
> understand keystroke CTRL+ALT+
>
> I've taken the liberty to make a local copy of the class on which I
> could make some tests. I've added the key mapping (and some more for the
> special characters as mentioned above) and it types 2 instead of @. Same
> thing happens with the SWT strategy and the Mock fail silently.
>
>> Could you also try the following snippet to provide more info:
>>
>> myTextBox.setFocus();
>> k = KeyboardFactory.getAWTKeyboard(); // or the other keyboard strategies
>> k.pressShortcut(SWT.ALT|SWT.CTRL, '2'); // alt gr = CTRL+ALT
>
> All 4 strategies (Mock, SWT, AWT and mine) fail silently, without typing
> anything. I'm beginning to suspect a platform specific issue: even when
> I use ctrl+alt+2 on my keyboard it doesn't do anything (and AltGr+2
> works), and I've asked a colleague that works under windows and the
> ctrl+alt works for him. I'm going to do some tests on Windows and see
> what happens.
>
> P
Re: swtBotEclipseEditor.typeText issue [message #42722 is a reply to message #38248] Fri, 10 July 2009 11:40 Go to previous messageGo to next message
Benjamin Glaser is currently offline Benjamin GlaserFriend
Messages: 17
Registered: July 2009
Junior Member
First I wondered why textbox.typeText("Text") don't works for me.
Now I found this discussion, and I think my problem is the missing
KeyboardLayout DE_DE.

Here is my Error:
------------------------------------------
java.lang.ExceptionInInitializerError
at
org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeCharacte r(Keyboard.java:100)
at
org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Key board.java:89)
at
org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Key board.java:77)
at
org.eclipse.swtbot.swt.finder.widgets.SWTBotText.typeText(SW TBotText.java:92)
at
org.eclipse.swtbot.swt.finder.widgets.SWTBotText.typeText(SW TBotText.java:79)
at
de.metris.workbench.fachwerte.test.gui.EditorTests.floatValu eAendern(EditorTests.java:171)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.junit.internal.runners.TestMethodRunner.executeMethodBod y(TestMethodRunner.java:99)
at
org.junit.internal.runners.TestMethodRunner.runUnprotected(T estMethodRunner.java:81)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected (BeforeAndAfterRunner.java:34)
at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMe thodRunner.java:75)
at
org.junit.internal.runners.TestMethodRunner.run(TestMethodRu nner.java:45)
at
org.junit.internal.runners.TestClassMethodsRunner.invokeTest Method(TestClassMethodsRunner.java:66)
at
org.junit.internal.runners.TestClassMethodsRunner.run(TestCl assMethodsRunner.java:35)
at
org.junit.internal.runners.TestClassRunner$1.runUnprotected( TestClassRunner.java:42)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected (BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunn er.java:52)
at org.junit.internal.runners.CompositeRunner.run(CompositeRunn er.java:29)
at
org.junit.internal.runners.TestClassRunner$1.runUnprotected( TestClassRunner.java:42)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected (BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunn er.java:52)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:45)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at
org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main( RemotePluginTestRunner.java:64)
at
org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U ITestApplication.java:123)
at
org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:68)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.IllegalArgumentException: keyboard layout DE_DE not
available.
at
org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getKey boardLayout(KeyboardLayout.java:89)
at
org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getDef aultKeyboardLayout(KeyboardLayout.java:75)
at
org.eclipse.swtbot.swt.finder.keyboard.Keystrokes.<clinit>(Keystrokes.java:110)
... 33 more
----------------------------------------


Unfortunately I have no idea how to get or create a matching
KeyboardLayout.

Would be great if somebody helps me out.

Thanks
Benjamin
Re: swtBotEclipseEditor.typeText issue [message #42784 is a reply to message #42722] Fri, 10 July 2009 12:27 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Benjamin Glaser wrote:
> First I wondered why textbox.typeText("Text") don't works for me.
> Now I found this discussion, and I think my problem is the missing
> KeyboardLayout DE_DE.
>
> Unfortunately I have no idea how to get or create a matching
> KeyboardLayout.
>
> Would be great if somebody helps me out.
>
> Thanks Benjamin
>

Take the EN_US keyboard bundled with SWTBot as an example to start out.
The keyboard file contains the key sequence you have to type for a
specific character. For example, I think the '@' character is typed with
AltGr + q on a DE keyboard. Another example would be the '"' character
on a FR_CA, which is typed using shift + 2.

However, I would rather suggest you use a standard US keyboard instead
because both SWT and AWT can't reproduce the AltGr key. There is an open
bug in SWT and SWTBot to make this work. See
https://bugs.eclipse.org/bugs/show_bug.cgi?id=280824 and
https://bugs.eclipse.org/bugs/show_bug.cgi?id=280562.

To make use of a standard US keyboard, you need to do two things:
1- Change the native layout of your keyboard. Doing so depends on your
OS: on linux, type in a shell: setxkbmap us. On windows, the language
bar can do this. On a Mac, you'd better ask Ketan :P
2- Change the default keyboard layout in SWTBot. SWTBot tries to guess
the native keyboard layout based on the locale you are on, but it rarely
does a good guess when you change your native support (due to lack of
functionality in SWT). Change the SWTBotPreference#KEYBOARD_LAYOUT to
"EN_US".

You should be set on using the typeText method.

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

*Because performance matters.*
Re: swtBotEclipseEditor.typeText issue [message #42815 is a reply to message #42784] Fri, 10 July 2009 13:42 Go to previous messageGo to next message
Benjamin Glaser is currently offline Benjamin GlaserFriend
Messages: 17
Registered: July 2009
Junior Member
Hi Pascal,

thanks a lot for your great help.
I get it working now!

Because I didn't know how to do step 2 I only did step 1 and that solved
the problem. I only changed the keyboard layout of my OS.

> To make use of a standard US keyboard, you need to do two things:
> 1- Change the native layout of your keyboard. Doing so depends on your
> OS: on linux, type in a shell: setxkbmap us. On windows, the language
> bar can do this. On a Mac, you'd better ask Ketan :P
> 2- Change the default keyboard layout in SWTBot. SWTBot tries to guess
> the native keyboard layout based on the locale you are on, but it rarely
> does a good guess when you change your native support (due to lack of
> functionality in SWT). Change the SWTBotPreference#KEYBOARD_LAYOUT to
> "EN_US".


typeText() with an US keyboard layout helps for now.

But I still wanna know how to do step 2 (change any SWTBotPreferences)
because you wrote almost the same in my other thread.
I have no glue how to do that.
Would be nice if you got the time to explain it to me.

Regards
Benjamin
Re: swtBotEclipseEditor.typeText issue [message #42876 is a reply to message #42815] Fri, 10 July 2009 14:28 Go to previous message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
On 10/7/09 19:12, Benjamin Glaser wrote:

> But I still wanna know how to do step 2 (change any SWTBotPreferences)
> because you wrote almost the same in my other thread.
> I have no glue how to do that.
> Would be nice if you got the time to explain it to me.

See the javadocs for SWTBotPreferences#KEYBOARD_LAYOUT on how to set
your own keyboard preference.

See the test[1] and a sample keyboard layout configuration[2] on how you
can plug in your own layout.

Note that however you may not be able to type all keys depending on the
layout and keyboard strategy you are using because of bugs in SWT and
also AWT :( Drop in a note in such a case and someone could help you
resolve this issue.

[1] -
http://github.com/ketan/swtbot/blob/master/org.eclipse.swtbo t.swt.finder.test/src/org/eclipse/swtbot/swt/finder/keyboard /KeyboardLayoutTest.java
[2] -
http://github.com/ketan/swtbot/tree/master/org.eclipse.swtbo t.swt.finder.test/src/com/foo/bar

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr
Previous Topic:Support of Nebula FormattedText widget
Next Topic:Cant select contextMenu from own plugin
Goto Forum:
  


Current Time: Thu Nov 14 09:02:11 GMT 2024

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

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

Back to the top