Sunday, June 14, 2020

Working with different controls in Test complete

Working with different controls in Test complete

Button
  1. To click button- mybutton.clickmybutton.clickbuttonmybotton.keys “~F” (shortcut assigned to that button ex. Find), sys.keys [tab][tab] sys.keys[x32] (keystroke of navigation)
  2. To check button state- mybutton.enable
  3. To take image of the button – mybutton.wimage

Checkbox
  1. To select or unclear the checkbox – mycheckbox.clickbutton cbuncheckedmycheckbox.clickbutton cbcheckedmycheckbox.click (toggle using select/unselect), mycheckbox.keys[tab] mycheckbox.keys[x32](using keystrokes)
  2. To check the state of checkbox – mycheckbox.wstate
  3. Checkbox image – mycheckbox=sys.process(“mapp”).window(“mywindow”).window(“checkbox”), mycheckbox.wimage

Combobox
  1. Type of combobox – simple combox with edit option, dropdown with list option, drop down combo box with edit option
  2. Select item from combobox – mycombo.clickitem(“Apple”), mycombo.clickitem(3) (by caption or index, we cant select multiple together), mycombo.keys(4), mycombo.keys[down](by keystroke as well and up and down method too)
  3. Getting combo box item- mycombobox.wItem(5) return the name of the item by given index, windex=mycombo.selectedindex,mycombo.witem(windex) will return selected item value, mycombo.witemlist will give array of all items from the list and need to write for loop to get all items using aqstring.getlistitem
  4. Get the number of item count in combo- mycombo.witemcount
  5. To take image of correspond item’s default image- mycombo.witemimage, item’s selected image- mycombo.witemselectedimage

Edit
  1. Getting edit control text- editctrl=sys.process(“notepad”).window(“notepad”).window(“edit”), editctrl.keys(“this is my text”), mytxt=editctrl.wtext
  2. Entering text in edit- editctrl.wtexteditctrl.settexteditctrl.keys(“text”)
  3. Working with password- edit.wpasswordchar
  4. Obtain text limit in edit – edit.wlimt

Radiobutton
  1. Selecting radio button- myradio.setfocusmyradio.clickmyradio.clickbutton()
  2. State of radio button- myradio.wchecked
  3. Get image of radio button- myradio.wimage
  4. Working with radiogroupmyradiogroup.setfocu

Listbox
  1. Select single item from list -mylist.clickitem(index), mylist.dbclickitemmylist.selectitem(index), mylist.keys(index), mylist.keys[tab] (keystroke)
  2. Select multiple items from list- str=item1,item2, mylist.multiselect(str)
  3. Getting single list item- mlist.witem(index)
  4. Getting multiple list item – mylist.wselecteditemsmylist.witemlist
  5. Number of list item count- mylist.witemcount
  6. Determine current item- mylist.wfocus
  7. Checking list box item selected or not- mylist.wselected(index)

Thursday, June 11, 2020

VBA Function to Clear content except header rows and Get col headers in string or array

Folks,

sometimes need to use only headers or template from existing file then below code might help to clear the data. Sometimes you need to capture the column header in array or string then below function will help you.

Function DeleteExceptFirstHeader(shWrite)
    'shWrite.Rows("2:" & Rows.Count).ClearContents
    shWrite.Rows("2:" & Rows.Count).Clear
End Function

Function fnReadColHeader(wST As Worksheet)
    Dim strData() As Variant
    lastCol = wST.Range("a1").End(xlToRight).Column
    strData = wST.Range("1:" & lastCol).Value
    strHeaders = 0
    Dim columnCounter As Long
 
    For columnCounter = LBound(strData, 1) To UBound(strData, 1)
        strHeaders = strHeaders & ":" & strData(1, columnCounter)
    Next columnCounter
 '   MsgBox strHeaders
   fnReadColHeaderDRF = strHeaders
End Function

Cheers.
TJ

VBA Function to Generate Dummy data for numbers, string and date values

Hi guys,

If you need to generate any random dummy data for string/alphanumeric/date/numbers(2 digit/3 digit) then below logic might help you.

provide your sDatatype in below select case.

  Select Case sDataType
            Case Is = "Alphabets"
                dtRndData = UCase(Cnst) & Vowel & Cnst & Vowel & Cnst
            Case Is = "Alphanumeric"
                DLocation = UCase(Cnst) & Vowel & Cnst & Vowel & Cnst
                dtRndData = Tens() & " " & DLocation
            Case Is = "Date"
                dtRndData = GetRndDate(#12/1/1965#, #5/31/2020#)
            Case Is = "Numbers"
                dtRndData = Tens()
        End Select

Function LName()
    Dim i As Long, Tmp As String
    LName = UCase(Cnst) & Vowel & Cnst & Vowel & Cnst
End Function

Function Vowel()
      Dim V
      V = Array("a", "e", "i", "o", "u")
      Vowel = V(Int((5 * Rnd)))
End Function
   
Function Cnst()
    Dim C
    C = Array("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", _
                "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z")
    Cnst = C(Int((21 * Rnd)))
End Function
Function Tens()
    Tens = Int(100 * Rnd)
End Function

Function Hundreds()
    Hundreds = Int(1000 * Rnd)
End Function

Function GetRndDate(dtStartDate As Date, dtEndDate As Date) As Date
    On Error GoTo Error_Handler
    Dim dtTmp                 As Date

    'Swap the dates if dtStartDate is after dtEndDate
    If dtStartDate > dtEndDate Then
        dtTmp = dtStartDate
        dtStartDate = dtEndDate
        dtEndDate = dtTmp
    End If

    Randomize
    GetRndDate = DateAdd("d", Int((DateDiff("d", dtStartDate, dtEndDate) + 1) * Rnd), dtStartDate)

Error_Handler_Exit:
    On Error Resume Next
    Exit Function

Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: GetRndDate" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Function

Getting data type from given value whether Number/String/Date/Alphanumeric

Hi Folks,

Sometimes need to generate some random test data based on given value of cell or variables data value, whether it is number, date, string, alphabets.
strOrignalData="John Smith" 'DOB,phone number any original data

 sDataType = GetDatatype(strOrignalData)

Public Function GetDatatype(strData)
            numbers = 0
            alphabets = 0
            specialChar = 0
            For i = 1 To Len(strData)
                b = Mid(strData, i, 1)
                If IsNumeric(b) Then
                 numbers = numbers + 1
                ElseIf (Asc(b) >= 97) And (Asc(b) <= 122) Or Asc(i) >= 65 And Asc(i) <= 90 Then
                 alphabets = alphabets + 1
                ElseIf InStr(b, "/") > 0 Then
                 specialChar = specialChar + 1
                Else
                    'None
                End If
            Next
            If numbers = Len(strData) Then
                strdatatype = "Numbers"
            ElseIf specialChar >= 2 Then
                strdatatype = "Date"
            ElseIf alphabets > 0 And numbers = 0 Then
                strdatatype = "Alphabets"
            Else
                strdatatype = "Alphanumeric"
            End If
            GetDatatype = strdatatype
         
End Function

cheers.
TJ