Thursday, 16 July 2015

REAL TIME QTP SCRIPTS FOR WEB APPLICATION

First you should select some text in the required webtable.
---> then open object spy and click on that hand icon
---> now select the required text in that webtable
---> here a dialog box opens. here u should carefully select the required table from

This dialog box (default selection is the text which is selected by object spy)
---> important point in this answer is u should select (required) webtable icon in

The dialog box ONLY. otherwise u won't get the required table.
----> send feedback


Browser("Google").Page("Google").WebTable("Advanced Search").GetCellData(row column)

GetCelldata retrieves the cell value of a table.

row=Browser("browser").page("page").webtable("table").getroproperty("rows")


cols=Browser("browser").page("page").webtable("table").getroproperty("cols")


for i=0 to row-1


for j=0 to col-1


val=Browser("browser").page("page").webtable 


("table").getcelldata(i j)


next


next


4 Types of Testcases should be automated:
1. Testcases which has high path frequency i.e. Testcases which are executed with high degree of frequency in production enviroment should be automated.
2. Testcases from mission critical processes are prime candidate for Automation.
3. Application with Long life span in production are enviorment are eligible for Automation.
4. Repetitive testcases should be automated


How to count number of links in a web page using QTP?

This is the script We should first create an object
set oDesc=description.create()
'prefer descriptive programming...batter
oDesec( micclass ).value= link 
'get all child objects in an variable
set oLink=browser( name:=.* ).page( title:=.* ).childobjects(oDesc)
'count all links 
intC=oLink.count

'Use print or msgbox or 'reporter.reportevent'
print intC 
'it glows links in the web page
for i=0 to intC-1
oLink(i).highlight
next
set oLink=nothing
set oDesc= nothing

'Offer me comment if it works properly


 By using Description object which contains a 'mask' for objects we would like to get we can count number of links. 

Set oDesc = Description.Create()
oDesc("micclass").Value = "Link"
Set Links = Browser("Google").Page("Google").ChildObjects(oDesc)
Msgbox "Total links present: " & Links.Count

Here 'ChildObjects' returns the collection of child objects matched the description ("micclass" is "Link") and contained within the object ' Page("Google") '


For counting the number of links in webbased

set obj=description.create()
obj( micclass ).value= Link

set Links=browser().page().childobject(obj)
NumofLinks=Links.count-1
for i=0 to Links(count)-1
Links(i).select i+1
Next

 Dim mylink linkcount
linkcount =0
Set MyObjLink = Description.Create()
MyObjLink("micclass").value = "Link"
MyObjLink("html tag").value = "A"
SystemUtil.Run "C:Program FilesInternet ExplorerIEXPLORE.EXE" "" "C:Documents and Settingsdfhdfhdfhdfh" "open"
Set myObj = Browser("Google").Page("Google").ChildObjects(MyObjLink)
For i=0 to MyObj.count-1
mylink=MyObj(i).GetROProperty("url") 
If mylink <>"" Then 
linkcount =linkcount+1
End If
Next
msgbox "Number of link on this page is " & linkcount


Retrieve Particular Cell Data

First you should select the required cell and use object spy to know rows nos. and col nos. in the selected area then use below in QTP editor
set oReqVal= browser().page().webtable().getcelldata(rows cols)
print oReqVa




How to load function library at run time without adding it in the resource tab of settings?

You can use If conditions along with executefile like
If x=y Then
Executefile "C:ATPFrameworkFunctionLibraryCommon.vbs
End If
 Dynamic button in a Web Table

Use the below code to click access webtable childobjects

Code:
Set obj = Browser("browser123").Page("page123").WebTable("table123").ChildItem(rownumber colnumber "WebButton" 0) 
obj.Click

In "ChildItem(rownumber colnumber "WebButton" 0)" 0 represents the index of the dynamic webbutton. By default its index value is 0 if the webtable cell contains more than one button you have to take care of index. 
Fisrt button in webtable cell get the index value as 0
Second button get the index value as 1 an so on....
Dynamic button in a Web Table

Hi this is Priyank 

To click a button on page dynamically use following code-

dim val
set my_button = Description.create ()
my_button("html tag").value = "A" ' check through object spy
my_button("text").value= val 'test1 is the text on button that you want to click

browser("sample").Page("sample").webbutton(my_button).click

To make this code dynamically you just need to update the value of variable "val" and respective button will be clicked.

To get the value in val use getcelldata(row col) method




