Example of Descriptive Programming using Regular Expressions – User friendly Tech help
Scenario:-n
AUT:- http://in.finance.yahoo.com
n
Test Steps:– Fill company name and click on “Get Quotes”.New page loads and click on “Historical Prices”
n
nSolution:-
nWe will use “Descriptive Programming” and “Regular Expressions” to solve the problem in a easy and smart way.
n
nStep1:- Look for unique properties to identify the objects on the page
nStep2:- Use “Regular Expressions” to solve the problem of redefining the page objects when new page opens.
n
Code Part:-
n
‘Creating the Page object using DP and RG Expressions
nSet objYahoo = Browser(“CreationTime:=0”).page(“url:=http://in.finance.yahoo.com.*”)
n
n‘Function call to search stocks
nfnStocks “infy”
n
Public function fnStocks(sCompany)
n
‘Setting the compnay name and clicking on Get Quotes
nobjYahoo.WebEdit(“html id:= txtQuotes”).Set sCompany
n
‘Clicking on the get Quotes button
nobjYahoo.webbutton(“html id:= btnQuotes”).Click
n
‘Clicking on historical data link and doing error handling
n
If objYahoo.link(“text:=Historical Prices”,“html tag:=A”).Exist(5) Then
n objYahoo.link(“text:=Historical Prices”,“html tag:=A”).Click
n reporter.ReportEvent 0,“Historical Data”,“Available for the company = “&sCompany
nelse
n reporter.ReportEvent 1,“Historical Data”,“Not Available for the company = “&sCompany
nEnd If
n
End Function
n