Free Training


C Language  |  CSS  |  MainFrame  |  VBScript  |  PHP  |  XML  |  C++ Tutorials  |  Ajax  |  JavaScript  |  CSS3  |  UML  |  jQuery  |  Microsoft AJAX

Swing Testing Tutorials

 
Home Tutorials Swing Testing
 

Swing Extreme Testing - Unit Test Infrastructure

 

Unit Test Infrastructure

Having seen the broad outline of the test class and the UI methods needed, we can look closely at the implementation of the test. We'll start with the UI Wrapper class and the init() and cleanup()methods.



The UISaveAsDialog Class

UISaveAsDialog has methods for entering a name and for accessing the dialog, buttons, and text field. The data entry methods use a Cyborg, while the component accessor methods use UI:


Sample Code
  1. public class UISaveAsDialog {
  2. Cyborg robot = new Cyborg()
  3. private IkonMakerUserStrings us =
  4.  
  5.  
  6.  IkonMakerUserStrings.instance()
  7.  
  8. protected Dialog namedDialog
  9. public UISaveAsDialog() {
  10. namedDialog = UI.findNamedDialog(
  11. SaveAsDialog.DIALOG_NAME )
  12. Waiting.waitFor( new Waiting.ItHappened() {
  13. public boolean itHappened() {
  14. return nameField().hasFocus()
  15. }
  16.  
  17.  
  18.  }, 1000 )
  19. }
  20. public JButton okButton() {
  21.  
  22.  
  23.  return (JButton) UI.findNamedComponent(
  24. IkonMakerUserStrings.OK )
  25. }
  26. public Dialog dialog() {
  27. return namedDialog
  28. }
  29. public JButton cancelButton() {
  30. return (JButton) UI.findNamedComponent(
  31. IkonMakerUserStrings.CANCEL )
  32. }
  33. public JTextField nameField() {
  34. return (JTextField) UI.findNamedComponent(
  35. IkonMakerUserStrings.NAME )
  36. }
  37.  
  38.  
  39.  public void saveAs( String newName ) {
  40. enterName( newName )
  41. robot.enter()
  42.  
  43.  
  44.  }
  45. public void enterName( String newName ) {
  46. robot.selectAllText()
  47.  
  48.  
  49.  robot.type( newName )
  50. }
  51. public void ok() {
  52.  
  53.  
  54.  robot.altChar( us.mnemonic( IkonMakerUserStrings.OK ) )
  55. }
  56. public void cancel() {
  57. robot.altChar( us.mnemonic( IkonMakerUserStrings.CANCEL ) )
  58. }
  59. }
Copyright exforsys.com



A point to note here is the code in the constructor that waits for the name text field to have focus. This is necessary because the inner workings of Swing set the focus within a shown modal dialog as a separate event. That is, we can't assume that showing the dialog and setting the focus within it happen within a single atomic event. Apart from this wrinkle, all of the methods of UISaveDialog are straightforward applications of UI methods.



Read Next: Swing Extreme Testing - The ShowerThread Class



 
Related Topics

Related Jobs


 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Weekly Offers

Sponsored Links