Skip to content

SWT Layer usage

jpeterka edited this page Apr 18, 2013 · 10 revisions

Obsolete page !!!

The Red Deer SWT layer provides an API for directly accessing and manipulating SWT Widgets and Controls based on SWTBot.

The SWT Layer is used by higher level RedDeer plugins. If you're testing Eclipse or RCP applications (for example,org.jboss.tools.eclipse) you should use higher layers API (like Eclipse layer) for you tests. SWTLayer is intended to be used mainly for building higher abstraction levels and to be used in pure SWT applications.

The SWT Layer can be used outside of Red Deer when direct SWT Widget manipulation is needed, making it it suitable for pure SWT application testing.

Usage

just add org.jboss.reddeer.swt into your MANIFEST.MF

Basic client usage examples


// Object lookup
Shell shell = new WorkbenchShell();	
// Object state read
assertEquals("Eclipse",shell.getTitle());

// Object lookup
Button button = new PushButton("Ok");
// Object manipulation
button.click();

// Select menuitem of the shell
Menu menu = new ShellMenu("Window","Properties");
menu.select();


Matchers

Menu instances provides constructors to allow use predefined or users custom matchers and multi-matchers builders (for regex lookup, etc.)


RegexMatchers m = new RegexMatchers("Win.*", "Prefz.*");
Menu menu = new ShellMenu(m.getMatchers());

Exception handling

These are thrown by Reddeer SWT layer


SWTLayerException - exception indicates unexpected state on SWTLayer (widget not found, widget lost, multiple widgets, etc.)

If you want to react to these exception you need to catch them in your code:


try {
  Button b = new PushButton("OK");
}
catch (SWTLayerException e) {
 doSomething();
}

Current Scope of Implementation

SWT Layer aims to implement these [https://github.com/jboss-reddeer/reddeer/tree/master/org.jboss.reddeer.swt/src/org/jboss/reddeer/swt/api] (https://github.com/jboss-reddeer/reddeer/tree/master/org.jboss.reddeer.swt/src/org/jboss/reddeer/swt/api)

  • Browser.java
  • Button.java
  • Canvas.java
  • CLabel.java
  • Combo.java
  • Composite.java
  • CoolBar.java
  • CTabFolder.java
  • DateTime.java
  • ExpandBar.java
  • Group.java
  • Label.java
  • Link.java
  • List.java
  • Menu.java
  • ProgressBar.java
  • Sash.java
  • Scale.java
  • ScrolledComposite.java
  • Shell.java
  • Slider.java
  • Spinner.java
  • StyledText.java
  • TabFolder.java
  • Table.java
  • Text.java
  • ToolBar.java
  • Tray.java
  • TreeItem.java
  • Tree.java
Clone this wiki locally