Lists and Tables


In this tutorial, we will create a simple script for searching flights. Take a look at our demo booking page. Here we have three combo box elements, one date-picker control and a search button. We will create a special view for each of the combo box elements and for the DatePicker control to select the right destination. Let’s start with the “From” control. Click Scan GUI button. We should scan our view with the combo box opened, to do that, hold the control key on your keyboard and click on the combo box to open it, then release the control key and click anywhere in the application to scan it. Enter the name for the application and for the view. Here we need only one object - the label “From”. We will select this object and remove rest of the objects. Now we should create a related object which we will use later in the script to perform a click on it to extend combo box’s drop down list. To select the item in the combobox list, we can use ZAPTEST's special object type: List. List has a special parameter - number of rows. Our combo box list has four rows. All list objects should have a parent object. In our case, it is the label “From”. Let’s add some code to our project. Our script should start from the launching of the browser application. We should open the browser and navigate to demo.zaptest.com/book webpage. Then we should click on the first combobox to open it and select the destination. To select the destination, we will use the List object. This object has a special method the ClickRow, which has a text parameter of the item value. In this script, we will use Datatable for all used parameters. Let’s add a new parameter “From” to our Datatable. Let's choose “New York” as our departure city. Then use this data in the ClickRow method. We also parametrize browser to a datatable for cross-browser execution in the future. Let’s run the script. ZAPTEST will open the booking page and select “New York” in the departure field. We should repeat the same steps for the next combobox control. Click Scan to create a new view and remove all objects except label “To”. Now create relative objects: one regular for activating the combobox dropdown and another one – list – for selecting the item value. This combobox item have three lines, so we should set this number to the “Rows” field. Also, we should set the relative object for list – label “To”. Return to our script. Now we should add a new parameter to our Datatable: destination. Activate our combobox and then select the destination. Now we have our destination selected. Next element is DatePicker control. Like we did before, we should create a new view for the DatePicker control. Click Scan UI. Make the DatePicker control visible by using the control key trick that we learned earlier and scan the page. Here we should also remove all the objects except “Date” label. Then we should create one special object for opening the DatePicker. In this tutorial, we will select just one date. However, in the next lesson we will show you how to change the month and add some advanced logic to the calendar. For working with calendars ZAPTEST has a special object type: table. Table object can represent any table and has two parameters: rows and columns. In our case DatePicker control has seven columns and six rows. As well as the List object Table should have a parent object. Let's set it to the “Date” label.  It’s time to add some code around the DatePicker control. We will need to open a calendar and select day 28 of the current month. Let's add a new parameter – Date - to our Datatable and set it to 28. When we enter a number, the Datatable will represent it as a numeric format. Each cell has a context menu where we can set different properties. One of these properties is "Format', so we should set the format of the date to "Text", because the method which we will use accepts only text data. Now we can activate the DatePicker by clicking on it. Let's add the table object and use the method ClickCell. In case of Web Calendar objects, we should set the second parameter to “true”. The last thing we should do is click on the search button and collect the results. Let’s create a new view for the results. Scan UI of web page with the results. Here we should keep the following objects: the "Search" button, the "Search" label for detecting results, and the "Flight" label for collecting information about flights.  Truncate the “Search Results” label. We will use the "OCR Partial" mode to detect only the first part of the string. To do this, open the extended properties panel and change the Recognition Type to "Partial OCR". This will allow us to run universal result checking, which will not be influenced by the date or the flight information. We will also add a new related object for collecting flight numbers. Here we should update a property: the text color, which should be set to white. In the code we will click on the search button and use the Exist method to check the results. Then we will use the GetText method to get text data from the object. This method returns current text data of the object, which we could keep in a variable. We will save this data to our report using the CustomReport method, which we already used in the first lesson. The last line of our script should close the browser window. Let’s run the script. ZAPTEST will select the destinations, change the date, click on the search button and then it will save the flight numbers to the report and close the browser. Let’s open the results: here we can find detailed information about all of the steps of searching a flights. Thank you for using ZAPTEST

Contact Us

Tower Place 100

3340 Peachtree Rd NE #1800 

Atlanta, GA 30326 USA

(404) 814-5227