Showing posts with label Test Complete. Show all posts
Showing posts with label Test Complete. Show all posts

Saturday, August 8, 2020

Find a Filename from folder path

 Public Function fnFindFileFromPath(SearchPath, SearchFileName, dataSht) As String

    Dim StrFile As String

    'Debug.Print "in LoopThroughFiles. SearchPath: ", SearchPath

 '   StrFile = Dir(SearchPath & "\*" & SearchFileName)

    StrFile = Dir("D:\Test\")

     While (StrFile <> "")

      If InStr(StrFile, "Test") > 0 Then

         MsgBox "found " & StrFile

         Exit Function

      End If

     StrFile = Dir

    Wend

End Function

Sunday, June 14, 2020

Test complete useful content

  • Programming language supported by test complete
    1. Jscript, vbscript, c#, c++,delphi,python
  • Recording mode in Test complete
    1. Simple recording – shift+F1
    2. Low level recording – shift +F4
    3. Stop recording – shift+F11
  • Capture object in test complete
    1. Object spy
    2. Recording
    3. Find method-
      • Find
      • Findchild
      • FindAllchildren
      • Findall
  • Checkpoints in Test complete
    1. File
    2. Web service
    3. Database table
    4. Property
    5. Object

  • Run, pause and stop the test run
    • Run – F5
    • Pause – Shift+F10
    • Resume – shift +F3
    • Stop – shift +F2 (in scripts - using the Runner.Stop or Runner.Halt method)
  • Debugging in Test complete
    • Using debugging we can evaluate variable values, define debug points and go through steps
    • Running test through debugging- we can run to the cursor, stepping through test and set next execution step too
    • Breakpoints- using breakpoint we can create and modify the properties of variables
    • Debug panel- call stack panel, local panel and watch list panel
  • Export Test result format for testcomplete (Log.SaveResultsAs is use to store the result from script and Use the /exportLog command-line argument:)
    • Junit report
    • Mht
    • Html
    • Pdf
    • Xml
    • tclogx

Environment variables
If you have a system variable and a user variable with the same name:
·         To get the user variable, use aqEnvironment.GetEnvironmentVariable.
·         To get the system variable, use WMI.GetEnvironmentVariable.

Regular Expression
  1. Native Regular expression (built into scripting language)
    1. Example in vbscript
Dim re, matches, match

  
Set re = New RegExp
  re.Pattern = "gr[ae]y"
  re.IgnoreCase = 
True
  re.Global = 
True ' Find all occurrences of the pattern

  
Set matches = re.Execute("Do you spell it gray or grey?")
  
For Each match In Matches
    Log.Message(match.Value)
  
Next
  1. Non native regular expression (own regular expressions) syntax: obj.Find("WndCaption", "regexp:pattern"); example: notepad.Find("WndCaption", "regexp:.* Notepad", 5);


NameMappingNameMapping is one of the important features of TestComplete through which we could provide a Custom Name for any selected object. The unique name is created by using some special values

If your computer resolution will be change, your same script will be run or it will get fail
There are two possibilities -Yes! Our script gets fail in case if we implement Record and Playback methodology. Yes! Our Script will be run successfully If we Implement Name mapping or Descriptive programming methodology

If any unexpected windows pop up during your script in TestComplete, how can you handle that- Use OnUnexpectedWindow Event to handle unexpected windows

distributed testing and how it can be achieved using TestComplete Distributed testing means that a test consists of several parts and each of them is performed on a separate computer. TestComplete uses Network suite plugin to achieve distributed testing.

Launch desktop application- dbgservice plugin should install
  1. Using dbgservice.launchapplication(pathof application)
  2. Using dbservice.launchtestedapplication(pathof application)
  3. Using Testedapplication.launch=true, testedapplication.run()

Log operations
Log.message Log.Message(MessageTextAdditionalInformationPriorityAttrPictureFolderID)
Log.error (Log.Error(MessageTextAdditionalInformationPriorityAttrPictureFolderID)
Log.picture
Log.Event Log.Event(MessageTextAdditionalInformationPriorityAttrPictureFolderID)
Log.warning (Log.Warning(MessageTextAdditionalInformationPriorityAttrPictureFolderID)

String functions

  • aqString.Compare(String1String2CaseSensitive) – compare two string casesensitive(true,false) and return 0 if match else 1 or -1.
  • aqString.Concat(String1String2) – concate two string
  • aqString.Find(InputStringSubStringStartPositionCaseSensitive)- to find the first occurrence of a substring in the input string
  • aqString.GetChar(InputStringPosition) to get the character located at the specified position within a string (ex. Aqstring.getchar(“abc”,2) return b)
  • aqString.SubString(InputStringStartPositionLength) to obtain a text fragment starting from the specified position and having the specified length. Ex. aqString.SubString(“123456789”, 3, 5) returns 45678
  • aqString.Replace(InputStringStringToReplaceSubStringCaseSensitive)
  • aqString.ToLower(InputString)
  • aqString.ToUpper(InputString)
  • aqString.Trim(InputStringSpace)
  • aqString.GetLength(InputString) -returns the total number of characters in the input string


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

Generate filename with date time stamp and separate file name and path from given file path

Hi folks,

many times we need to create the dummy or new file or report file with date timestamp appending to file name. Also, from the given file path we need to separate the file name and file path then definitely this post might help you.

Public Function AddResultTestdatafile(strFilePath)
   
    Workbooks.Add Template:=strFilePath
    strNewFileTempName = getFName(strFilePath)
    strTestFileNameval = Split(strNewFileTempName, ".")
    strNewFilePath = getPath(strFilePath)
    'to generate file name appending datetime stamp
    strNewTestFileName = strTestFileNameval(0) & "_" & "DummyData" & "_" & Year(Date) & Right("00" & Month(Date), 2) & Right("00" & Day(Date), 2) & Right("00" & Hour(Time), 2) & Right("00" & Minute(Time), 2) & Right("00" & Second(Time), 2) & ".xlsx"
    ActiveWorkbook.SaveAs _
        Filename:=strNewFilePath & strNewTestFileName
    ResultDummyFilename = strNewFilePath & strNewTestFileName
    AddResultTestdatafile = ResultDummyFilename
   
End Function

'to get the path from given file path
Function getPath(pathfile) As String: getPath = Left(pathfile, InStrRev(pathfile, "\")): End Function

'to get the file name from given file path
Function getFName(pathfile) As String: getFName = Mid(pathfile, InStrRev(pathfile, "\") + 1): End Function

Cheers.
TJ

Thursday, May 28, 2020

Getting row index for particular given string value of string

Hi Folks,

Sometimes, you need to find the row index of particular row in sheet based on fixed value string and need to operate some operation based on that row like adding and delete row above and below that string value row, this code might help you.

strSearchTxt ="This is search row text for index find of this row"
Dim iTextRow As Long: iTextRow = GetTextRow(strSearchTxt )

Public Function GetTextRow(strSearchTxt)
GetTextRow = 0
With ActiveSheet
    Set Rng = .UsedRange.Find(strSearchTxt)
    If Not (Rng Is Nothing) Then GetTextRow = Rng.Row
End With
End Function

Cheers.

Get Column index based on column name using vba

Hi folks,

If you need to find the column index based on column name, when your column sequence is not fixed in your sheet, please find below code which might helpful to you.

Code sample 1:
 Set findrng = wST.Range("1:1")
 ColNameIndex = findrng.Find("searchcolname").Column

Code sample 2:
strnameindex = wST.Match("searchcolname",wST.Range("1:1"), 0)

Code sample 3:
Function GetHeaderColumn(shRead As Worksheet, header As String) As Integer
    Dim headers As Range
    Set headers = shRead.Range("1:1")
    GetHeaderColumn = IIf(IsNumeric(Application.Match(header, headers, 0)), Application.Match(header, headers, 0), 0)
End Function

Cheers.
TJ.

Wednesday, April 15, 2020

Integration of testcomplete with Jenkin

Integrating Test complete with jenkin can be in following way

•By using the TestComplete support plugin. – most convenient way
•By using the special SessionCreator command-line utility that is shipped along with TestComplete.
•By running TestComplete from the command line.

Pre requisite
Test complete must be available on jenkin node
Test complete license should be accessible from jenkin node

Run TestComplete tests in Jenkins
  1. Install the TestComplete support plugin. In jenkin- manage jenkin>manage plugin>switch available tab>testcompletesupport plug in and install without restart
  2. Prepare jenkin node
    1. Enable remote desktop connection, configure group policies, and do a few more preparatory actions
    2. Configure slave computers as Jenkins nodes and launch the slave agent. For complete information
  3. Add your TestComplete tests to Jenkins builds -You can add your TestCompletetests in Jenkins by using Freestyle Jobs or Pipelines

Test results
After the build is finished, you can view the results of your TestComplete tests in Jenkins on the build page. To do this open the build page in your browser and click TestComplete Test Results in the menu on the left

Export results
With TestComplete, you can export test results in various formats: tcLogX or .mht and JUnit report

Reference by support of smart bear and credit goes to them.