Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts

Monday, August 3, 2015

UFT Description and .GetChildObjects | Working with multiple objects with similar or the same set of properties


It is a best practice to make your automation script as Dynamic as possible. Here's a sample when dealing with search results or blog post or list of articles.

In this example, I use the google.com search results.

Scenario:
I'd like to automate the searching capability of google search and click the first search result (not the featured) no matter what title or text it has.

Figure 1.0 Search results in google.com

Tip: You can get the properties of the object either using object spy or developer tools in your browsers.

Figure 2.0 Decription and .ChildObjects
You can also do the loop statement to iterate all the present occurrences of the object.

   
Figure 2.1 Looping the objects' existence

Object indexes acts like arrays, it always starts with '0' index.

Note: You can always maximize your scripts to be suitable for similar layouts as long as the objects are still the same and uses the same hierarchy.
 

Monday, July 27, 2015

UFT GetROProperty and CheckProperty | Comparing Expected Text with Actual Text


There are times when you need to check if the Expected Text is displayed against Actual Text displayed on the actual applications.

For intance:

You need to check the exact page title description in the www.w3schools.com website.

Figure 1: w3schools.com homepage screenshot

Text that needs to check : 'The language for building web pages."

You need also to consider that this part is a content maintainable. Which means, it is possible that it will change it depends of the content owner.

The best way to do it is you have to place it on your data table.

There are different ways on how to check the text it depends on the availability of the object properties.


GetROProperty Method:

Object.GetROProperty is the property used to get the current property of the Object. This is easier to use if the Object has a unique property that we can identify easily (e.g. html id, class, etc.)


Example:

Let's assume that the page description of the w3schools.com homepage has a unique property.

Object Property (through Oject Spy)
      html id:=page-description

Data Table:
    



Code:
   


Explanation:
   
   Line # 4: Set the row of which row from the data table you want to get.
                   by default, the row setting is always 1.

   Line # 8 & #11: string variable and object variable declaration

   Line # 15 to # 21 :
     Since we already declare the object variable for page description, we can use the 'objPageDescription' variable.

   Check first the existence of the object using the code '.Exist(1)'. The integer parameter of the function 'Exist' represents the number of seconds it needs to wait before it returns a boolean value (true or false)

   In doing so, we are sure that during run time, the code will not encounter error because we made sure of it that we check its existence first before getting its property.

NOTE: This is the most common error issues encountered when using the GetROProperty function. It will throw an error if you try to GetROProperty of an object which is not there (or not exist).

   You can always use the GetROProperty function in printing the exact value on Actual Runtime as a Reporter value and description so that it will be printed in the Results Viewer.


CheckProperty Method:

But what if the the object doesn't have a unique property, which is the most common scenario.

You can always use the 'outertext' property and the datatable value you just declared as Expected Result text.

Example:
 
Object Spy:


Code:
   

Explanation:
   In this way, you can always use the 'outertext' property directly in declaring the object. (see line # 11).
   
   Same logic above, you still need to check the existence of the object before checking it's property.

   CheckProperty method has two parameters, Object.CheckProperty(propertyName,PropertyValue). It returns boolean value (true or false) if the specified property name and value matches the actual status of the Object.


I am not sure though on which of the two is the best method to use, but the two method above works for me depends on the availability of the properties that I need.
   

Wednesday, July 22, 2015

UFT Datatables | Accessing Datatables ~ Tips and Tricks



I've been working with DataTables for quite long time now, and there are instances that you will think of the ways to maximize the use of those rows and columns of the table.

For a usual scenario, you use the DataTable for the sets of data that is used for each iteration of the code like for instance, User Profile, etc.

To have a quick overview of what I am talking about, here's the sample view of a usual usage of the DataTable.

Figure 1.0 Usual way of using DataTable
Assuming your Test Settings are set to 'Run on All Rows', even without looping your code, it will iterate each row until it reaches the last row.

Figure 2.0 File > Setting > Run


However, you can use the DataTable more than the usual scenario same as above. Let's just say, you are running a full website script (one-way) testing and there are a lot of texts involved - not just keywords or one word data.

Given the scenario above, here's what I do if multiple text are being checked and the component is content maintainable.

Figure 3.0 Other way of using DataTable

Note: Select the 'Run One Iteration only' in the Testing Setting when using this kind of approach.
Figure 4.0 : File > Settings > Run

In this way, you are the master of your datatable, wherein you will be the one to instruct your code on which row and column you will be needing in a certain checking you need.

Monday, July 20, 2015

UFT Datatables | Accessing Datatables


In this blog, I am assuming that you have a background in Recording using Unified Functional Test (UFT). If you don't have any, you can always roam around google search and try to understand some.

First post I will be doing is about Data table. This is the collection of data you will be needing all throughout your automation testing and placed in a table form (exactly like excel sheet).

Simple and straightforward:

Figure 1.1 Getting the data from datatable

Figure 1.2 The actual datatable

Brief Explanation:

  • Dim strFirstName : This is a variable declaration.
  • ':' (colon) : This is denoting that the line after the colon (:) will be treated as the next line of code. This is the same when you write the code like the ff:
               
  • DataTable("strFirstName",dtLocalSheet) : This is the syntax for the data retrieval. The first parameter is the data column name in the actual datatable (see Figure 1.2), the 2nd parameter specifies which Datatable are you referring (dtLocalSheet refers to the 'CodeSnippetsbyRain' sheet in Figure 1.2)
Data table contains two sheets, the Global Sheet where all actions in the same script can access, while the other is the Local Sheet, and only the action can access its own script.