http://wiki.eclipse.org/SWTBot/Testing_Custom_Controls
SWTBot/Testing Custom Controls
Thomas Py wrote: > hI! > i´ve got a rcp-application with own swt-items.. for example there is a "QCombo extends Composite" how can i access this combobox with the swtbot? it´s not a ccombobox and not a combobox so i dont know how can i change the selected item with the swtbot. can swtbot list all widgets? > thnx for any help
Finding the widget is quite easy. Using it is something else...
To find your QCombo widget, do this:
QCombo widget = bot.widget(widgetOfType(QCombo.class));
Now to use it, you can't just do QCombo.setSelectedItem() (or whatever API it might have), you must ensure that the code that needs running in the UI thread be run in the UI thread, using sync or async execution. For some quick testing, you could do this:
asyncExec(new VoidResult(){ void run(){ widget.setSelectedItem(); } }
but it quickly burdens your test code. What you should do instead is use the page object pattern: make a wrapper for your widget. Ex:
public class SWTBotQCombo extends AbstractSWTBot<QCombo>{ public SWTBotQCombo(QCombo w) throws WidgetNotFoundException { this(w, null); } public SWTBotQCombo(QCombo w, SelfDescribing description) throws WidgetNotFoundException { super(w, description); } public void setSelectedItem() { asyncExec(new VoidResult(){ void run() { widget.setSelectedItem(); } } } ... }
在swtbot中所有swt的widget控件必须实现AbstractSWTBot类实现.
AbstractSWTBot泛型实现类为:
public abstract class AbstractSWTBot<T extends Widget> {
在AbstractSWTBot中触发非阻塞的事件的方法如下:
protected void notify(final int eventType, final Event createEvent)
为实现该类的子类使用提供了条件.
同步执行的方法为syncExec的集中重载如下:
/** * Invokes {@link ArrayResult#run()} on the UI thread. * * @param toExecute the object to be invoked in the UI thread. * @return the array returned by toExecute. */ protected <T> T[] syncExec(ArrayResult<T> toExecute) { return UIThreadRunnable.syncExec(display, toExecute); } /** * Invokes {@link VoidResult#run()} on the UI thread. * * @param toExecute the object to be invoked in the UI thread. */ protected void syncExec(VoidResult toExecute) { UIThreadRunnable.syncExec(display, toExecute); } /** * Invokes {@link ListResult#run()} on the UI thread. * * @param toExecute the object to be invoked in the UI thread. * @return the list returned by toExecute */ protected <E> List<E> syncExec(ListResult<E> toExecute) { return UIThreadRunnable.syncExec(display, toExecute); } /** * Invokes {@link BoolResult#run()} synchronously on the UI thread. * * @param toExecute the object to be invoked in the UI thread. * @return the boolean returned by toExecute */ protected boolean syncExec(BoolResult toExecute) { return UIThreadRunnable.syncExec(display, toExecute); } /** * Invokes {@link BoolResult#run()} synchronously on the UI thread. * * @param toExecute the object to be invoked in the UI thread. * @return the boolean returned by toExecute */ protected String syncExec(StringResult toExecute) { return UIThreadRunnable.syncExec(display, toExecute); } /** * Invokes {@link Result#run()} synchronously on the UI thread. * * @param toExecute the object to be invoked in the UI thread. * @return the boolean returned by toExecute */ protected <T> T syncExec(Result<T> toExecute) { return UIThreadRunnable.syncExec(display, toExecute); } /** * Invokes {@link WidgetResult#run()} synchronously on the UI thread. * * @param toExecute the object to be invoked in the UI thread. * @return the Widget returned by toExecute */ protected T syncExec(WidgetResult<T> toExecute) { return UIThreadRunnable.syncExec(display, toExecute); } /** * Invokes {@link IntResult#run()} synchronously on the UI thread. * * @param toExecute the object to be invoked in the UI thread. * @return the integer returned by toExecute */ protected int syncExec(IntResult toExecute) { return UIThreadRunnable.syncExec(display, toExecute); }
异步执行的方法asyncExec如下:
/** * Invokes {@link BoolResult#run()} asynchronously on the UI thread. * * @param toExecute the object to be invoked in the UI thread. */ protected void asyncExec(VoidResult toExecute) { UIThreadRunnable.asyncExec(display, toExecute); }
快捷键实现如下:
/** * Presses the shortcut specified by the given keys. * * @param modificationKeys the combination of {@link SWT#ALT} | {@link SWT#CTRL} | {@link SWT#SHIFT} | * {@link SWT#COMMAND}. * @param c the character * @return the same instance * @see Keystrokes#toKeys(int, char) */ public AbstractSWTBot<T> pressShortcut(int modificationKeys, char c) { waitForEnabled(); setFocus(); keyboard().pressShortcut(modificationKeys, c); return this; } /** * Presses the shortcut specified by the given keys. * * @param modificationKeys the combination of {@link SWT#ALT} | {@link SWT#CTRL} | {@link SWT#SHIFT} | {@link SWT#COMMAND}. * @param keyCode the keyCode, these may be special keys like F1-F12, or navigation keys like HOME, PAGE_UP * @param c the character * @return the same instance * @see Keystrokes#toKeys(int, char) */ public AbstractSWTBot<T> pressShortcut(int modificationKeys, int keyCode, char c) { waitForEnabled(); setFocus(); keyboard().pressShortcut(modificationKeys, keyCode, c); return this; } /** * Presses the shortcut specified by the given keys. * * @param keys the keys to press * @return the same instance * @see Keyboard#pressShortcut(KeyStroke...) * @see Keystrokes */ public AbstractSWTBot<T> pressShortcut(KeyStroke... keys) { waitForEnabled(); setFocus(); keyboard().pressShortcut(keys); return this; }
相关推荐
对于SWTBot不直接支持的自定义控件,可以通过实现`ISWTBotFinder`接口来自定义查找策略,或者通过` SWTBotFactory.registerWidget(Class<? extends Control> clazz, IControlCreator creator)`方法注册新的控件创建...
SWTBot是一个开源自动化测试框架,专为Eclipse RCP(Rich Client Platform)和SWT(Standard Widget Toolkit)应用程序设计。这个工具允许开发者和测试人员编写可重复的、可靠的UI测试,无需深入学习复杂的事件模拟...
SWTBot是一款强大的开源自动化测试工具,主要用于Java GUI应用程序,特别是那些基于Eclipse RCP(Rich Client Platform)和SWT(Standard Widget Toolkit)的应用。它提供了丰富的API,使得测试人员和开发人员能够...
SWTBot是一个强大的开源自动化测试框架,专门用于Eclipse RCP(Rich Client Platform)和SWT(Standard Widget Toolkit)应用程序的UI测试。它提供了一种简单而强大的方式来编写可维护的测试,使得开发者和测试人员...
SWTBot是一款强大的开源自动化测试框架,主要用于Java GUI应用程序,特别是那些基于Eclipse RCP(Rich Client Platform)和SWT(Standard Widget Toolkit)的应用。它提供了丰富的API,使得编写测试用例变得更加简单...
通过安装这个插件,开发者可以利用SWTBot的强大功能来自动化SWT和JFace构建的图形用户界面(GUI)的测试过程。 描述中提到的"例子"是指SWTBot包内可能包含了各种示例代码和教程,帮助初学者快速理解和应用SWTBot。...
SWTBot是一个开源的自动化测试框架,主要用于Java SWT(Standard Widget Toolkit)和JFace应用程序的UI测试。它为开发者提供了一种简洁的方式来编写可维护的、可靠的用户界面测试。了解SWTBot的运行原理对于有效地...
### 使用SWTBOT进行GUI自动化测试 #### 引言 在软件开发过程中,图形用户界面(GUI)测试一直是挑战之一,特别是在Java世界里...通过合理的设计和实施策略,可以充分利用SWTBOT的优势,实现高效稳定的GUI自动化测试。
swtbot eclipse插件 测试界面
sbtwot(应为swtbot)是一种开源的Java GUI测试工具,它专注于测试Swing和SWT/SWT JFace UI组件。尽管swtbot最初是为了测试桌面应用程序而设计的,但它也可以用于Web页面测试。在Eclipse环境下建立swtbot的Web应用...
6. **异常处理和调试**:如果测试失败,可以利用SWTBot提供的信息定位问题,进行调试和修复。 **四、SWTBot与其他测试框架的比较** 虽然SWTBot专为SWT和RCP应用设计,但与其他自动化测试框架如Selenium相比,它的...
**SWT(Standard Widget Toolkit)**是Java编程中用于创建图形用户界面(GUI)的一种开源库,它是IBM为对抗Java AWT和Swing而推出的。SWT直接与操作系统API交互,因此可以提供更快的性能和更原生的外观。Eclipse IDE...
SWTBot是用于SWT / RCP应用程序的自动化和测试工具,具有记录和回放脚本的功能。 功能将包括基于文本的脚本,对测试套件的回放,报告和多线程回放的ant支持。
【标题】"pdi-ui-test"是一个专门针对Pentaho数据集成(PDI)的UI自动化测试框架,它利用了SWTBot库来实现对PDI用户界面的全面测试。 【描述】该项目"pdi-ui-test"的核心目标是提供一个高效、可靠的测试套件,确保...
许多Eclipse插件也利用SWT来构建自定义视图和编辑器。 7. ** SWT/JFace 框架** JFace是对SWT的抽象层,提供了一些高级组件和服务,如对话框、表视图和树视图,简化了GUI开发。 8. ** SWTBot** SWTBot是Eclipse...
方案示例-swtbot-e4 结合使用场景和SWTBot来测试和记录Eclipse RCP e4示例应用程序的示例UI测试和Scenarioo集成可在plugins/org.scenarioo.example.e4.test/src/org/scenarioo/example/e4文件夹中找到。构建并运行...
NULL 博文链接:https://mwhgjava.iteye.com/blog/2257771
SWT,全称 Standard Widget Toolkit(标准小部件工具包),是Java编程语言中用于创建图形用户界面(GUI)的一种开源库。它由Eclipse基金会维护,是Eclipse IDE的核心组件之一,提供了丰富的控件和功能,让开发者能够...