Friday, 26 February 2016

QTP - Crypt Object

QTP - Crypt Object Examples
================================================


Dim pwd
pwd=sumit
epwd=crypt.Encrypt("pwd")
print epwd

Output:
51eeb9d7dc0bee3d2b1ec7ba
'

Excel:Storing Image to Excel file using Vbscript

Dim oExcel, oWB, oSheet,
Set oExcel=CreateObject("Excel.Application")

Set oWB=oExcel.Workbooks.Open("C:\Users\Sunshine\Desktop\myframework.xlsx")
Set oSheet=oWB.WorkSheets("data") 'Above Workbook has sheet named "data"

oExcel.Visible=TRUE

oSheet.Shapes.AddPicture "C:\Users\Sunshine\Desktop\ritu.jpg", True, True, 100, 100, 70, 70
   
   
oWB.Save
oWB.Close
Set oExcel=Nothing
 Set oExcel=Nothing

Saturday, 13 February 2016

QTP/UFT Image Capture :Capturing Full Webpage screenshot using Dot Net Factory and Snag it tool

QTP Image Capture :Capturing Full Webpage screenshot using Dot Net Factory and Snagit:

QTP/UFT by dafault has CaptureBitmap method to Capture the screenshot.
One limitation of this method is it always captures visible part of the webpage.

But imagine if you have to capture full webpage:
Below code can be used to capture full webpage image.


Lets go step by step to the solution,
As part of implementing the solution, we need to get the height and weight of the entire page. Inorder to get that we using DOM of a page using .object method.

''#Get the Full Height of Page
FullHeight = Browser("Wikipedia, the free encycloped").Object.document.body.scrollheight
''#Get the Full width of Page
Fullwidth = Browser("Wikipedia, the free encycloped").Object.document.body.scrollwidth

Once we  found the complete page size, we need to find the client size (how much browser can show)

''#Get the visible height - Viewable part of the page
BrowserHeight = Browser("Wikipedia, the free encycloped").Object.document.body.clientHeight
''#Get the visible width - Viewable part of the page
Browserwidth = Browser("Wikipedia, the free encycloped").Object.document.body.clientwidth

Next we need to implement required dot net libraries using Dot Net Factory

Set oGraphics=DotNetFactory.CreateInstance("System.Drawing.Graphics")
Set oPoint=DotNetFactory.CreateInstance("System.Drawing.Point")
Set oImgFormat=DotNetFactory.CreateInstance("System.Drawing.Imaging.ImageFormat","System.Drawing", Nothing)
Set oImageLib = DotNetFactory.CreateInstance("System.Drawing.Image")
Set oPens=DotNetFactory.CreateInstance("System.Drawing.Pens","System.Drawing")
We will loop through the page and take screenprints separately. finally using Dotnet library we will merge the images.
''#Dot Net Factory - Importing required Dot net classes
Set oGraphics=DotNetFactory.CreateInstance("System.Drawing.Graphics")
Set oPoint=DotNetFactory.CreateInstance("System.Drawing.Point")
Set oImgFormat=DotNetFactory.CreateInstance("System.Drawing.Imaging.ImageFormat","System.Drawing", Nothing)
Set oImageLib = DotNetFactory.CreateInstance("System.Drawing.Image")
Set oPens=DotNetFactory.CreateInstance("System.Drawing.Pens","System.Drawing")

''#Launch IE and Maximize the Browser
systemutil.Run "iExplore","https://en.wikipedia.org/wiki/Main_Page",,,3
''#Get the Full Height of Page @@ hightlight id_;_Browser("Wikipedia, the free encycloped").Page("Wikipedia, the free encycloped").Link("Link")_;_script infofile_;_ZIP::ssf3.xml_;_
FullHeight = Browser("Wikipedia, the free encycloped").Object.document.body.scrollheight
''#Get the visible height - Viewable part of the page
BrowserHeight = Browser("Wikipedia, the free encycloped").Object.document.body.clientHeight
''#Get the Full width of Page
Fullwidth = Browser("Wikipedia, the free encycloped").Object.document.body.scrollwidth
''#Get the visible width - Viewable part of the page
Browserwidth = Browser("Wikipedia, the free encycloped").Object.document.body.clientwidth

''#Calculate how many times page needs to be scroll down
 If round(FullHeight/BrowserHeight) < (FullHeight/BrowserHeight) Then
  Heightscrollcount = round(FullHeight/BrowserHeight) + 1
 else
  Heightscrollcount = round(FullHeight/BrowserHeight) 
 End If
 
''#Calculate how many times page needs to be scroll right
 If round(Fullwidth/Browserwidth) < (Fullwidth/Browserwidth) Then
  widthscrollcount = round(Fullwidth/Browserwidth) + 1
 else
  widthscrollcount = round(Fullwidth/Browserwidth) 
 End If
 
