Open topic with navigation

# Insight code sample (Java SDK)

In this topic:

## Identify and click a button using Insight

This example uses Insight to identify and activate an image object. It clicks button 2 on the calculator.

To run this test:

- The calculator application must be open
- A bitmap of button number 2 on the calculator must be stored in the directory in which the test is running

    import java.awt.image.RenderedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import com.hp.lft.sdk.insight.InsightDescription;
    import com.hp.lft.sdk.insight.InsightObject;
    import com.hp.lft.sdk.stdwin.*;
    .
    .
    .

    @Test
    public void testCalcWithInsight() throws GeneralLeanFtException, IOException {

    	WindowDescription calculatorDescription = new WindowDescription.Builder().windowClassRegExp("CalcFrame").windowTitleRegExp("Calculator").build();
    	// Identify the calculator application.
    	Window calculator = Desktop.describe(Window.class, calculatorDescription);

    	// Locate the bitmap.
    	File imgFile = new File("c:\\TwoButton.bmp");
    	RenderedImage image = ImageIO.read(imgFile);
    	InsightObject twoButton = calculator.describe(InsightObject.class, new InsightDescription(image));

    	// Click button number "2"
    	twoButton.click();

    }

Back to top

See also:

- Lean Functional Testing (LeanFT) Java SDK Reference
- LeanFT Java SDK code samples