Monday, 2 November 2015

REST API Webservices Testing

Steps for testing webservices (REST API):

  • Copy below given code and paste it in your action.
  • Give path to your TestPlan.xlsx, SampleTemplate.txt and ResponseXML.xml

Set oExcel=createobject("excel.application")
Set oExcelWorkbook=oExcel.Workbooks.Open("Path for Excel File- Data Sheet - Test Plan")
Set OExcelSheet=oExcelWorkbook.Worksheets("DataSheet")
oExcelCount=OExcelSheet.usedrange.rows.count

For i=3 to oExcelCount
  FromCity= trim(OExcelSheet.cells(i,3))
  FromState= trim(OExcelSheet.cells(i,4))
  FromCountry= trim(OExcelSheet.cells(i,5))
  
  ToCity= trim(OExcelSheet.cells(i,6))
  ToState= trim(OExcelSheet.cells(i,7))
  ToCountry= trim(OExcelSheet.cells(i,8))
  
  strFileText=templateLoad()
  
  strFileText=Replace(strFileText,"citys",FromCity)
  strFileText=Replace(strFileText,"states",FromState)
  strFileText=Replace(strFileText,"countrys",FromCountry)
  
  strFileText=Replace(strFileText,"cityd",ToCity)
  strFileText=Replace(strFileText,"stated",ToState)
  strFileText=Replace(strFileText,"countryd",ToCountry)
  
  url=strFileText
  responseText=getResponse(url)
  
  writeXML(responseText)
  
  Set getresult=getvalueXML()

  OExcelSheet.cells(i,11)=getresult(0)
  OExcelSheet.cells(i,12)=getresult(1)
  
  expectedDuration=trim(OExcelSheet.cells(i,9))
  expectedDistance=trim(OExcelSheet.cells(i,10))
  
  print expectedDuration
  print expectedDistance
  print getresult(0)
  print getresult(1)
  
  If (strcomp(trim(expectedDuration),trim(getresult(0)))<>0 )  Then
   OExcelSheet.cells(i,13)="Fail"
  Else
   If (strcomp(trim(expectedDistance),trim(getresult(1)))<>0) Then
    OExcelSheet.cells(i,13)="Fail"
   Else
    OExcelSheet.cells(i,13)="Pass"
   End If
   
  End If
  
Next

oExcelWorkbook.save
oExcelWorkbook.Close
oExcel.quit

'##########################################
'#########COMMON FUNCTIONS#################
'##########################################

Function writeXML(responseText)

 Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile("Path for Response XML",2,true)
 objFileToWrite.WriteLine(responseText)
 objFileToWrite.Close
 Set objFileToWrite = Nothing

End Function

Function templateLoad()
 
 Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("Path for Sample Template-URL",1)
    strFileText = objFileToRead.ReadAll()
    objFileToRead.Close
    Set objFileToRead = Nothing
    templateLoad=strFileText
 
End Function

Function getResponse(url)
 
 Set oReq = CreateObject("Microsoft.XMLHTTP")
   oReq.open "POST", url, False
  oReq.send
   'Response
   responseText = oReq.responseText
   getResponse=responseText
 
End Function

Function getvalueXML()
 
 Set xmlDoc = CreateObject("Microsoft.XMLDOM")
   xmlDoc.Async = False
   xmlDoc.Load("Path for Response XML")
  
   Set nodes = xmlDoc.SelectNodes("/DistanceMatrixResponse/row/element")
  
   Set duration = xmlDoc.SelectNodes("/DistanceMatrixResponse/row/element/duration/text/text()")
   Set distance = xmlDoc.SelectNodes("/DistanceMatrixResponse/row/element/distance/text/text()")
 
   Set userArrayList = CreateObject( "System.Collections.ArrayList" )
   userArrayList.add duration(0).NodeValue
   userArrayList.add distance(0).NodeValue
   Set getvalueXML=userArrayList
 
End Function

exittest


Screenshot of Sample Template-URL:



Screenshot of Response XML:



Screenshot of Excel File- Data Sheet - Test Plan:


Monday, 19 October 2015

Recording in UFT

Recording:

·         Normal Context-Default Recording
·         Analog-Mouse Movements, record the tracks of mouse movements in single line(no steps)
·         Low-Level-doesnot record mouse movements- cor-ordinates
·         Insight-UFT record on appearance not on native property

Data Driven Testing using vb script UFT

Find below the code for DDT

First, we have to create object of "excel.application"
Then we have to use this object for performing various functions.



Set oExcel=createobject("excel.application")
Set oExcelWorkbook=oExcel.Workbooks.Open("D:\DataSheet\Datasheet.xls")
Set OExcelSheet=oExcelWorkbook.Worksheets("DataSheet")
oExcelCount=OExcelSheet.usedrange.rows.count

For i=2 to oExcelCount
  user= OExcelSheet.cells(i,1)
' msgbox user
 password= OExcelSheet.cells(i,2)
' msgbox password
print user
print password
Next

oExcel.Workbooks.Close

Thursday, 15 October 2015

Synchronization

Synchronization:

file-setting-run-object synchronization time for synchronization
Object synchronization-20 seconds. Page snchronization default time 60 seconds

1. sync- used for page navigation
2. wait- explicit wait
3. waitproperty- direct and condition (mostly used to check enabled disabled) millisecond
4. exist- on condition only (used with if condition)second

Used to control the execution of script according to the application. Script default time 20 second
·         Sync: browser navigation (default time 60 second)
·         Wait: (default time)-static
·         Waitproperty: (millisecond) dynamic wait. Can be defined only on object and we need to validate any property []

·         Exist: (seconds) used for condition, dynamic [icici example]

Random Number

a=now
b=replace(a,"-","")
c=replace(b," ","")
d= replace(c,":","")
msgbox d

Parameterization

Parameterization:

1. Datatable
2. Environment Variable
3. Action Parameter-right click on action-properties- action parameter
.Set parameter("user")
4. Random Variable

Object Repository

Object Repository:

1. Local-by default is local .mtr
2. Shared- performance, security and maintenance
Also called as User Defined repository.
.tsr
to merge resources-OR-tools-merge tool
associate repository

Object Repository:

Feature in QTP where objects are stored
·         Local(mtr-Mercury Test Repository)-By Default
·         Shared(tsr-Test Shared Repository)-User Defined
Covert Local to Shared:
·         Save local repository. It will be in .tsr format i.e. shared

·         Goto resources –or manager-click ->tools->OR Merge Tool->Enable Editing->Browser name should be same for all the pages in all actions