How to use QTP to automate different Browsers (with same code)
Suppose, we have object for different browsers:
Set objIE=Browser(“application version:=internet explorer.*”)
Set objFF=Browser(“application version:=Mozilla firefox.*)
Set objChrome=Browser(“application version:=Chrome.*)
‘Set page object as per the browser on which script is to be run
‘we are reading browser on which script is to be run from datatable/excel
If script is to be run on IE Then
Set objPage=objIE.Page(“title:=.*”)
SystemUtil.Run “iexplore.exe”
ElseIf script is to be run on FF Then
Set objPage=objFF.Page(“title:=.*”)
SystemUtil.Run “firefox.exe”
ElseIf script is to be run on Chrome Then
Set objPage=objChrome.Page(“title:=.*”)
SystemUtil.Run “chrome.exe”
End If
‘same function can be used for different browsers
Call sameCodedifferentBrowser(objPage)
Public Function sameCodedifferentBrowser(oPage)
objPage= oPage
Execute(oPage.Parent.Navigate “http://www.gmail.com”)
Execute(oPage&".Sync")
End Function
For more articles like this, please visit http://learn2automate.wordpress.com
Here, we are using Execute function to reuse the same code for different browsers. To know more about Execute function, stay tuned for my next blog post.....
Note: we can use this technique to automate (or we can say, test eventually) only those test cases (on different browsers) which use same methods to perform same actions (or at least support those methods) for different browsers
For more articles like this, please visit http://learn2automate.wordpress.com