Wednesday, December 19, 2018

Test Complete /UFT- Automation of Database

dim objconnection
set objconnection= Createobject("Adodb. co nection)

'function to connect sql server
public function opendbconnection()
aqutils. delay 3000
strcoonectionstring="provoder=sqloledb;datasourcee=strdatasourceval;initial catalog=strcatval;security=sspi;persist security info=true"
objconnection. open strcoonectionstring
if objconnection. state=1  then
   log. message "DB connect"
else
Log. message "Db not connect"
end if
end function

'function to close db connection
public function closedbconnection()
objconnection. close
if objconnection. state <>1  then
   log. message "DB connection close"
else
Log. message "Db not connection not close"
end if

end function

dim strcodedelimiter, strDBrowdelimiter
strdbrowdelimiter="@@"
strcodedelimiter="|"

public function get_db_row()

dim objrecordset, strdbrow
strdbrow=""
if objconnection. state=1 then
    set objrecordset =createobject (adodb. recordset")
    objrecordset. activeconnection=objconnection
   objrecordset. open DBquery, objconnection
   if not objrecordset. eof then
    while not objrecordset. eof
         for intdbcolcounter=0 to objrecordset. fields. count-1  step 1
               strcurrentvalue=objrecordset. fields(intdbcolcounter). value
          if isnull(strcurrentvalue) or strcurrentvalue ="" then
           strcurrentvalue =Null
          end if
strdbrow=strdbrow & strcodedelimiter & strcurrentvalue
next
strdbrow= strdbrow & strdbroedelimiter
objrecordset. movenext
wend
if left(strdbrow, 1)=strcodedelimiter then
    strdbrow =right(strdbrow, len(strdbrow) - 1)
end if
strdbrow =replace(strdbrow, strdbrowdelimiter & strcodedelimiter, strrowdelimiter)
objrecordset. close
set objrecordset =nothing

else
    log. message "no data found"
end if
get_db_row= strdbrow

else
     log. message "db connection fail"
end if

end function

'function to update db row
public function uodate_db_row()
dim objrecordset, strdbrow
strdbrow=""
if objconnection. state=1 then
    set objrecordset =createobject (adodb. recordset")
    objrecordset. activeconnection=objconnection
   objrecordset. open DBquery, objconnection
   if err. description <>"" then
          log. message "no data found in db"
    else
bdbflag=true
end if
else
bdbflag=false
log. message "db connection failed"
end if
update_db_row=bdbflag

end function

'function to compare db value
public function comparedbvalue(strvalidatiinval, strdbvalue)
dim bdbvalflag
if aqutils. vartostr (strvalidatiinval) =aqutils. vartostr (strdbvalue) then
   bdbvalflag=true
else
bdbvalflag=false
end if
comparedbvalue=bdbvalflag
end function

Test Complete / UFT-launch window application

Test Complete
Dbgservices object is only available if dbgservices plugin is installed.
set proc=dbgservices. launchtestedapplication(strapppath)
Res=proc. exists
if Res then
     log. message ("App launch successfully")
else
log. message (" app not started")
end if

UFT
systemutil.run strapppath

Test Complete / UFT-Run functions dynemic through excel files

Hey folks,

sometimes functions execution flow needs to controll through excel files and need to run the functions dynemic, so hope this line of code will help. Same applies to UFT as well.

in excel sheet, for exampme TC1 having FUNC1-10 then,

for fncnt=1 to sheet. columncount
    strfunctionname=""
    if(aqconvert. vartostr(fncnt)) <>"" then
         strfunctionname=aqconvert. vartostr(testcasedriver. value(fncnt))
        functiontorun="Call" & strfunctionname
       execute functiontorun
    end if
next

wishes,
Trupti

Test Complete-Terminate window application or exe using vbscript

dim process, strprocesstokill, strobject, strcomputer

strcomputer="."
strobject="winmgmts://" & strcomputer
'To kill multiple instance like excel or anything use for loop else use without for loop
for each process in getobject(strobject). instanceof("win32_process")
       if (sys. waitprocess(strprocess), 0).exists) then
              sys. process(strprocess). Terminate()
       End if
Next

Tuesday, December 18, 2018

Send Email through vbs using CDO object

set  objemail=createobject("cdo. message")
objemail. from=strmailfrom
objemail. to=strmailto
objemail. subject=strmailsubject
objemail. textbody=strmailbody
strmailattachment="c:\test. btml"
objemail. addattachment strmailattachment
objemail. configuration. fields. item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
objemail. configuration. fields. item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mailhost. ldn... com"
objemail. configuration. fields. item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =25
objemail. configuration. fields. update
objemail. send

Send email through vbs using Outlook Application utility object

set objoutlookmail=createobject("outlook. application")
Set mymail=objoutlookmail. createitem(0)
mymail.display
set mymailproperty=objoutlookmail. activeinsepector
if mymailproperty. iswordmail="trur" then
    set mydoc=mymailproperty. wordeditor
    mydoc. range chr(13)+"Hi All," +chr(13) & " Please see execution status for.... application." +chr(13)
     mydoc.range.insertafter chr(13)+"Regards,"+chr(13) & "support team" +chr(13)
     strmailattachment="c:\test. html"
      mymail. Attachments. add strmailattachment
       mymail. from="abc@gmail.com"
       mymail. to="xyz@gmail.com;pyz@gmail.com"
      mymail. subject="Application Automation Execution Reports"
       mymail. send
end if
Set mymail.=Nothing
Set mydoc=Nothing
Set objoutlookmail=Nothing