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:
- Define an environment variable as
OPEN_URL
. - 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", ...
Get Advanced UFT 12 for Test Engineers Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.