Example of Descriptive Programming using Regular Expressions



Test Steps:– Fill company name and click on “Get Quotes”.New page loads and click on “Historical Prices”

We will use “Descriptive Programming” and “Regular Expressions” to solve the problem in a easy and smart way.

Step1:- Look for unique properties to identify the objects on the page
Step2:- Use “Regular Expressions” to solve the problem of redefining the page objects when new page opens.

Code Part:- 

‘Creating the Page object using DP and RG Expressions
Set objYahoo = Browser(“CreationTime:=0”).page(“url:=*”)

‘Function call to search stocks
fnStocks “infy”

Public function fnStocks(sCompany)

‘Setting the compnay name and clicking on Get Quotes
objYahoo.WebEdit(“html id:= txtQuotes”).Set sCompany

‘Clicking on the get Quotes button
objYahoo.webbutton(“html id:= btnQuotes”).Click

‘Clicking on historical data link and doing error handling

If“text:=Historical Prices”,“html tag:=A”).Exist(5) Then“text:=Historical Prices”,“html tag:=A”).Click
    reporter.ReportEvent 0,“Historical Data”,“Available for the company = “&sCompany
    reporter.ReportEvent 1,“Historical Data”,“Not Available for the company = “&sCompany
End If

End Function

Leave a Reply

Your email address will not be published. Required fields are marked *