''#Scroll down through the page and take screen prints
For HeightIterator = 1 To Heightscrollcount
 ''#Scroll right through the page and take screenprints 
 For WidthIterator = 1 To widthscrollcount
  Browser("Wikipedia, the free encycloped").Page("Wikipedia, the free encycloped").CaptureBitmap "C:\temp1\Image_" & HeightIterator & "_" & WidthIterator & ".png"
  Browser("Wikipedia, the free encycloped").object.document.parentwindow.scrollBy Browserwidth, 0  
 Next
 
 ''#Scroll left back to normal
 For WidthIterator = 1 To widthscrollcount
                ''# Giving scrollby in negative to scroll left
  Browser("Wikipedia, the free encycloped").object.document.parentwindow.scrollBy (0-Browserwidth), 0                 
 Next
 
 Browser("Wikipedia, the free encycloped").object.document.parentwindow.scrollBy 0, BrowserHeight
Next

''#Merging Images
finalImage = "C:\temp1\Image_Final.png"

''#Final Image height and Width should match with Scrollheight and Width. so lets create final image with scroll height and width

''#set img3 = oBmp.Bitmap(Fullwidth, FullHeight)
Set img3=DotNetFactory.CreateInstance("System.Drawing.Bitmap","System.Drawing",Fullwidth, FullHeight)
set g = oGraphics.FromImage(img3)

HeightCount = 0
WidthCount = 0
For HeightIterator = 1 To Heightscrollcount 
 For WidthIterator = 1 To widthscrollcount
  set img = oImageLib.FromFile("C:\temp1\Image_" & HeightIterator & "_" & WidthIterator & ".png")
  
  ''# For the last peace of image
  If WidthIterator > 1 Then
   If WidthCount + Cint(img.Width) > Fullwidth  Then 
    WidthCount = WidthCount - (WidthCount + Cint(img.Width) - Fullwidth)
   End if
  End if
  
  If HeightCount + Cint(img.Height) > FullHeight  Then   
   HeightCount = HeightCount - (HeightCount + Cint(img.Height) - FullHeight)
  End if
  
  ''#Drawing the image
  
  g.DrawRectangle oPens.Black,WidthCount,HeightCount,WidthCount+Cint(img.Width),HeightCount+Cint(img.Height)
  
  g.DrawImage img, WidthCount, HeightCount
  
  If WidthIterator > 1 Then
   ''#Add Right   
   WidthCount = WidthCount + Cint(img.Width)
  else
   ''#AddBottom    
   HeightCount = HeightCount + Cint(img.Height)  
  End if  
  img.Dispose
 Next
Next
g.Dispose
img3.Save finalImage, oImgFormat.Png
img3.Dispose
 
 
 

Thursday, 12 November 2015

QTP KeyWord Frame work driver script



'===============================================================
' QTP KeyWord Frame work driver script
'===============================================================
'Project Name :-Esources
'Script Name  :-Key Word Frame Work Driver Script
'Author       :-Sumit Raut
'Created Date :-12 Nov 2015
'--------------------------------------------------------------
'Declearing the variables
Option explicit
Dim fname,intmrc,i,mexe,mmid,inttcrc,j,tcmid,tcexe,tctcid,k,inttsrc,tstcid,kwd,strres,resfilnam
'intmrc=rowcount of modules sheet
'mexe=refers to execution flag of modules sheet
'mmid=module id


'Association of environment file,repository and function library
'Environment.LoadFromFile "E:\nareshuft63\automation\environmnet\pbank.xml"
'RepositoriesCollection.Add Environment.Value("rep")&"pbank.tsr"

RepositoriesCollection.Add "C:\Users\Sunshine\Desktop\UFT Again\OR\estotoal.tsr"
'ExecuteFile Environment.Value "C:\Users\Sunshine\Desktop\UFT Again"

ExecuteFile "C:\Users\Sunshine\Desktop\UFT Again\esources.qfl"

'Adding the new sheets to datatable
DataTable.AddSheet("dtmodules")
DataTable.AddSheet ("dttestcases")
DataTable.AddSheet ("dtteststeps")

'Deleting the default sheets of datatable
DataTable.DeleteSheet ("Global")
DataTable.DeleteSheet("Action1")

'Importing the excel sheets data into datatable sheets
fname="C:\Users\Sunshine\Desktop\UFT Again\keyword.xls"
'C:\Users\Sunshine\Desktop\UFT Again\keyword.xls
DataTable.ImportSheet fname,"modules","dtmodules"
DataTable.ImportSheet fname,"testcases","dttestcases"
DataTable.ImportSheet fname,"teststeps","dtteststeps"

'Working with dtmodules sheet of datatable
intmrc=DataTable.GetSheet("dtmodules").GetRowCount
MsgBox "m rowcount="&intmrc
For i = 1 To intmrc Step 1
DataTable.GetSheet("dtmodules").SetCurrentRow (i)
    mexe=DataTable.Value("execution","dtmodules")
    If ucase(trim(cstr(mexe)))="Y" Then
    mmid=DataTable.Value("moduleid","dtmodules")
    MsgBox "module id="&mmid
  
