Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Wednesday, 10 June 2015

Descriptive Programming Examples

1. Script for Gmail sign in using  "Dynamic descriptive Programing":

'Username="Coming into Uftworld"
'Password="World of UFT" 

'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com"

'Descriptive object to identify  Browser  with a particular title
Set  Dbrowser=description.Create
Dbrowser("micclass").value="Browser"
Dbrowser("title").value="Gmail: Email from Google"

'Descriptive object to identify  Web page with a particular title
Set  Dpage=description.Create
Dpage("micclass").value="Page"
Dpage("title").value="Gmail: Email from Google"

'Descriptive object to identify a particular Web Button
Set  Dbutton=description.Create
Dbutton("micclass").value="WebButton"
Dbutton("name").value="Sign in"

‘Descriptive object to identify  Web Text Box
Set Dedit=description.Create
Dedit("micclass").value="WebEdit"
Dedit("name").value="Email"

'wait till browser loads
Browser(Dbrowser).Page(Dpage).Sync

'Enter  Email id in Username Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set  " Coming into Uftworld"" 
Dedit("name").value="Passwd"

'Enter password in Passowrd Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set  " World of UFT "

'Cick on the Sign In Button

Browser(Dbrowser).Page(Dpage).WebButton(Dbutton).Click 

2. Script to click on Web Buttons Using "ChildItem":

'To click on the first button
Set objButton1 = Browser("Dbrowser").Page("Dpage").WebTable("Sample Buttons"). ChildItem(2,1,"WebButton",0)

objButton1.highlight
objButton1.click

' To click on the second button
Set objButton2 = Browser("Dbrowser").Page("Dpage").WebTable("Sample Buttons"). ChildItem(2,1,"WebButton",1)

objButton2.highlight
objButton2.click

Alternatively we can use the below code


'To click on the first button
Browser
("Dbrowser").Page("Dpage").WebTable("Sample Buttons"). ChildItem(2,1,"WebButton",0).Click

'To click on the second button

Browser
("Dbrowser").Page("Dpage").WebTable("Sample Buttons").ChildItem(2,1,"WebButton",1).Click

NOTE: The same concept will apply for WebLink or Images etc but the Micclass will change in the ChildItem method, 


If you are looking to handle WebLinks then:

'To click on the first link
Browser
("Dbrowser").Page("Dpage").WebTable("Sample Buttons"). ChildItem(2,1,"Link",0).click

'To click on the second link
Browser
("Dbrowser").Page("Dpage").WebTable("Sample Buttons").ChildItem(2,1,"Link",1).click

If you are looking to handle Images then:


'To click on the first image
Browser("Dbrowser").Page("Dpage").WebTable("Sample Buttons"). ChildItem(2,1,"Image",0).click


'To click on the second image
Browser
("Dbrowser").Page("Dpage").WebTable("Sample Buttons"). ChildItem(2,1,"Image",1).click

3. Login into gmail account  using  "Child Objects" :

'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com"
'Descriptive object to identify  Browser  with a particular title
Set  Dbrowser=description.Create
Dbrowser("micclass").value="Browser"
Dbrowser("title").value="Gmail: Email from Google"

'Descriptive object to identify  Web page with a particular title
Set  Dpage=description.Create
Dpage("micclass").value="Page"
Dpage("title").value="Gmail: Email from Google"

'Descriptive object to identify a  particular Web Button
Set  Dbutton=description.Create
Dbutton("micclass").value="WebButton"
Dbutton("name").value="Sign in"
 'Descriptive object to identify  Web Text Box
Set Dedit=description.Create
Dedit("micclass").value="WebEdit"

'wait till browser loads
 Browser(Dbrowser).Page(Dpage).Sync

'to find number of  webedit in gmail page
Set  Wtextbox = Browser(Dbrowser).Page(Dpage).ChildObjects(Dedit)

NoOfTextbox = Wtextbox.Count

   For Counter=0 to NoOfTextbox-1
      If Wtextbox(Counter).getroproperty("name")="Email" then
       ' Enter  Email id in Username Field
      Wtextbox(Counter).set   "Coming into UFTworld"
     Elseif  Wtextbox(Counter).getroproperty("name")="Passwd" then
       'Enter password in Passowrd Field
      Wtextbox(Counter).set  "world of UFT"
       End If
   Next

'Cick on the Sign In Button

Browser(Dbrowser).Page(Dpage).WebButton(Dbutton).Click

4.Using "Regular Expression" in DP...:

‘Declare an Object Variable
Dim oDesc

‘Create an Empty Description
Set oDesc=Description.Create
oDesc(“text”).value=”Go To Next Page\d\d\d
oDesc(“Html tag”).Value=” Gmail: Email from Google

‘Link Selection
Browser(Dbrowser).Page(Dpage).Link(oDesc).Click

5. Using "Variables" in DP...:

‘Variable Declaration
Dim Uname

‘Assiging Name to Variable
Uname=user456

‘Link click
Browser(Dbrowser).Page(Dpage).Link(“text:=Go To Next Page”&Uname, “html tag:= Gmail: Email from Google”).Click

6. Using "Ordinal Identifiers" in DP..:

We can also use any of the three ordinal identifiers like index, location, Creation time  in descriptive programming.
Forexample:

‘Using Location
Browser("title:=.*gmail.*").Page("micclass:=Page").WebEdit("name:=dpTest","location:=0").Set "1"

‘Using Index
Browser("title:=.*gmail*").Page("micclass:=Page").WebEdit("name:=dpTest", "index:=0").Set "1"

‘Using Creation Time
‘Creation time 0
SystemUtil.Run "iexplore.exe", "http://www.QC.com"
‘Creation Time 1
SystemUtil.Run "iexplore.exe", "http://www.UFT.com"  
'CreationTime 2         
SystemUtil.Run "iexplore.exe", "http://www.ALM.com"           

Browser( "creationtime:=" ).Highlight 
Browser( "creationtime:=1" ).Highlight
Browser( "creationtime:=2" ).Highlight