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

Object Identification Mechanism

Object Identification Mechanism

1. Mandatory Property
 -Description Property in QTP- combination of Mandatory and Assistive Property
2. Assistive Property
3. Ordinal dentifier- if qtp not able to identify object using mandatory and assistive property then it goes for ordinal property
1.Location
2.Index- when properties of two objects are same then it goes for index(starts with zero)
3.Creation Time- used for brwoser- if 3 browsers are opened, it will perform action on 1st
browser("CreationTime:=1").Close
4. Smart Identification- It is technique to identify object with combination of two filter properties:
base filter property
optional filter property

local setting-individual-
tools-object identification-web-select button-Global Setting
file -setting-run-disable smart identification during run session

Object Identification Mechanism:
·         Mandatory property:
·                     Frame
·                     Name
·                     Browser, page
·                     None
·                     Web Table
·                     HTML Tag
·                     WebList, WebRadioGroup
·                     HTML tag ,Name
·                     WebButton WebFile WebEdit WebCheckbox
·                     HTML tag ,Name,Type
·                     ViewLInk WebElement
·                     HTML tag ,Inner Text
·                     Web Area
·                     HTML tag ,Alt(tool tip)
·                     Image
·                     HTML tag ,Alt, Image Type

·         Assistive: e.g Name in WebEdit
·         Ordinary identifier:
Location X,Y
 Creation time: used for browser
Indexing- t overcome Location drawbacks

·         Smart Identification: inbuilt feature to recognize object
Base filter properties(Mandatory & Assistive)
Optional Filter properties(Ordinary identifier)

File Handling

Set fso=createobject("scripting.filesystemobject")

Error Handling

2 types of error handling:

1. Expected Error
2. Unexpected Error

on error resume next


if you want to receive error then write following line:
On error goto 0
to resume error handling again write below mentioned line:
on error resume next

RECOVERY SCENARIO
resource-> recovery scenario manager
new scenario-> welcome(next)->
1. define trigger events-popup window-object state change(proprty change),application crash, text run error
2. specify recovery operation
3. ch
4. enter descriptive information about events

Environment Variable

Environment Variable is like global variable

1. Built in or system defined
2. User Defined
2.1 internal-we can change its value at runtime
2.2 external-we cannot change its value at runtime

file-setting-env

Environment: 
File >Setting->Environment
·         Builtin- systemDefined- (By Default) e.g  test directory, OS,OS version,Product (msgbox Environment.Value (“OS”))
·         User Defined
->Internal->we can change value at runtime
->External->cannot change value at runtime
msgbox Environment.Value ("int")
Environment.Value("int")="zellax"

msgbox Environment.Value ("int")

Descriptive Programming

Descriptive Programming

1.Static
Object repository will work before descriptive only
descriptive will not work before object repository
browser("name:=")

2.Dynamic: when object is dynamic
systemutil.Run "iexplore","http://localhost:81"
Set oDesc= description.Create
oDesc("type").value="text"
oDesc("html tag").value="input"
'oDesc("micclass").value="Link"
Set oCollection=browser("name:=vtiger.*").Page("title:=vtiger.*").ChildObjects(oDesc)
'msgbox oCollection.count
oCollection(0).set "admin"

Date Function

date only date
now date and time
dateadd add date
datediff delete date

Data Table

Data Table:

1. Global .Set datatable.Value("Lname",dtlocalsheet)
2. Local  .Set datatable.Value("Lname",dtglobalsheet)


global setting-file-setting-run-run on all rows


Runtime:
datable.Import(path,source,destination)
datable.ImportSheet()

Manually:
Right Click-Import Excel File

Checkpoints

Checkpoints: Start Recording - got Insert-checkpoints

1. Standard Checkpoint:
1. Page Checkpoint
2. Image Checkpoint
3. Table Checkpoint

2. Text Checkpoint
3. TextArea chexkpoint - window based application
4. Bitmap Checkpoint
5. Database Checkpoint
6. Accessability Checkpoint options-web-advance-accesability check- w3c standards
7. XML Checkpoint from resources
8. XML Checkpoint from application

Wednesday, 19 August 2015

Actions:

Actions:

Actions helps testers to divide scripts into groups of QTP statements called actions. Actions are similar to functions in VBScript, however there are few differences. By Default QTP creates a test with 1 action.