'Working with dttestcases sheet of datatable
    inttcrc=DataTable.GetSheet("dttestcases").GetRowCount
    MsgBox "tc rowcount="&inttcrc
    For j = 1 To inttcrc Step 1
        DataTable.GetSheet("dttestcases").SetCurrentRow (j)
        tcmid=DataTable.Value("moduleid","dttestcases")
        tcexe=DataTable.Value("execution","dttestcases")
        If (trim(cstr(tcmid)))=(trim(cstr(mmid))) and (ucase(trim(cstr(tcexe))))="Y" Then
        tctcid=DataTable.Value("testcaseid","dttestcases")
        MsgBox "tc tcid="&tctcid
          
'Working with dtteststeps sheet of datatable
inttsrc=DataTable.GetSheet("dtteststeps").GetRowCount
MsgBox "ts rowcount="&inttsrc
For k = 1 To inttsrc Step 1
    DataTable.GetSheet("dtteststeps").SetCurrentRow(k)
    tstcid=DataTable.Value("testcaseid","dtteststeps")
    If trim(cstr(tstcid))=trim(cstr(tctcid)) Then
        kwd=DataTable.Value("keyword","dtteststeps")
        MsgBox "Keyword="&kwd
      
'Introducing the select case conditional statement
Select Case kwd
    Case "apl"
    'strres=fnAppLaunch(strurl)
    strres=fnAppLaunch("http://www.esources.co.uk/")
  
    Case "algn"
    'strres=fnAppLogin(strun,strpwd)
    strres=fnAppLogin("estesting2015","testing")  
  
  
    Case "algt"
    strres=fnAppLogout()
  
    Case "apc"
    strres=fnAppClose()
End Select

'Updating the results into the teststeps and testcase sheets of datatable
DataTable.Value("status","dtteststeps")=strres
If DataTable.Value("status","dttestcases")<>"fail" Then
   DataTable.Value("status","dttestcases")=strres
   else
   DataTable.Value("status","dttestcases")="fail"
End If
    End If
Next
else
DataTable.Value("status","dttestcases")="blocked"
        End If
    Next
      
    End If
Next

'Exporting the results of datatable into excel file 
resfilnam=replace(replace(replace(now,"/",""),":","")," ","")
'DataTable.Export Environment.Value("res"filnam&")&reskwdfw.xls"
DataTable.Export "C:\Users\Sunshine\Desktop\UFT Again\keywordresult.xls"




Wednesday, 24 July 2013

QTP- When to associate a library file with a test and when to use execute file?

When to associate a library file with a test and when to use execute file? 

 

  • When we associate a library file with the test, then all the functions within that library are available to all the actions present in the test.
  • When we use Executefile function to load a library file, then the function are available in the action that called executefile. 
  • By associated a library to a test we share variables across action (global variables basically), using association also makes it possible to execute code as soon as the script runs because while loading the script on startup QTP executes all the code on the global scope.
  • We can use executefile in a library file associated with the test to load dynamic files and they will be available to all the actions in the test.

QTP AOM Script : Launch QTP, Create new test and Save it


QTP AOM Script : Launch QTP,  Create new test and Save it
===============================================
dim qtpapp

set qtpapp=createobject("quicktest.application")

qtpapp.launch

qtpapp.visible=true

qtpapp.new

qtpapp.test.saveas "C:\qtpapp"

qtpapp.visible=true

qtppapp.quit

set qtpapp=nothing


Saturday, 22 June 2013

QTP :-Useful Datatable Methods

Data table methods are used for performing the operations on the runtime data table

1. Add- sheet: It is used for adding the new sheet for the runtime data table

Syntax: Datatable.Addsheet("SheetName")

Ex. Datatable.Addsheet("Sumit")




2. Delete- sheet: It is used for deleting a specified sheet from the run time data table

Syntax:
Datatable.Deletesheet("SheetName")
Datatable.Deletesheet(SheetID)


Ex. Datatable.DeleteSheet("Sumit")
Ex. Datatable.DeleteSheet(3)


3. Import: It is used for importing the data present in all the sheets in an excel file to the runtime data table
Syntax:
DataTable.Import("pathoffile")


ex datatable.Import("c:\esbbxl.xls") 



'4. Import Sheet: It is used for importing specified sheet of data from the excel file to the specified sheet in the runtime data table
'Syntax:
'Datatable.Importsheet “path of the excel file, source sheet id, destination sheet id”


datatable.ImportSheet "c:\esbbxl.xls",2,3 


//Imports 2nd sheet from esbbxl file  into 3rd sheet of datatable, i.e action 2 in our case.
1. Global
2.Action 1
3. Action 2 







 



 




Rest Assured Chectsheet

REST Assured Cheat Sheet 🚀 REST Assured Cheat Sheet Complete Reference for ...