' Open notepad
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad", 9
' Give Notepad time to load
WScript.Sleep 500
' Do The Paste
WshShell.SendKeys "%e"
WshShell.SendKeys "p"
Saturday, April 2, 2011
Tuesday, June 29, 2010
How to handle null strings
In TestComplete whenever DDT diver or array or anything returns null or nothing instead of a string value then it gives error message. For example if you are fetching values using the DDT driver as follow it will return you the data string from the excel file if the value exists:
'path is the path of axcel file
'sheet is the sheet ID of excel file
'A is the column name in excel file
set inputdata = DDT.ExcelDriver(path,sheet)
name = inputData.value("A")
In case if it does not exists then, it will trough an error/exception. You can handle it versy easily by using &"" with the string.
set inputdata = DDT.ExcelDriver(path,sheet)
name = inputData.value("A") &"" 'this will add nothing but will remove the exception you are getting.
How to use Regular Expression to test Email ID and other strings
'Here x is the string that needed to be tested and y is the pattern against which x will be tested
Function RegExpression(x,y)
Dim reg
Set reg = New RegExp
reg.Pattern = y ' Regular Expression filter
reg.IgnoreCase = True 'ignoring the case sensitive
RegExpression = reg.Test(x) ' Test the captured value against the filter
End Function
The above function can be used in the main procedure as:
Sub RegularExpression
x = "0.10" ' Captured value
y = "0[.]10" ' Regular expression filter and expected value
z = RegExpression(x,y) ' Call the function
if z = -1 then
log.message "The value is valid"
else
log.error "The value is not valid"
end if
End Sub
'An email ID can be tested with Regular expression using the above function by passing the following patern:
'here y can change as per the characters allowed in the email ID
Sub RegularExpression
x = "abc27@yahoo.com" ' Captured value
y = "^[A-Z0-9]+@[A-Z0-9]+.[A-Z]{3}" ' Regular expression filter and expected value
z = RegExpression(x,y) ' Call the function
if z = -1 then
log.message "The value is valid"
else
log.error "The value is not valid"
end if
End Sub
How to get excel row count
function get_row_count(path,sheet)
dim inputdata
dim rowc
set inputData = DDT.ExcelDriver(path, Sheet)
while not inputdata.EOF
inputdata.Next
rowc = rowc+1
Wend
get_row_count = rowc
end Function
Wednesday, November 25, 2009
Testcomplete: To check if the file exists and to delete a file if it exists
Below is the vbscript code that can be used to check if the file exists on system or not
'In below examples: path is the path of file like "c:\text.txt"
Sub Main
set fs=createObject("Scripting.FileSystemObject")
If not fs.FileExists(path) Then
Log.Message("Fail: file does not exist")
Else
Log.Message("Pass: File exists")
End If
End Sub
Below is the code to delete a file
Sub Delete
set fs=createObject("Scripting.FileSystemObject")
If not fs.FileExists(path) Then
Else
fs.deletefile(path)
End If
End sub
Tuesday, November 24, 2009
TestComplete: To get all the sheets name in your excel workbook
To get all the sheets name from the excel file.
Sub Main
Set p = Sys.WaitProcess("EXCEL")
'this will Make sure you close any Excel work book already open
If p.Exists Then
Call p.Terminate()
End If
'This is setting the driver
Set MsExcel = Sys.OleObject("Excel.Application")
'This will open you workbook
'Specify the location of your excel file
Call MsExcel.Workbooks.Open("c:\test.xls")
MsExcel.Visible = True
'To Loop through all the sheet
for I = 1 to MsExcel.sheets.Count
'To activate the sheet
msexcel.Sheets(I).Activate
'To get the name of the active sheet
MsgBox(MsExcel.activesheet.name)
Next
End Sub
Monday, November 16, 2009
Testcomplete : Data Driven Testing Framework
Data-driven testing is a framework where test input and output values are read from data files (datapools, ODBC sources, cvs files, Excel files, DAO objects, ADO objects, and such) and are loaded into variables in captured or manually coded scripts. In this framework, variables are used for both input values and output verification values. Navigation through the program, reading of the data files, and logging of test status and information are all coded in the test script.
Data-driven testing means using a single test to verify many different test cases by driving the test with input and expected values from an external data source instead of using the same hard-coded values each time the test runs. This way, you can test how the application handles various input without having a lot of similar tests that only have different data sets.
To learn how to perform Data Driven testing using Testcomplete, you can view the following video file: Data Driven Testing Video Tutorial
Thursday, November 5, 2009
TestComplete : To access column of Infragistics Grid using its index
To access column of Infragistics Grid using its index:
------------------------
function get_column(grid, columnindex)
set get_column = grid.DisplayLayout.Bands.Item(0).Columns.Item(columnindex)
end Function
---------------------
You can use this function as bellow to get the header caption of a particular column
sub main
MsgBox( get_column(DIGridControl,4).Header.get_Caption.ToString)
end sub
TestComplete : To access cell of Infragistics UltraGrid using row index and column index
To access Infragistics grid's cell on the basis of row and column index:
-------------------
function get_cell(grid, row, column)
set get_cell = grid.DisplayLayout.Rows.Item(row).Cells.Item(column)
end Function
-------------------
You can use this function as follow to set the value in it:
sub main
'here Ultragrid is the object of grid
call get_cell(Ultragrid, 0, 4).set_Value("checking")
end sub
Wednesday, November 4, 2009
TestComplete : To make a perticular tab selected (Infratistics Ultratabcontrol)
In infragistics Ultratabcontrol clicktab() method do not work correctly to make a tab selected or active. It gets recorded but at the time of play, the testcomplete does not click on the tab.
In this case you can use the following procedure to select a tab.
'--------------------------
'tabcontrol is the name of ultratabcontrol object
'tabname is the name of tab (string)
sub tab_click(tabcontrol, tabname)
dim I
for I = 0 to tabControl.Tabs.Count-1
if tabControl.VisibleTabs.get_Item(I).Text.OleValue= cstr(tabname) then
tabControl.VisibleTabs.get_Item(I).Selected = true
end If
Next
end Sub
'------------------------------------------
Subscribe to:
Posts (Atom)
