How to simulate function keys F1-F12 in JUnit tests

WindowTester allows you to easily create and run unit tests for every GUI they build. It can also be used to generate system level tests.

Moderators: gnebling, Eric Clayberg, Dan Rubel, keertip, Phil Quitslund

How to simulate function keys F1-F12 in JUnit tests

Postby keico » Fri Feb 04, 2011 6:53 am

Hello,
Does anyone know how to simulate the function keys such as F1-F12 in their WindowTester JUnit tests? If yes, please drop me some hints. Thanks!

-keico
keico
 
Posts: 21
Joined: Wed Jan 05, 2011 7:37 am

Re: How to simulate function keys F1-F12 in JUnit tests

Postby gnebling » Tue Feb 08, 2011 9:24 am

Have you tried using the SWT constants ... (e.g., SWT.F1, etc.)?
gnebling
Moderator
 
Posts: 243
Joined: Tue Aug 22, 2006 7:49 am

Re: How to simulate function keys F1-F12 in JUnit tests

Postby keico » Tue Feb 08, 2011 12:12 pm

Yes. I have tried using the SWT constants. For some unknown reason the SWT.F1-F12s does NOT work at all while other constant such as SWT.DEL just works fine. Please refer to attached code for details. Please let me know how to get around this issue. Thanks very much!

-keico
Attachments
SpinnerTest2.java
Test code
(775 Bytes) Downloaded 10 times
NumberSpinner.java
Source code
(1.67 KiB) Downloaded 10 times
keico
 
Posts: 21
Joined: Wed Jan 05, 2011 7:37 am

Re: How to simulate function keys F1-F12 in JUnit tests

Postby gnebling » Tue Feb 08, 2011 2:28 pm

When your application is running and you press a function key, does it work? In your example clicking F1 doesn't do anything.
gnebling
Moderator
 
Posts: 243
Joined: Tue Aug 22, 2006 7:49 am

Re: How to simulate function keys F1-F12 in JUnit tests

Postby keico » Wed Feb 09, 2011 6:20 am

In the example code, I use a KeyListener to capture all key events. Once a key event gets captured, it simply prints out the corresponding key code to the standard output. As a result, once clicking F1 you should see this output gets printed out:
key: 112

In test code if I use other keys such as SWT.DEL or other characters as 'a', '5' ... as the test runs, same key code get printed out as I click. However, I did not receive any output if I use SWT.F1-12. I believe the function key F1 did not get simulated correctly.
keico
 
Posts: 21
Joined: Wed Jan 05, 2011 7:37 am

Re: How to simulate function keys F1-F12 in JUnit tests

Postby gnebling » Mon Feb 14, 2011 10:14 am

This is a WindowTester limitation, unfortunately. Function keys and other key combinations are not supported in some cases.
gnebling
Moderator
 
Posts: 243
Joined: Tue Aug 22, 2006 7:49 am


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest

cron