GetVisibleText Vs GetRoProperty

GetVisibleText :Statically the data is retrieved by using Get Visible text propery
GetRoProperty:Dynamically(Runtime) the data is captured by using GetRoPropery







Count the number of objects in a web page



METHOD I 

Set RadBtn_Desc = Description.Create()
RadBtn_Desc("micclass") = "RadioButton"

Set RadBtn_Coll = Browser(B).Page(P).ChildObjects(RadBtn_Desc)

MsgBox RadBtn_Coll.Count

METHOD II''''''''''I am not Sure try on ur System

set RadBtn = Browser(B).Page(P).ChildObjects("class := RadioButton")

MsgBox RadBtn.Count


Executing any file in QTP


Executing any file can be achieved with the below method.

ExecuteFile Filename

Save the file that you want to execute in any folder as function sub-routines.. and provide the path in place of FileName.

ExecuteFile "C:Documents and SettingsuserDesktopgain.vbs"


Concept of Shared object repository is useful when you have multiple team members working on same module. To avoid copy of same objects in OR in all the test will unnnecessary increase the size of the test. Moreover, SOR will provide a standard way of adding your objects in the OR. You need to follow some standards while adding objects to the same OR, so that you can refrain from duplicating objects.

Merging of OR is required to make a single master SOR for the AUT by adding different ORs.

Why do we use share/Merge Object repository ?

The shared repository is stored as a file that can be accessed with multiple tests. You can say that it "fosters" a team environment by having a shared repository used by multiple testers for the same application (in read-only mode though). So multiple actions can use the objects that are stored in the shared repository. For example if you have a shared repository and you would like to test the application on another machine you can just use that shared repository (if it has all the necessary object properties) to test the application at hand without re-recording.

The second part of the question: You can also merge shared object repositories. However when you do this one of them will be the primary source and the other will be the secondary and they will both point to a third repository the target repository. The first and the second repository might have some conflicting object properties which are "handled" in the target repository with the help of some preconfigurable rules. The repositories being merged will remain unchanged.





Q: What are the prerequisites to connect QTP with QC?

A:
  1. Check Allow other Mercury products to run tests and components present under Tools > Options > Run in QTP
  2. If you are running the tests on the same computer where you have QC client installed, then you will need:
1.   QTP Connectivity Add-In
2.   QTP Add-in
  1. If you are running the tests on the different computer than where you have QC client installed, then you will need:
1.   QTP Add-in where QC client is installed.
2.   QTP Add-in and QC connectivity Add-in where QTP is installed.
  1. QC connectivity can be found at QC server URL > ‘Add-Ins Page’ link > ‘QC Connectivity’ link > ‘Download Add-in’
  2. QTP Add-in can be found at QC server URL > ‘Add-Ins Page’ link > ‘More QC Add-ins’ link > Download and install QTP Add-in according to its version.


qtqcApp.Open “C:\Temp\Project\QTPTestScript1″, True
‘ Get the Test object
Set qtqcTest = qtqcApp.Test
‘ Use the SaveAs method to upload the test to Quality Center
qtqcApp.Test.SaveAs “[QualityCenter] Subject\FolderName\QTPTScript”



: How can we automatically connect QTP with QC on start up?




‘ Create the QuickTest Professional application object.
Set qtqcApp = CreateObject(“QuickTest.Application”)
qtqcApp.Launch ‘Launch QTP
qtqcApp.Visible = True ‘Make it visible
‘Connect to Quality Center
‘qtqcApp.TDConnection.Connect <QC Server path>, <Domain name that contains QC project>,
‘<Project Name in QC you want to connect to>, <UserName>, <Password>,
‘ <Whether ‘password is entered in encrypted or normal. Value is True for encrypted and FALSE for normal>
qtqcApp.TDConnection.Connect “http://QualityCenterServer/tdbin”,
“FR”, “Flights”, “learnqtp”, “welcome”, False




Dim Test_path
Test_path = "C:\Documents and Settings\MKrisha\Desktop\Automation\Streamline_Regression_Suites"
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start QuickTest
qtApp.Visible = True ' Make the QuickTest application visible
' Set QuickTest run options
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False
qtApp.Open Test_path, True ' Open the test in read-only mode
' set run settings for the test
Set qtTest = qtApp.Test
qtTest.Run ' Run the test
qtTest.Close ' Close the test
qtApp.quit
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object

No comments:

Post a Comment