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

Tuesday, November 27, 2018

Test Complete- Search data in csv or text file

public function searchdatainfilr()
strfilepath="c:\test. csv
set objfso=createobject(" scripting. filesystemobject")
set infile=objfso. opentextfile("strfilepath")
set outpath=objfso. opentextfile(strfilepath & ". tmp", 2,true)
dim irowcnt
irowcnt=0

do while not infile. atendofstream
line=inline. readline
fullfile=fullfile & line
loop

log. message fullfile
if instr(fullfile, "searctxtval") >0  then
     log. message "validation pass"
else
    log. message "validation fail"
end if
infile. close
outfile. close
objfso. deletefile(strfilepath l
objfso. movefile strfilepath & ". tmp", strfilepath

end function

Tuesday, November 20, 2018

Test Complete- Move file from source to destination

function fnMovefile(Sourcepath, destinationpath)
'path given till folder level only
' code to find csv file from particular location
set foundfiles=aqfilesystem. findfiles(sourcepath, "*.csv")
if not foundfiles is nothing then
    while foundfiles. hasnext
        set afile=foundfiles. next
        var_foundfiles=afile. name
    wend
else
     log. message "no files were found"
end if
call aqfilesystem. copyfile(soyrcepath, deatinationpath)
nowtime=aqdatetime. time()
nowtime=aqstring(nowtime, ":", "_")
nowtime=aqstring(nowtime, "pm", "_")
nowtoday=aqdatetime. today()
nowtoday=aqconvert. vartostr(nowtoday)
nowtoday=aqstring.replace(nowtoday,"/","_")
destinationfile=destinationpath & "\" & varfoundfiles
destinationfilerename=destinationpath & "\" & nowtine & "_" & nowtoday & "_" & varfoundfiles
call aqfile. rename(destinationfike, desti ationfilerename)
log. message " move file with rename successfully"
end function

Test Complete - Find value is present in excel sheet or not

function searchdatainexcel(strpath, searchcol, searchval)
path="c:abc. xls"
set searchdata=DDT. exceldriver(strpath, "sheet1", true)
do while not searchdata. EOF
   if aqconvert. vartostr(searchdata. value(searchcol)) =searchvalue then
       blnflag=true
       exit do
   else
       blnflag =false
   end if
searchdata. next
loop
if blnflag =true then
    log. message "record match"
else
   log. message "record not match"
end if
end function

Monday, October 8, 2018

Tosca intergration with c#

Hey folks,
Tosca is one of tge tool used for automation, however personally i dont feel much great tool.
You could write your own advanced logic in C# and integrate it with Tosca. I found this link after almost 1.5 months efforts.
Though it's challenging but helpful to get help after many tickets on tosca support
.
Integration of C# with Special Execution task
  1. First we need to create a new XModule in our TOSCA Commander:
  2. On this new Module switch to the Properties tab and create two additional configuration parameters and name them "SpecialExecutionTask" and "Engine".
  3. The Engine parameter specifies which assemblies/engines are searched for theSpecialExecutionTask specified in the second parameter. We are going to tag our assembly with “TutorialEngine” in order to tell TOSCA to search in our assembly. The key for ourSpecialExecutionTask is "Hello World"
Preparing Visual Studio
First create a new Class Library in C# and make sure you have selected the .Net Framework 4.0. There are 2 assemblies we need to reference in order to successfully create our SET:
·     Tricentis.Automation.Creation
·     Tricentis.Automation.Interaction
These can be found in “%TRICENTIS_HOME%\Automation\Framework\”.
Right click on References in your Solution Explorer and choose Add Reference: Answer the following warning that might pop up by clicking "Yes". Change the "Copy Local" property of the References to "false".
Next we are going to tag our AssemblyInfo (can be found in your project, under Properties->AssemblyInfo.cs) with the necessary information, we already defined in our Module:
We are going to use the namespace
using Tricentis.Automation.Creation.Attributes;
and add the following EngineIdAttribute:
[assembly: EngineId("TutorialEngine")]
 Now we are going to implement our SpecialExecutionTask. We need a class "HelloWorld.cs". You can either create a new class or rename the automatically created "Class1.cs". Then add an attribute to this class. This links the XModule to our class. Add
usingTricentis.Automation.Engines.SpecialExecutionTasks.Attributes;
to any existing usings, as well as the attribute SpecialExecutionTaskName
[SpecialExecutionTaskName("HelloWorld")]
public class HelloWorld {
}
to our class. 
Our class is going to derive from the abstract class SpecialExecutionTask. We are going to override the Execute method. In this method we return a passing resultwith our message.
public class HelloWorld : SpecialExecutionTask {
    public override ActionResultExecute(ISpecialExecutionTaskTestAction testAction) {
        return newTricentis.Automation.Engines.PassedActionResult("Hello World!");
    }
}
Now build the assembly for AnyCPU and copy the output *.dll to %TRICENTIS_HOME%\Automation\Framework\
You should now be able to use the XModule in a TestCaseand see the results in your ExecutionList:

cheers
Trupti

Friday, October 5, 2018

Read XML file as string using Vbscript

hi folks, To read XML file as entirely string we can use below logic. Hope it will useful.

set xmldoc=createobject("MICROSOFT. XMLDOM")
xmldoc. async=false
xmldoc. load(recentxmlfilepath)
for each ochdnd in xmldoc. documentelement. childnodes
     strxmldocline=ochdnd. nodename & ":" & ochdnd. text & vbcrlf
xmldocdata= xmldocdata & strxmldocline
next
msgbox xmldocdata

cheers
Trupti

Thursday, August 2, 2018

Text file edit using UFT/QTP/VBS

Hi folks

Create test file on path with content.

Test file edit data-Trupti to Jethva
Data -Trupti

Save file c:\test.txt

Now write function as
Public function fnModifytextfile(strfilepath,strchangedata)
Const ForReading=1
Const ForWriting=2
Set objfso=createobject(“scripting.filesystemobject”)
Set myfile=objfso.opentextfile(strfilepath,forreading,true)
Set mytemp=objfso.opentextfile(strfilepath & “.tmp”, forwriting,true)
Do while not myfile.atendofstream
       Myline=myfile.readline
       If instr(myline,”Data”) then
            Orignaldata=split(myline,”-“)
            Orignaldatachange=orignaldata(1)
            Datatobechange=“ “& strchangedata
            Myline=replace(myline,orignaldatachange,datatobechange)
       Endif
       Mytemp. Writeline myline
Loop
Myfile.close
Mytemp.close
Objfso.deletefile(strfilepath )
Objfso.movefile strfilepath & “.tmp”, strfilepath
Msgbox “done”
End function
Call fnModifytextfile(“c:\test.txt”,”jethva”)

Friday, July 27, 2018

Jira user story workflow

Hey folks,

In Jira, we have to work on user story for testing. Here, I try to write some basic flow about it. This can be vary as per your project needs.

When story is assigned-it will be in NEW stage.
After discussions, when story is accepted it will be inPENDING ASSIGNMENT stage.
When story is discussed among team it is ASSIGNED to development team.
When story is developing ,it is in FIX IN PROGRESS.
Once developed, it is in READY FOR QA DEPLOYMENT
Once deployed,it is in READY FOR TESTING
Once testing is in progress,it is in QA IN PROGRESS
If everything working fine on SIT, story assigned to UAT for testing and take change to PASS. If something fails, then defect needs to raise and follow defect life cycle and stage is FAILED RETEST.
Once the story is passed, stage change to CLOSE

Regards,
Trupti

Friday, May 11, 2018

Git Hub basics- Source control tool

Hey Folks,

Few updates on Source Control tool, which I recently learn, would like to share with you.

GitHub (originally known as Logical Awesome LLC)[3] is a web-based hosting service for version control using git. It is mostly used for computer code. It offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. It provides access control and several collaboration features such as bug tracking, feature requests, task management, and wikis for every project (Reference taken from Wikipedia)
Repository-A repository is usually used to organize a single project. Repositories can contain folders and files, images, videos, spreadsheets, and data sets – anything your project needs. You can create public and private repository
Branch-
Branching is the way to work on different versions of a repository at one time.
By default your repository has one branch named master which is considered to be the definitive branch. We use branches to experiment and make edits before committing them to master.
Basic Git Commands
  1. git init- create new local repository
  2. git status-List the files you've changed and those you still need to add or commit
  3. git push origin master- Send changes to the master branch of your remote repository
  4. git commit -m "Commit message"-Commit changes to head (but not yet to the remote repository):
  5. git commit -a- Commit any files you've added with git add, and also commit any files you've changed since then
Steps
1. Login through git url
2. Start Project 
3. Create project and follow link
4. Install git on local machine
5. Create folder on c:
6. Type cmd on url and write git command
7. Change environment variable to your account and path %git_home%\bin
8. Again go to c: folder and write command cmd and git
9. Clone the project to url with ‘ git clone https://githubprojectpath/hit Project.git”
10. Enter username and password
11. Copy your local code to clone folder and follow git basic commands

Regards,
Trupti