Skip to main content

Posts

Showing posts with the label vb script

Working With FCK editors

I had troubles working with FCK editors using QTP. As these editors are recorded as “WebElement” it is not possible to perform “Set” operation on them I came across two posts which talk about dealing with this issue,   One is of Tarun’s where in talks about using “object” as well as “DeviceReplay” methods which could be used to simulate control on FCK editor He suggests not using “object” for browsers other than IE as it is supported only in IE     Browser ( " testB " ). Page ( " testP " ). Frame ( "Frame" ). WebElement ( " WebElement " ). object . innerText = " Text ” Browser ( " testB " ). Page ( " testP " ). Frame ( "Frame" ). WebElement ( " WebElement " ). object . innerHTML = "<h1> T ext</h1> ”     While other method uses object “DeviceReply” object...

Strange QTP Errors and Possible Solutions

Herein I have listed couple of error which I encountered while working with QTP. Some of these are very cryptic and you just can not guess about their Raison d'être. I have listed these errors hoping it would help a new bird. Error while opening Test On Debug Error with Function Error while using a function whose definition was not available in Action Unable to work with IE Unable to recognize IE window; had to restart the browser General Run Error There have been multiple instances of General Run Error with QTP; they just don’t let u know as to what went wrong. On such instance is when I was mistakenly trying to check a check box which was disabled. Instead of General Run Error, there could have been a more comprehensible error like – “object is disabled…”

QTP AOM File

Here in I have got sample AOM file which invokes QTP test. This file also pushes test results to a designated folder. Herein there is no hard coding of path ant where in AOM file - ################################################## 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 = 240000 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....

Reading Outlook Contents From VB Script

There are instances when an application involves mail delivery for certain app features. one way to automated this is to hook with Outlook and read content of mail (though I am not very comfortable with this approach anyways!) #################################### 'Get the Count of Items in Inbox Set app = CreateObject("Outlook.Application") Set nameSpace = app.GetNamespace("MAPI") Set MyFolders = nameSpace.GetDefaultFolder(6) MsgBox MyFolders.Items.Count 'Read unread items in Inbox Set cols = MyFolders.Items For each mail In cols If mail.unread Then MsgBox mail.subject MsgBox mail.sendername MsgBox mail.body mail.unread=false End If Next ####################################

VB Script and ADO DB

VB Script can be used to establish db connection. This is very useful in QTP for writing db test cases. DB connection can be established for both SQL Server Authentication as well as Windows Authentication - ######################################### Function Func_dbConnect On Error Resume Next 'Creating the Connection Object set cn = CreateObject("ADODB.Connection") 'Setting the Data Source strCS = "Driver={SQL Server}; Server=1.1.1.1; Database=GSBREG_021010; UID=us; PWD=us;" 'Open Connection cn.Open strCS If (Err.Number 0) Then MsgBox("Login Failed") End If Set Func_dbConnect = cn End Function Sub ExecuteSQLQuery Set cn = Func_dbConnect() 'Creating RecordSet Object Set rs = CreateObject("ADODB.recordset") rs.CursorType = 2 'SQL query FetchAcademicLevels = "Select even_id from allocation_event"_ ...

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.

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 bracke...

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 ...

Deallocating memory in VB Script

I came across a few articles which talk about setting objects to 'Nothing' after its usages to release memory though I did not find any specific pointer about normal variables. I variable should be set to 'Empty' to deallocate memory, i.e. ****************************** Dim aVariable aVariable = 1 aVariable = Empty MsgBox IsEmpty(aVariable) Dim aObject Set aObject = CreateObject("Scripting.FileSystemObject") Set aObject = Nothing MsgBox aObject Is Nothing ****************************** For more on this refer here commented on - 16th Feb 2010 Looks like some one has different thought here

Using ExcelADO to fetch data from excel

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 a...