Remembering how we use Fitnesse before in this wiki, we now see how to incorporate UISpec4J API into the framework:
- Code: Select all
import org.uispec4j.UISpec4J;
import org.uispec4j.UISpecTestCase;
public abstract class ModelLogin extends UISpecTestCase {
static {
UISpec4J.init();
}
Your project has to get the jar as shown in the Fitnesse script:
- Code: Select all
classpath: /Users/red1/Documents/workspace/POSFitnesse/uispec4j-2.4-jdk16.jar
Your POJO (plain java objects) test code then just extends the ModelLogin and execute WindowTriggers:
- Code: Select all
public class DumpGUIObjects extends ModelLogin {
private ClassLoader classload = ClassLoader.getSystemClassLoader();
private Class clazz;
private String results;
protected String press1;
//pressing GUI buttons containing productnames
//TODO -- getting values from returned GUI actions
//
//execute triggers from UISpec4J
public boolean execute() {
if (getMainWindow() == null)
return false;
return true;
}
public void setClassName(String classname) throws ClassNotFoundException{
clazz = classload.loadClass(classname);
}
public void setPress1(String item){
press1 = item;
}
public String Results(){
return results;
}
public Window getMainWindow() {
final Window[] result = new Window[3];
WindowInterceptor.init(new MainClassTrigger(clazz, new String[0]))
.process(new WindowHandler(){
public Trigger process(Window window) throws Exception{
results=window.getTitle();
window.getTextBox("userTextField").setText("SuperUser");
window.getPasswordField("passwordField").setPassword("System");
window.getButton("Ok").click(); //1st window login preset to SuperUser
window.getComboBox("orgCombo").select("Store Central");
window.getButton("Ok").click();
//
return window.getButton("Cancel").triggerClick(); //
}
})
.process(new WindowHandler(){
public Trigger process(Window window) throws Exception{
try {
result[1]=window; //2 selections pressed, with values passed from FitnesseStory script
window.getButton(press1).click();
window.getButton("non existent").click();
}catch (Exception e){
results = e.toString();
return window.getButton("Oak").triggerClick();
}
return window.getButton("Ok").triggerClick();//same window fallbacks
}
})
.run();
return result[1];
}
}
The above is called from the following Fitnesse page:
As you can see, it is passing the parameters into the POJO above. The purpose of this particular testing is not yet running off the POS as shown earlier. This marvelous little sample test is actually doing a dump of the panel names for easier developer reference during test creation! See what i mean below:
Now we can see what panels or buttons actually appear. The lower part of the Fitnesse output is this:
- Code: Select all
BPartner,Cancel,Delete,Edit,History,Logout,Minus,New,Next,Payment,Plus,Preference,Previous,Print,Product]
What this means is that we can directly 'touch' these visible buttons or panels just by:
- Code: Select all
window.getButton("any name").click()
and it will get programmatically clicked, without launching anything onto the desktop. It is clicked by its object name displayed and unlike other tests such as Selenium (for Web-based apps), it is not doing things via macro steps to look for relative positioning of the GUI. Thus the panel can be anywhere on the screen and the code will click on it. This means fast, sure testing.