`
longgangbai
  • 浏览: 7338856 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

SWTbot键盘事件

阅读更多

 官方地址:

http://wiki.eclipse.org/SWTBot/Keyboard_Layouts

Keyboard Layouts in SWTBot

Keyboard strategies

SWTBot can send keyboard events using different strategies:

These different strategies are made available because the keyboard handling is very different depending on the native widget toolkit, keyboard layout and operating system / JRE / SWT version. Not all strategies work in all cases, see KeyboardTest & non EN keyboards to learn more about the reasons why different strategies are provided.

Keyboard layouts

The Keyboard strategies need to send events with key codes, not with characters. For example, for a QWERTY/Z keyboard layout, to type the character '!', you need to press "SHIFT+1" and these events will be generated:

  • KeyDown Shift
  • KeyDown 1
  • KeyUp 1
  • KeyUp Shift

This effectively closely simulates a normal human being typing at a keyboard. In order to configure SWTBot to work with various keyboard layouts, SWTBot contains '.keyboard' files which define a mapping from characters to keys combinations, for example the character '!' maps to the keystrokes 'SHIFT+1' (on a US keyboard). This mapping is different depending on the keyboard layout of the system executing the tests. SWTBot includes some keyboard layouts, but the layout for your keyboard may be not available as of now. Please read further in case your layout is unavailable.

Keyboard configuration

By default, SWTBot uses the AWT keyboard strategy. This can be configured using the system property "org.eclipse.swtbot.keyboard.strategy" or the variableSWTBotPreferences#KEYBOARD_STRATEGY.

Creating keyboard layouts

If your keyboard is missing, please file a bug for SWTBot in Bugzilla. Please mention the country code and operation system.

The keyboard layout is automatically detected from the system. To define the keyboard layout explicitly, you can set the system property "org.eclipse.swtbot.keyboard.layout" or set the variable SWTBotPreferences#KEYBOARD_LAYOUT.

The value of the keyboard layout property should be of the form [package.name.][MAC_][upper-case-two-character-language-code][upper-case-two-character-country-code]. e.g.,

  • com.foo.bar.DE_DE for a German keyboard in Germany
  • com.foo.bar.MAC_FR_FR for a French keyboard on a Mac in France
  • com.foo.bar.MAC_FR_CA for a French keyboard on a Mac in Canada

If the package name is omitted, the layout is loaded from the SWTBot package org.eclipse.swtbot.swt.finder.keyboard. The prefix "MAC_" marks keyboard layouts for Mac keyboards.

Note that on systems that use a Dvorak layout, the "country" code is actually replaced by "DVORAK", hence:

  • com.foo.bar.MAC_EN_DVORAK for a English Dvorak keyboard on a Mac

Keyboard layouts can be created using the KeyboardLayoutGenerator class in the 'org.eclipse.swtbot.swt.finder.test' bundle. This class is not packaged with SWTBot, you will need to download this from the SWTBot source repository.

To create keyboard mappings for your keyboard:

  • Checkout the bundle 'org.eclipse.swtbot.swt.finder.test'
  • Change method Keys#specialChars() for your keyboard.
  • Execute KeyboardLayoutGenerator, this will generate a file 'keyboard.layout' containing keyboard mappings.
  • Execute KeyboardLayoutFilter, this will generate a file keyboard.layout.filtered containing filtered keyboard mappings.
  • Ensure that keyboard.layout.filtered is correct and not missing anything obvious, edit if necessary.
  • Rename keyboard.layout.filtered to [COUNTRY_CODE].keyboard.
  • You should execute the SWTKeyboardTest and/or AWTKeyboardTest test classes to check if your .keyboard file is working properly.
  • Please file a bug and a Gerrit review to contribute the keyboard layout once you got it working or attach it to your bug for the missing keyboard layout!

.keyboard file format

See EN_US.keyboard for an example of the US English keyboard layout, and MAC_EN_US.keyboard for the corresponding keyboard layout on a mac.

.keyboard files are simple text files with the following format:

<CHARACTER> <KEY_COMBINATION>

The <CHARACTER> is the complex character that needs to be typed, and the <KEY_COMBINATION> is the combination that types the <CHARACTER>. Valid <KEY_COMBINATION>s are: CTRL, SHIFT, ALT, COMMAND and all other keys on the keyboard, capitalized ( 'T' is valid, 't' is not). Similarly '3' on a US keyboard is valid, '#' is not.

 

注册键盘事件:

 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
  SWTBotPreferences.KEYBOARD_STRATEGY = "org.eclipse.swtbot.swt.finder.keyboard.SWTKeyboardStrategy";
 

For TreeItem:

final SWTBotTreeItem item = ...
item.select().pressShortcut(Keystrokes.ALT, KeyStroke.getInstance("N")); 

For TableItem:

final SWTBotTable item = ...
item.pressShortcut(Keystrokes.DOWN);item.pressShortcut(Keystrokes.CR); 

For EclipseEditor

((SWTBotEclipseEditor)bot.activeEditor()).pressShortcut(Keystrokes.ALT,  KeyStroke.getInstance("E"));

From Active Shell:

 bot.activeShell().pressShortcut(
        Keystrokes.CTRL, KeyStroke.getInstance("1"));
分享到:
评论

相关推荐

    swtbot详细例子说明网页分享

    它采用事件驱动模型,监听UI事件,模拟用户的交互行为。此外,SWTBot还支持插件机制,可以方便地添加新的控件支持或自定义功能。 ### 自定义部件 对于SWTBot不直接支持的自定义控件,可以通过实现`ISWTBotFinder`...

    swtbot学习资料

    此外,SWTBot支持事件监听,可以捕获用户与GUI交互时发生的事件,这对于模拟用户行为和验证应用程序响应非常有用。例如,可以监听按钮点击事件来确保正确处理。 学习SWTBot时,还要注意其与Eclipse插件开发的集成。...

    swtbot运行原理

    当一个测试脚本执行时,SWTBot会注入一个特殊的事件监听器到SWT组件中,这个监听器能够捕获并处理所有与用户交互相关的事件。 在SWTBot的运行过程中,主要包含以下几个步骤: 1. **初始化**:测试开始前,SWTBot会...

    SWTBot自动化测试学习软件

    3. **事件模拟**:通过SWTBot,你可以触发各种用户事件,如键盘输入、鼠标点击等,从而测试这些事件触发后程序的响应情况。 4. **断言和验证**:SWTBot提供了丰富的断言方法,可以用来验证控件的状态、内容或值是否...

    swtbot 详细例子说明

    SWTBot是一个开源自动化测试框架,专为Eclipse RCP(Rich Client Platform)和SWT(Standard Widget Toolkit)应用程序设计。这个工具允许开发者和测试人员编写可重复的、可靠的UI测试,无需深入学习复杂的事件模拟...

    SWTBot收集

    SWTBot是一个强大的开源自动化测试框架,专门用于Eclipse RCP(Rich Client Platform)和SWT(Standard Widget Toolkit)应用程序的UI测试。它提供了一种简单而强大的方式来编写可维护的测试,使得开发者和测试人员...

    SWTBot插件包及例子

    3. **事件模拟**:SWTBot允许开发者模拟用户与UI的交互,如键盘输入、鼠标点击等,这对于测试用户行为至关重要。例如,`Bot.text().typeText("用户名")` 可以在文本框中输入"用户名"。 4. **断言与验证**:测试的...

    swtbot eclipse插件 测试界面

    swtbot eclipse插件 测试界面

    使用SWTBOT进行GUI自动化测试

    ### 使用SWTBOT进行GUI自动化测试 #### 引言 在软件开发过程中,图形用户界面(GUI)测试一直是挑战之一,特别是在Java世界里。传统的手动测试不仅耗时且容易出错,而自动化测试则可以显著提高测试效率和准确性。...

    Web页面测试-swtbot

    ### Web页面测试-swtbot #### 一、Web页面测试的重要性与挑战 随着互联网和内部网(Intranet)的迅速发展,Web技术已经成为影响工业、商业、医疗、教育、政府乃至个人生活的关键技术之一。越来越多的传统信息系统...

    SWTBot - SWT/Eclipse functional testing-开源

    SWTBot是用于SWT / RCP应用程序的自动化和测试工具,具有记录和回放脚本的功能。 功能将包括基于文本的脚本,对测试套件的回放,报告和多线程回放的ant支持。

    eclipse4.4.4+gmf+swtbot

    NULL 博文链接:https://mwhgjava.iteye.com/blog/2257771

    scenarioo-e4-swtbot-example-integration

    方案示例-swtbot-e4 结合使用场景和SWTBot来测试和记录Eclipse RCP e4示例应用程序的示例UI测试和Scenarioo集成可在plugins/org.scenarioo.example.e4.test/src/org/scenarioo/example/e4文件夹中找到。构建并运行...

    SWT的自动化测试框架

    3. **事件模拟**:SWTBot能够模拟各种用户事件,如键盘输入、鼠标点击、窗口操作等,从而全面覆盖用户可能的操作。 4. **断言支持**:提供丰富的断言方法来检查应用程序的状态,例如`bot.textWithLabel("Username")...

    SWT的详解,例子,介绍

    2. **基本概念**:了解SWTBOT的核心类,如`SWTBot`、`BotFactory`和`WidgetFinder`,以及它们在测试中的作用。 3. **选择和操作控件**:学习如何通过SWTBOT选取和操作窗口、菜单、按钮、文本框等GUI元素。 4. **...

    pdi-ui-test:基于SWTBot的用于Pentaho数据集成的UI测试的集合

    【标题】"pdi-ui-test"是一个专门针对Pentaho数据集成(PDI)的UI自动化测试框架,它利用了SWTBot库来实现对PDI用户界面的全面测试。 【描述】该项目"pdi-ui-test"的核心目标是提供一个高效、可靠的测试套件,确保...

    如何为EclipseJFaceUI运行单元测试Java开发

    为了测试JFace UI组件,我们可以结合使用 SWTBot,这是一个专门用于测试Eclipse RCP和SWT应用的测试库。SWTBot允许我们模拟用户交互,例如点击按钮、选择菜单项等。 要开始设置单元测试,确保你的项目已经包含了...

    SWT 整理出的部分资料

    SWT(Standard Widget Toolkit)是...其丰富的组件库、灵活的布局管理和事件处理机制为开发者提供了丰富的工具来创建复杂且用户友好的应用程序。结合JFace和其他Eclipse相关技术,SWT可以满足各种桌面应用开发的需求。

Global site tag (gtag.js) - Google Analytics