Pages

Friday, January 6, 2012

GUI Testing using UISpec4J api

I would like to share some information regarding how to use UISpec4J for GUI Testing. This post will be edited with more information as soon as I gain experience in that.

First we have to create a setup method like this inside the subclass we extended from UISpecTestCase

protected void setUp() throws Exception {
 

super.setUp();
UISpec4J.setWindowInterceptionTimeLimit(TIMELIMITININT);

setAdapter(new MainClassAdapter(YOURMAINCLASS.class));

Window window = getMainWindow();
 

// Get references to UI elements 
 

}

While getting references to other elements, we have to make sure that it is easily accessible to UISpec4J. For that developers, should use setName() method for the UI elements like button, text box, panel, etc .......

If the element is not directly accessible (ie. nested inside many panels). We have to use the panel1 = window.getPanel("PANELNAME") method to get a reference.

So using the panel2 = panel1.getPanel("PANELNAME") method we can easily
go to the particular panel in the application window.

Note :- Before making assertions we have to call the UISpec4J.setAssertionTimeLimit(int ms) to give a delay before starting the assertion.

To intercept a modal dialog box, we have to use like this,
UISpec4J.setWindowInterceptionTimeLimit(12000);
WindowInterceptor
.init(ANY TRIGGER EVENT)
.process(new WindowHandler("Main Window") {
public Trigger process(Window window) {
// Now you can use the window to access the elements in the modal dialog box
return window.getButton("OK").triggerClick();

}
})
.run();
If anything wrong, inform me. :)

No comments:

Post a Comment