Testing a Custom Control Using Automation Support

You can create specific automation support for the custom control. This additional automation support provides recording support and more powerful play-back support. To create automation support, the test application must be modified and the Open Agent must be extended.

Before you can test a custom control in Silk4J, perform the following steps:
  • Define the custom control in the test application
  • Implement automation support

After the test application has been modified and includes automation support, perform the following steps:

  1. Create a Java class for the custom control in order to test the custom control in your tests. For example, the spinner control class must have the following content:
    package customcontrols;
    
    import com.borland.silktest.jtf.Desktop;
    import com.borland.silktest.jtf.common.JtfObjectHandle;
    import com.borland.silktest.jtf.flex.FlexBox;
    
    /**
     * Implementation of the FlexSpinner Custom Control.
     */
    public class FlexSpinner extends FlexBox {
    
      protected FlexSpinner(JtfObjectHandle handle, Desktop desktop) {
        super(handle, desktop);
      }
    
      @Override
      protected String getCustomTypeName() {
        return "FlexSpinner";
      }
    
      public Integer getLowerBound() {
        return (Integer) getProperty("lowerBound");
      }
    
      public Integer getUpperBound() {
        return (Integer) getProperty("upperBound");
      }
    
      public Integer getValue() {
        return (Integer) getProperty("Value");
      }
    
      public void setValue(Integer Value) {
        setProperty("Value", Value);
      }
    
      public Integer getStepSize() {
        return (Integer) getProperty("stepSize");
      }
    
      public void increment(Integer steps) {
        invoke("Increment", steps);
      }
    
      public void decrement(Integer steps) {
        invoke("Decrement", steps);
      }
    
    }
    
  2. Add this Java class to the Silk4J test project that contains your tests.
    Tip: To use the same custom control in multiple Silk4J projects, we recommend that you create a separate project that contains the custom control and reference it from your Silk4J test projects.
  3. Add the following line to the <Silk Test installation directory>\ng\agent\plugins\com.borland.silktest.jtf.agent.customcontrols_<version>\config\classMapping.properties file:
    FlexSpinner=customcontrols.FlexSpinner
    The code to the left of the equals sign must be the name of custom control as defined in the XML file. The code to the right of the equals sign must be the fully qualified name of the Java class for the custom control. Now you have full record and playback support when using the custom control in Silk4J.

Examples

The following example shows how increment the spinner's value by 3 by using the "Increment" method that has been implemented in the automation delegate:
desktop.<FlexSpinner>find("//FlexSpinner[@caption='index:1']").increment(3);
This example shows how to set the value of the spinner to 3.
desktop.<FlexSpinner>find("//FlexSpinner[@caption='index:1']").setValue(3);