Image and Area Objects

Welcome to ZAPTEST tutorials In this tutorial, we will show how to work with image-based objects, and introduce a new object type: Area. We will use the script from our previous lesson preceded by login process from first script and starting from login page. In the previous lesson, we have shown how to work with Combo Boxes using the List object. But if you launch this script on Internet Explorer you can notice that the Combo Boxes obscure the label which we use to detect the object. So, here we will learn a different way to automate the Combo Boxes, which adds support for Internet Explorer and makes the script cross-browser. We have used the Type method multiple times, but what exactly does it do? The Type method clicks on the object, cleans the text inside of it, and then types the new text into it. Let's look at the parameters of this method: Text for typing, time Delay between each character typed, and Boolean, which when set to true, erases the field content. We have also “use physical keyboard” and “string culture name” parameters which emulates text input directly from keyboard and defines keyboard layout for certain language. So, if we disable erasing the field, we can click on the Combo Box, type some text, and press the Enter key. This combination will select the item in our Combo Box and will work on all browsers. However, we might find that some applications do not support such input type. Let’s try it. First, remove the code which uses the List object; then, change the Click command of our Combo Box objects to Type. Lastly, provide the item text and disable the erasing of the field. Don’t forget to set the "delay between typing" parameter to its default value. Last 2 parameters can be skipped. We can find it in the tooltip information. Now, we have a big script with the login process. If we want to check only a part of our script, we can use the special “Run from This Line” feature. To do that, perform a right-mouse click on the line of code where you want to start the execution, and select “Run from This Line” in the menu. ZAPTEST will skip the code prior to this line and will execute the remaining of the script. So ZAPTEST selected the correct destinations. Next in this lesson, we will select the first Monday of the next month. First, we should click on the Next Month button in the DatePicker control. Open “Book - Date” view in the GUI Map. Notice that the Next Month button doesn’t have any text. So, for this case, we can use the image-based recognition type. Click "add new object", type the name “Next” and set property Recognition Type to Image. This way, ZAPTEST will use image detection algorithms. When we use image based objects, we should pay attention to the object borders, color and shape, because ZAPTEST will crop this image from our object repository and try to find it in the application under test during runtime. So, let's select the Next Month button with some area around it to improve recognition. Otherwise, when the defined image is too small, it might match other similar objects on the page. Also, change object property Precision to High. Add this object to our code, and select Click method. Now let’s select the date. Let's say we want to select the first Monday of the month. How can we do that? The Table object has two methods for that: The first is to retrieve the cell text, and the other is to click on a specific cell when we provide it with the row and the column numbers. Let’s find the row and the column of the first Monday in the table. Start by defining two variables: “row” and “col”. If the first Monday is located at the first week, then it should have a row value 1 and “col” value 2. In the next line, we will read the text of this cell and check if it is indeed the first Monday of this month. The method GetCellText returns the cell data string. Now, to use it in a conditional statement, we should first convert this string into an integer. And VisualBasic has a special function for that: C-I-N-T, Cint. Then we check, if the number of the day is higher than 2, it means that the first Monday is located on the second row and we should set the row value to 2. Now we should click on this cell using the ClickCell method by providing the row and the column numbers. Let’s check it: ZAPTEST has selected the 7th of August, which is the first Monday of that month. The last thing which we are going to do in the test script, is book the flight and check the confirmation message. Let’s scan the page with the flight results. Create the View and remove all the objects except the flight number, the “book” button, and the confirmation message. Then update the names of these objects. We may also improve the recognition of the “Flight Number” object. Select the object and change the property Text Color to white. We can see there are two flights from New York to Boston, then how do we click on the corresponding “book” button of a specific flight number? ZAPTEST has a special object type: Area. Instead of looking for an BOOK THE FLIGHT button in the whole page, Area object crops the view and let us find objects in the cropped area. Let's see how it works. Add a new object, set the name “FlightArea”, and then change the object type to “Area”. Now, let's resize and position this area next to the FlightNumber object and relate it as it’s child. This way, ZAPTEST will dynamically move this area object to the right side of the specific Flight Number. Then, we tell ZAPTEST to search for the "Book" button inside this area. It’s easy. we set the parent object for our BOOK button to the “Flight Area”. That’s it. Now, when ZAPTEST looks for the BOOK button object, it will find the “Flight Number” object, crop this area, and try to find our button inside of it. So, if we want to book another flight number, we should be able to do so just by updating the text property of the “FlightNumber” object, and we can do it here or programmatically in the script. Add “flight” column to the Datatable and set the flight number to: “BS101”. Now, we should set the TEXT property of our FlightNumber object. We've already learned how to do that in the previous lessons, simply use the SetProperty method. We can now click on the BOOK button. ZAPTEST will click exactly on the button which appears at the right side of the flight number text. Let’s check the confirmation message. We should declare a new variable in which we combine the dynamic message with the flight number from the Datatable. Then we also update the text property and use the "Exist" method to check that our flight is booked. That’s it. Let’s run our script and check that everything works as expected. ZAPTEST will login to the system, select the parameters, click the search button and then book the flight. Thank you for using ZAPTEST

Contact Us

Tower Place 100

3340 Peachtree Rd NE #1800 

Atlanta, GA 30326 USA

(404) 814-5227