Book Image

Advanced UFT 12 for Test Engineers Cookbook

Book Image

Advanced UFT 12 for Test Engineers Cookbook

Overview of this book

Table of Contents (18 chapters)
Advanced UFT 12 for Test Engineers Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing a simple search class


In this recipe, we will see how to create a class that can be used to execute a search on Google.

Getting ready

From the File menu, navigate to New | Test, and name the new test SimpleSearch. Then, create a new function library by navigating to New | Function Library, or use the Alt + Shift + N shortcut. Name the new function library cls.Google.vbs and associate it with your test.

How to do it...

Proceed with the following steps:

  1. Define an environment variable as OPEN_URL.

  2. Insert the following code in the new library:

    Class GoogleSearch
      Public Function DoSearch(ByVal sQuery)
        With me.Page_
          .WebEdit("name:=q").Set sQuery
          .WebButton("html id:=gbqfba").Click
        End With  
        me.Browser_.Sync
        
        If me.Results.WaitProperty("visible", 1, 10000) Then
          DoSearch = GetNumResults()
        Else
          DoSearch = 0
          Reporter.ReportEvent micFail, TypeName(Me), "Search did not retrieve results until timeout"
        End If
      End Function
    
      Public...