Please post your Web Driver questions in official Web Driver forum

Tuesday, March 30, 2010

Testing XPath in Firebug

Given the lack of testing hooks in web applications, many a times Selenium Users use XPath to work on UI Objects. So far I used to use Selenium IDE to test XPath in Firefox. I read a blog post here and got to know that Firebug itself can be used to test XPath. This is accomplished using $x function in Firefox.









Consider that highlighted text box does not have a constant identifier hence following XPath is to be used > $x("//input[@name='search']")
Write this XPath on Console of Firebug and hit enter -



















Keep mouse pointer on 'input' in console and it would highlight the text box in page.
Using Firebug Lite Firebug can be used for other browsers as well and in turn to test XPath on other browsers.......

Wednesday, March 24, 2010

Working with URL Redirection with VB Scripts

Had chance to work on checking http status VB script. Looks like not all objects work when used URL redirect, so I used "WinHttp.WinHttpRequest.5.1".

Set winhttpreq = CreateObject("WinHttp.WinHttpRequest.5.1")

'Initialize HTTP Request
winhttpreq.Open "Get", "http://iteamic.com/"

'Send HTTP Request
winhttpreq.Send()


Print winhttpreq.StatusText
Print winhttpreq.ResponseText

for now iteamic website redirects to ciber and this code works perfect for it.

Tuesday, March 23, 2010

VB Script and Square Brackets '[]'

I had tough time working with vb script and square brackets '[]'. Looks like square bracket has special meaning when it comes to regular expression in vb script.
I was trying to write DP for check box collection on page as -

******************************************************************************
Browser("name:=.*").Page("title:=.*").WebCheckBox("name:=publishedSectionId[0]").Set "ON"
******************************************************************************

Execution of this line resulted in following error -

******************************************************************************
"Cannot identify the object "[ WebCheckBox ]" (of class WebCheckBox). Verify that this object's properties match an object currently displayed in your application."
******************************************************************************

I wonder if this error makes any sense, any ways problem is with square brackets in name property which is -

****************************
name:=publishedSectionId[0]
****************************

To correct this I provided backslash before square bracket -

****************************
name:=publishedSectionId\[0\]
****************************

and got through. :-)

Monday, March 22, 2010

Data Driven Testing with QTP Using Excel ADO

We all are aware of externalizing test data from test scripts in test automation.
We often stumble upon using excel as test data file, and I have seen crude ways of handling excel.
i.e. - Creating Excel Application object
Opening work book and fetching data
Disadvantages of this approach are detailed on Microsoft website here - http://support.microsoft.com/kb/278973/EN-US/
In a gist following above mentioned approach would be process heavy and would make script execution (especially in case of long running test suites) slow
Another crude way is to use sheet-name (which is still acceptable), Row and Column number (i.e. - (2, 5)), Row and Column range (B5, B10). Using row and column identifier is fragile as insertion of new data set in excel would break existing test scripts.
A better approach to overcome these is to use ExcelADO along with name of Range in Excel.
ExcelADO overcomes process over head and using Range to overcome fragility over Row and Column Range.
In excel an individual cell or collection of cell could be referenced with name. To do this - Select required cell range and use 'Insert' > 'Name' > 'Define' Menu
Following are couple of functions to do same using named range cell in excel file -


'‘**************************************************
'Function Name : Func_GetExcelData
'Description : This function is used to return value from named cell range in excel file
' This method should be used when getting data from individual cell and not from collection fo cell
'Input parameters : strFileName - Name of test data file
' strQuery – SQL Query to execute

'Date of Creation : 19th Feb 2010
'‘**************************************************

Function Func_GetExcelData(strFileName, strQuery)

Dim cn
Dim rs

Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & strFileName & ";" _
& "Extended Properties=""Excel 8.0;HDR=Yes;"""


Set rs = CreateObject("ADODB.Recordset")
rs.Open strQuery, cn

'Remove Carriage Return and return the value
dataString = Split (rs.GetString, Chr(13))
Func_GetExcelData = dataString(0)

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

End Function



'‘**************************************************
'Function Name : Func_GetExcelRangeData
'Description : This function is used to return multiple values from named cell range in excel file
'Input parameters : strFileName - Name of test data file
' strQuery – SQL Query to execute

'Date of Creation : 26th Feb 2010
'‘**************************************************
Function Func_GetExcelRangeData(strFileName, strQuery)

Dim cn
Dim rs

Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & strFileName & ";" _
& "Extended Properties=""Excel 8.0;HDR=Yes;"""


Set rs = CreateObject("ADODB.Recordset")
rs.Open strQuery, cn

