Well, that’s very possible. Follow the instructions below.
Now at this point you are ready to play with SWTBot .
For demo purpose, I wrote a small login dialog for you, and it will look like this: 
The code
import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class SampleSWTUI { public Shell showGUI(final Display display) { Shell shell = new Shell(display); shell.setLayout(new GridLayout(3,true)); shell.setText("Sample SWT UI"); new Label(shell, SWT.NONE).setText("User Name: "); final Text nameText = new Text(shell, SWT.BORDER); nameText.setText (""); GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); data.horizontalSpan = 2; nameText.setLayoutData(data); new Label(shell, SWT.NONE).setText("Password: "); final Text passwordText = new Text(shell, SWT.BORDER|SWT.PASSWORD); passwordText.setText (""); data = new GridData(SWT.FILL, SWT.FILL, true, false); data.horizontalSpan = 2; passwordText.setLayoutData(data); Button loginButton = new Button (shell, SWT.PUSH); loginButton.setText ("Login"); data = new GridData(SWT.FILL, SWT.FILL, true, false); data.horizontalSpan = 3; loginButton.setLayoutData(data); loginButton.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e) { String user = nameText.getText(); String password = passwordText.getText(); System.out.println("\n\n\n"); if(user.equals("Favonius") && password.equals("abcd123")){ System.out.println("Success !!!"); }else { System.err.println("What the .. !! Anyway it is just a demo !!"); } } }); shell.pack(); shell.open(); return shell; } public static void main(String [] args) { Display display = new Display(); Shell shell = new SampleSWTUI().showGUI(display); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
Now create a JUnit test case (google for it if you are new to it). Also add all jar files to SWTBot (the one you downloaded) in the classpath .
Now first create a display (because the application needs it). Also get a container handle in which your widgets / controls are present. In my case, this is Shell .
SWTBot Code
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swtbot.swt.finder.SWTBot; import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton; import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; import org.junit.Test; public class SWTBotDemo { @Test public void test() { SWTBotPreferences.PLAYBACK_DELAY = 100;
Now all the methods and variables of SWTBot are well defined in the source and source bundled in the banks of SWTBot. That way you can always go and crack the source code.
additional literature
Hope this helps.
Favonius
source share