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.
- Testcomplete takes the image of the object on which we want to carry out some action.
- We need to search for that image, on a window or page object.
- Using Regions.Find method testcomplete searches for this image and finds its position.
- Now in this position you perform your actions (Clicking, entering text etc.)
In General, it includes the following 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.
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.
- 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.
- While entering values into the search box the Google search Button will differ. So we should add that button only.
- Once added it will be displayed in Regions window as in this screenshot. The Google Search Box is image is displayed here.
- 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.
- 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
- 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)
- It returns the rectangular image object which found in the chrome window. The rectangular image will have the following properties.
- 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.
- 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.
- 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.