'Remove Carriage Return and return the value
dataString = rs.GetString
Func_GetExcelRangeData = dataString

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

End Function




'‘**************************************************
'Function Name : Func_SetExcelData
'Description : This function is used to set data in one cell of excel file
'Input parameters : strFileName - Name of test data file
'strQuery – SQL Query to execute
'strVal - Value to be set
' intIndex - Index where value is to be updated

'Date of Creation : 19th Feb 2010
'‘**************************************************
Function Func_SetExcelData(strFileName, strQuery, strVal)

Dim cn
Dim rs

Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & strFileName & ";" _
& "Extended Properties=""Excel 8.0;HDR=Yes;"""


Set rs = CreateObject("ADODB.Recordset")
rs.ActiveConnection = cn

rs.LockType = 2
rs.Source = strQuery
rs.Open

rs.MoveFirst
rs.Fields(0).Value = strVal
rs.Update

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

End Function

Monday, March 8, 2010

Execute QTP Tests from AOM file

Herein I have got Sample QTP - AOM file.
Such sample files are easily available on net but they hard code test path as well as result path.
In this sample file I am going to read test path and results path dynamically from with in driver script, which would make script more portable
Dim qtpApp 'As QuickTest qtpApplication
Set qtpApp = CreateObject("QuickTest.Application")
Dim qtResultsOpt 'As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable
qtpApp.Launch
qtpApp.Visible = True
qtpApp.Test.Settings.Launchers("Web").Active = False
qtpApp.Test.Settings.Launchers("Web").CloseOnExit = True
qtpApp.Test.Settings.Run.ObjectSyncTimeOut = 120000
qtpApp.Test.Settings.Run.DisableSmartIdentification = True
qtpApp.Test.Settings.Run.OnError = "Dialog"
qtpApp.Test.Settings.Web.BrowserNavigationTimeout = 60000
qtpApp.Options.Run.RunMode = "Fast"
qtpApp.Options.Run.ViewResults = True
qtpApp.Options.Run.MovieCaptureForTestResults = "Never"
qtpApp.Options.Web.AddToPageLoadTime = 10
qtpApp.Options.Web.BrowserCleanup = True
qtpApp.Options.Run.ImageCaptureForTestResults = "OnError"
'Get path to trunk
sn = Wscript.ScriptName 'Script Name
fn = Wscript.ScriptFullName 'Fully Qualified Script Name
fp = Replace(fn, "\" & sn, "") ' Drive / Folder path
Set fso = CreateObject("Scripting.FileSystemObject")
'Open the test in read-only mode
qtpApp.Open fso.GetFolder(fp).ParentFolder& "\test_scripts\<TestName>", True
'Create the Run Results Options object
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
'Set the results location
timeStamp = FormatDateTime(Now, 1)&" "& Hour(Time) &"-"& Minute(Time) &"-"& Second(Time)
qtResultsOpt.ResultsLocation = fso.GetFolder(fp).ParentFolder& "\results\<TestName>\" &timeStamp
qtpApp.Test.Run qtResultsOpt 'Run the test
Set qtpApp = Nothing
Set qtResultsOpt = Nothing
Set fso = Nothing
THanks,
Tarun K

Wednesday, March 3, 2010

QTP Glitches So Far...

Well, I have started work on QTP after having worked on couple of functional test automation tools like – Selenium and Test Complete.
My first impression with QTP has not been very positive; herein I have listed few glitches I experienced so (I can only hope this list not overgrowing with time)
  • No Refactor of code – so if u modify a function name in one place it has to be updated manually in all function calls
  • “General Run Error” – try to check a check box which is disabled and you receive “General Run Error”! Can’t it say object is disable
There have been other mysteriously intermittent instances of “General Run Error” about whom I am still groping in dark
  • If used ExecuteFile to get function definition in Action then there is no way to jump to function definition from action. Function has to be opened manually. (I don’t associate function library as it is going to hardcode path to function)
  • While running QTP tests on a System it can not be used for any other task, QTP keeps bringing browser to top on which tests are executed
  • QTP on locked system, File Upload just does not work on locked system
  • Keep shared repo opened while executing test and be ready for unknown errors
  • Unable to test API on fly (It is Test Complete feature I love most), so if you want to check Web Table data – GetCellData(row, column)
Then you should execute it in test and there is no way to tests it from Object Spy itself
  • Some time have static screen while executing test and I keep waiting for next action, good if there were Test Complete sort of display during test execution
SO FAR………….
THanks,
Tarun K

Close Browser in QTP

Want to close browser on the basis of there creation time, just use –
Browser("CreationTime:=1").Close
THanks,
Tarun K
Fork me on GitHub