Automating Black Box testing using Find Image feature

September 18th, 2013 by Bill Echlin

Sometimes we’ll find that our application won’t be open to TestComplete. So the application doesn’t expose any details about the it’s objects and methods, or Testcomplete may not have in-built support for the controls or windows in the application. For example we may have a browser type that is not supported by TestComplete. Equally we may have objects like toolbar buttons, icons that aren’t supported by TestComplete. To automate test on these types of applications, we can use Find Image feature.

What do we mean when we talk about automation using the Find Image feature? Using the Image of a particular control, window or object, our script will find the position of the object and then performs an action on it.

This is like finding a thief, using his photograph. The Police may aim to catch this thief but he has only the photo of that thief. He gets a clue that the thief is there in a stadium. However, when he reaches the stadium he finds around 100 people in the stadium. He looks at every persons face in the stadium. Finally he identifies the thief and arrests him. Granted it’ll take a long time to look at every face and compare it to the photo but when we’re talking about searching for objects with TestComplete this process takes a fraction of a second. With TestComplete we going to use the Find Image method to implement this process.

  1. Testcomplete takes the image of the object on which we want to carry out some action.
  2. We need to search for that image, on a window or page object.
  3. Using Regions.Find method testcomplete searches for this image and finds its position.
  4. Now in this position you perform your actions (Clicking, entering text etc.)
  5. In General, it includes the following three steps.

    three_steps

To find the image on an object we have to use Regions.Find method. This method returns the identified rectangular image object.

The Syntax of this method is as follows.

       Regions. Find(PictureToSearchIn , PictureToSearchFor )

This method contains a few more optional parameters. To simplify though we will take these two required parameters alone.

parameters_alone

PictureToSearchIn – Window or Page object, on which we have to find the image

PictureToSearchFor – Image name of the object on which we want to perform action. We should have added this image in the Regions section of the Stores.

Let us consider the following scenario to be automated on the Google home page. I want to search for “Testcomplete”. But I want to automate it in chrome.  To automate this scenario using Find Image, we’ll do the following.

  1. Add the image of the Objects (on which you want to perform actions) to the Regions section of Stores Item. Here we have to add the images of the Google search box and Google search button.
  2. google1

  3. While entering values into the search box the Google search Button will differ. So we should add that button only.
  4. google_search_test

  5. Once added it will be displayed in Regions window as in this screenshot. The Google Search Box is image is displayed here.
  6. regoins-window-google-search

  7. Also the Google Search Button is added as shown in this screenshot. Give this a good name in the Regions sections so that we can use this in the find function.
  8. regoins-find-function

  9. Now we have to write a script, to get these rectangular image objects from the chrome window. Let us consider “chromeWinObj” is the entire chrome window
  10. chromeWinObj

  11. To Search the GoogleSearchBox in this window object you have to use the following code.
    Var rectImage = Regions. Find(chromeWinObj, “Google SearchBox” )
    (“Google SearchBox” is the name we have given in Regions section)
  12. It returns the rectangular image object which found in the chrome window. The rectangular image will have the following properties.
  13. GoogleSearchBox -varrectImage

  14. Using these properties we can easily identify the X,Y coordinates of the center point of this rectangular object in that screen. To do these use the following code.
  15. x-y-coordinates

  16. Once a click action is completed on the center point of the Search box, the cursor will be in the Search box. Now we can use the chromeWinObj.Keys(“testcomplete”) method, which will enter values into textbox.
  17. Again we now need to get the rectangular image object of the search button. Pass it into the same method. Then we can click the search button.

    So even though we might not have support for an application, using this approach we can automate onscreen actions.

Free Test Automation Framework Course
Learn the Practical steps to building an Automation Framework. Six modules, six emails (each email a short course in it's own right) covering Amazon AWS, Jenkins, Selenium, SoapUI, Git and JMeter.
Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *