Automated testing is not only about recording playback. Recording playback is amazing by the manufacturers of automated testing tools, but affects many beginners of automated testing and even leads the owners of automated testing projects.
Automated Testing requires a framework suitable for the actual situation of the project. This framework should solve the problems of the script design mode and script management and maintenance.
In the process of building an automated testing framework, some script functions or tools are generally applicable to different frameworks. TiB automated testing studio is developing the framework, we have collected and accumulated many such functions, such as the mail sending function:
Public Function bug_sendbysmtp (strfrom, strto, subject, body, attachment, attr_name)
If (emailaddress = "" or subject = "") then
Call logfile ("function sendmailbysmtp", "error", "Enter argument error ")
Exit Function
Else
Set objsendmail = Createobject ("cdonts. newmail ")
Objsendmail. From = strfrom
Objsendmail. To = strto
Objsendmail. Subject = subject
Objsendmail. Body = body
If attachment <> "" And attr_name <> "" then
Objsendmail. attachfile attachment, attr_name
End if
Objsendmail. Send
Set objsendmail = nothing
End if
End Function
Function for obtaining IP addresses:
Public Function fngetip ()
On Error resume next
Computername = "."
Dim ob1_miservice, colitems, objitem, objaddress
Set ob1_miservice = GetObject ("winmgmts: \" & computername & "\ Root \ cimv2 ")
Set colitems = ob1_miservice. execquery ("select * From win32_networkadapterconfiguration where ipenabled = true ")
For each objitem in colitems
For each objaddress in objitem. IPaddress
If objaddress <> "" then
Fngetip = objaddress
Exit Function
End if
Next
Next
On Error goto 0
End Function
Function for compressing folders:
Function fnzip (ssourcefolder, stargetzipfile)
'This function will add all of the files in a source folder to a zip file
'Using windows 'native folder zip capability.
Dim oshellapp, ofso, ierr, serrsource, serrdescription
Set oshellapp = Createobject ("Shell. Application ")
Set ofso = Createobject ("scripting. FileSystemObject ")
'The source folder needs to have a \ on the end
If right (ssourcefolder, 1) <> "\" then ssourcefolder = ssourcefolder &"\"
On Error resume next
'If a target zip exists already, delete it
If ofso. fileexists (stargetzipfile) Then ofso. deletefile stargetzipfile, true
Ierr = err. Number
Serrsource = err. Source
Serrdescription = err. Description
On Error goto 0
If ierr <> 0 then
Fzip = array (ierr, serrsource, serrdescription)
Exit Function
End if
On Error resume next
'Write the fileheader for a blank zipfile.
Ofso. opentextfile (stargetzipfile, 2, true). Write "Pk" & CHR (5) & CHR (6) & string (18, CHR (0 ))
Ierr = err. Number
Serrsource = err. Source
Serrdescription = err. Description
On Error goto 0
If ierr <> 0 then
Fzip = array (ierr, serrsource, serrdescription)
Exit Function
End if
On Error resume next
'Start copying files into the zip from the source folder.
Oshellapp. namespace (stargetzipfile). copyhere oshellapp. namespace (ssourcefolder). Items
Ierr = err. Number
Serrsource = err. Source
Serrdescription = err. Description
On Error goto 0
If ierr <> 0 then
Fzip = array (ierr, serrsource, serrdescription)
Exit Function
End if
Fzip = array (0 ,"","")
End Function
There are also many common framework functions not listed, such as reading and writing excel, operating folders and files, accessing the database, FTP, string formatting, logging, and so on, common functions of these frameworks play an important role in building an automated testing framework.
These functions are widely used in the general framework of TiB automated testing studio. Contact Us For details about framework development and usage.