Working with QTP

TestEveryThing

Get File count and found matching file name VB script

Posted by rajivkumarnandvani on January 7, 2010

Dim fs ‘ variable declared outside a procedure (this is a global variable)
‘ this is hold a reference to the file system object
”create an instance
On Error Resume Next
Set fs = CreateObject(“scripting.filesystemobject”)
Set MyFile = fs.CreateTextFile(“c:\Filepath.txt”,True,True)

‘ count files in windows directory
folderpathvalue = inputbox (“Plese Enter Folder path” ,”Folder”,”C:\WINDOWS\”)
FileNamevalue = inputbox (“Plese Enter File name/extension of file” ,”FileName”,”.txt”)
Filecountvalue = CountFiles (folderpathvalue , FileNamevalue )
Set WshShell = CreateObject(“WScript.Shell”)
Set MyFile = nothing
Set fs = nothing
rem it will return the total file count value not the matching file count value
msgbox “Total File count is ” & Filecountvalue
rem it will show the how many file found with matching criteria
WshShell.run(“c:\Filepath.txt”)
Set WshShell =nothing

‘ takes a string argument containing the name of the directory

‘ returns an integer contiang the nubmer of files in that direcrectory

‘ and all sub directories

Function CountFiles (ByVal StrFolder ,byval FileNamevalue)
Dim ParentFld
Dim SubFld
Dim IntCount
‘ note the use of the fs global variable
Set ParentFld = fs.GetFolder (StrFolder)
‘ count the number of files in the current directory
IntCount = ParentFld.Files.Count
For Each oFile In ParentFld.files
On Error Resume Next
If InStr(1, lcase(oFile.path),FileNamevalue) > 0 then
MyFile.writeline oFile.path
end If
Err.clear
Next
For Each SubFld In ParentFld.SubFolders
‘ count all files in each subfolder – recursion point
IntCount = IntCount + CountFiles(SubFld.Path ,FileNamevalue)
Next
‘ return counted files
CountFiles = IntCount
End Function
Err.clear

Posted in QTP | Tagged: , , , | Leave a Comment »

Check page broken link using VB script

Posted by rajivkumarnandvani on January 5, 2010

Hi,
I created a script that will check broken link in a page means valid url is that or not by using Microsoft.XMLHTTP object

rem create link object description
Set alllinkob = Description.Create()
alllinkob(“micclass”).value =”Link”
alllinkob(“html tag”).value =”A”

rem get alllink objects
set objAlllinkObj = Browser(“Google”).Page(“Google”).ChildObjects(alllinkob)
rem run a loop as per link on the page
For a =0 to objAlllinkObj.count-1
rem get link url
url = objAlllinkObj(a).getroproperty(“url”)
rem call function
call geturlstatus(url )

Next

Set objAlllinkObj = nothing
rem Clear browser cache
Public Function ClearBrowserCache()
On Error Resume Next

rem TEMPORARY_INTERNET_FILES file path in system
Const TEMPORARY_INTERNET_FILES = 32′&H20& ‘Decimal 32 is equivalent to hex value &H20&

rem create file system object
Set objCacheFSO = CreateObject(“Scripting.FileSystemObject”)

rem create shell application  object
Set objShell = CreateObject(“Shell.Application”)

rem create temporary folder path object
Set objFolder = objShell.Namespace(TEMPORARY_INTERNET_FILES)

Rem delete all file under temporary folder
objCacheFSO.DeleteFile(objFolder.Self.Path & “\*.*”)

Rem get cache folder path..

sPath = objCacheFSO.GetFolder(objFolder.Self.path) & “\Content.IE5\”

Rem create cache folder object..
Set objFolders = objCacheFSO.GetFolder(sPath)
For Each objFName In objFolders.SubFolders
‘WScript.Echo sPath & objFName.Name
objCacheFSO.DeleteFolder sPath & objFName.Name, True
Next
ClearBrowserCache= True
Set objFolder=Nothing
Set objShell=Nothing
Set objCacheFSO=Nothing
err.clear
End Function

Public Function geturlstatus(url )
On Error Resume Next
Call ClearBrowserCache()
Set webService = nothing
Set webService= CreateObject(“Microsoft.XMLHTTP”)
webService.open “GET”, url, False
webService.Send
pagestatus = webService.status
If pagestatus < 200 or pagestatus >399 Then
print “In valid request “& pagestatus &” ” & url
geturlstatus = 0
else
geturlstatus = 1
print “valid request “& pagestatus &” ” & url
End If
Set webService = nothing
err.clear
End Function

rem __________________________________________

url = “http://en.wikipedia.org/wiki/List_of_HTTP_status_codes”

call geturlstatus(url )

Posted in QTP | Tagged: , | 2 Comments »

Using Date in VB script

Posted by rajivkumarnandvani on January 1, 2010

Hi All,
Some time we required date in different format like DD/MM/YY but when we use now or date function it will written the value as per ur system configuration date format like if today is 1st jan 2010 and we need the date in DD/MM/YY format means 01/01/2010 but it will written 1/1/2010 if date 31 jan 2010 then it will written 31/1/2010 while we need 31/01/10
so for this we can use in this way

dim dayvalue, monthvalue , yearvalue
dayvalue =right(“0″&day(now),2)
msgbox “dayvalue =” &dayvalue

monthvalue =right(“0″&month(now),2)
msgbox “monthvalue =” & monthvalue
yearvalue=right(year(now),2)
msgbox “yearvalue =” & yearvalue

Posted in QTP | Tagged: | Leave a Comment »

Check object is Visible OR Not on Web Page QTP

Posted by rajivkumarnandvani on December 21, 2009

Hi All,

Some time we have to  check that a object(WebElement) should not be exist on page. For this we use obect exist = False  property but when we run the script it get failed While object is not showing in the Page. We think that there is a something  wrong.

The reason behind why QTP giving this because object is present in the page but not visible means it not displaying while it exist in HTML code.

So for this we have to be understand the object property( object.currentstyle.display) there will be case some time object inherit the property from its parent or another parent element property to display in page. First we have to identify that object when it not showing/displaying in page.We have to check its display property

Display property value we can get through like this

rem disvalue

disvalue =Browser(“Google”).Page(“Google”).Image(“Happy Holidays from Google!”).Object.currentStyle.display

if disvalue =”block” then

print ” object not displaying”

else

print ” object displaying”

end if

like this(incase if object using display property from its  parent object )  we have to check by which element my object showing on page

Posted in QTP | 4 Comments »

Use of index property in QTP

Posted by rajivkumarnandvani on November 28, 2009

Hi ALL,

Some time we use index proerty to idendify the object incase object found more than one with same property.
So before adding index property we have to understand that is this property realy required or not becos incase if an object one(unique in application). in case object unique in application and you add index property for that it increase the time to identified the object. In QTP 9.2 it taking more time with respect to QTP 9.5

Here i am showing an example that will show the time calculate withuse of index/creationtime property and without use of this and shows the time difference to execute the steps
First open the QTP application with WEB adding and copy the script in QTP
now open the browser(IE) after open the browser run the script

rem with creationtime

set objBrowser = Description.Create()
objBrowser(“micclass”).value =”Browser”
objBrowser(“CreationTime”).value=0
a= timer
print “with creation time” & Browser(objBrowser).GetROProperty(“title”)
print timer-a

Set objBrowser = nothing

rem without creationtime

set objBrowser = Description.Create()
objBrowser(“micclass”).value =”Browser”

b= timer

print “without creation time” & Browser(objBrowser).GetROProperty(“title”)
print timer-b

Set objBrowser = nothing

Posted in QTP | 2 Comments »

COMPLETE QTP 9.5 30 hours course

Posted by rajivkumarnandvani on November 19, 2009

COMPLETE QTP  9.5          30 hours course

This comprehensive course covers all the essential principles of using Quick Test Professional 9.5 Designed for beginners as well as testers with previous automation experience, it takes the newcomer to QTP from the basic techniques of record & replay in the keyword view, right through to advanced programming skills in the expert view. Throughout the course practical examples are demonstrated, and the delegates get to practice what they have learned in each chapter against windows and web applications.

Course Objectives

  • Understand the key principles of test automation; record & replay, synchronization, checkpoints, data-driven Testing
  • Understand how to structure your automated testing
  • Gain a full understanding of how QTP integrates with the system under test
  • Understand how you can design robust tests against dynamic applications
  • By the end of the course you should have a complete understanding of how to develop reliable, robust QTP test scripts

Key Points in Training Sessions

Record & Playback

How to create a basic script using record & replay in the keyword view

Object Recognition

Explains how QTP recognizes objects in the system under test. Describe Object Repository and different Repositories types.

Synchronization & Checkpoints

How to use synchronization to ensure that QTP waits for your application to complete processes? And how insert checkpoints in your script to test your application?

Multiple Actions

How to break your script down into smaller components called Actions, covers all types of Actions, and how to re-use Actions in other scripts.

Data-driven testing

How to use the built-in Data Table to data driven tests with multiple test cases?

The Expert View

Explain the differences between the Keyword and Expert view and also covers all the debugging features of the QTP Development environment.

Capturing Application Data

Cover the various methods for capturing data from your system under test for checking, or outputting to the Data Table and Results.

Passing Data between Actions

Look at the various techniques for passing data between Actions like tests such as Action Parameters, Global and

Variables, Environment Variables, Data Table.

Custom Checkpoints

How to create your own checkpoints using the Expert view? Demonstrate how to check dynamic data.

Dynamic Objects

How to test dynamic applications whose interfaces change at run-time in QTP? Look at making the Object Repository more flexible, descriptive programming and capturing object collections from your system under test.

Functions

Covers creating procedures in QTP, storing them in function libraries, calling them from scripts, how to override or create new methods for Test Objects.

Object Recognition Problems

Key points for overcoming object recognition problems. Cover the 3 recording modes, Virtual Objects, and mapping custom classes.

For Contact details mail to teachmeqtp@gmail.com OR write in Comment

Posted in QTP | Tagged: | 5 Comments »

Convert HTML text to Simple text VB Script

Posted by rajivkumarnandvani on November 6, 2009

Hi All,

Some time we required HTML text change to simple text here i created a function which will convert your HTML text to simple readable text.

‘ *************************************************************************************
‘ Function Name:    ConvertHTMLtoText
‘ Description:        This function is used to convert HTML string to Simple Text
‘ Arguments:        HTML string

‘ Return Value:        SimpleText
‘‘Syntax of calling the defined function:    Call  ConvertHTMLtoText(strHTML)
‘ *************************************************************************************

Public Function ConvertHTMLtoText(byVal strHTML)
If InStr(1,strHTML,”<”) > 0 Then
Do
startVariable = InStr(1,strHTML,”<”)

endVariable = InStr(startVariable,strHTML,”>”)
varName = Mid(strHTML,startVariable, endVariable-startVariable+1)
strHTML = replace(strHTML,varName,”")
Loop While InStr(1,strHTML,”<”) > 0
End If
strHTML = replace(strHTML,”&gt;”,”")
strHTML = replace(strHTML,”&lt;”,”")
ConvertHTMLtoText = strHTML
End Function

msgbox ConvertHTMLtoText(“<br><br><font color=”"”"#008000″”"”>TestingGUID position 26 with dashes must be one of the following: AB234567</font></body></html>”)

Posted in Miscellaneous | Leave a Comment »

Get Browser(iexplore) Count using VB script

Posted by rajivkumarnandvani on November 1, 2009

bcount = Get_ApplicationCount(“iexplore.exe”)

msgbox bcount

Public Function Get_ApplicationCount( byval sApplicationExe)

Dim strComputer

Dim objWMIService

Dim colProcesses

Dim objProcess

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2″)

Set colProcesses = objWMIService.ExecQuery (“Select * from Win32_Process Where Name = ‘”&sApplicationExe&”‘”) Get_ApplicationCount = colProcesses.count

Set objWMIService = Nothing

Set colProcesses=Nothing

End Function

If  bcount >0  Then

set objBrowser = Description.Create()

objBrowser(“micclass”).value =”Browser”

objBrowser(“CreationTime”).value=bcount-1

msgbox Browser(objBrowser).GetROProperty(“title”)

else

msgbox “No internet explorer open”

End If

Posted in QTP, WEB | Tagged: , , , , | Leave a Comment »

VB Get All Web page text ( Including All Webelement )

Posted by rajivkumarnandvani on October 1, 2009

Hi All,

Some Time we have to check that particular text is present on page or not during automation. If we get the page outer HTML in QTP we can not  get the whole text of all element like frame , webtable . div.etc…

So i created a function which will  check that the given text is present on page or not If Text present on page it will return True else False

REM  ——-   Set page object     ———-
set objpage = Browser(“BrowserName”).Page(“Pagename”)

msgbox   VerifyTextPresentOnPage(objpage ,”rajiv” )

Function VerifyTextPresentOnPage(byval objpage , byval Textvalue )
On error resume next

REM ——- Create child object description
Set childobjdes = Description.Create()
childobjdes(“micclass”).value=”WebElement”
childobjdes(“html tag”).value=”.*[A-Za-z0-9].*”
childobjdes(“outertext”).value =”.*[A-Za-z0-9].*”

REM  ———-Create ALL child object
set allobj = objpage.ChildObjects(childobjdes)
REM  get all  web element  outer text from web page and store in output variable
For i=1 to allobj.count-1
output=  output   & allobj.Item(i).GetROProperty(“outertext”)
Next
REM  now compare the value if the given value find or not
If instr(1,lcase(output),lcase(Textvalue)) > 0  Then

rem return true if found
VerifyTextPresentOnPage= True
Else

rem return true if  not found
VerifyTextPresentOnPage= False
End If
On Error GoTo
0
End Function

Posted in QTP | Tagged: , , , | 6 Comments »

Locating by XPath

Posted by rajivkumarnandvani on September 20, 2009

Locating by XPath

XPath is the language used for locating nodes in an XML document. As HTML can be an implementation of XML (XHTML), Selenium users can leverage this powerful language to target elements in their web applications. XPath extends beyond (as well as supporting) the simple methods of locating by id or name attributes, and opens up all sorts of new possibilities such as locating the third checkbox on the page.

One of the main reasons for using XPath is when you don’t have a suitable id or name attribute for the element you wish to locate. You can use XPath to either locate the element in absolute terms (not advised), or relative to an element that does have an id or name attribute. XPath locators can also be used to specify elements via attributes other than id and name.

Absolute XPaths contain the location of all elements from the root (html) and as a result are likely to fail with only the slightest adjustment to the application. By finding a nearby element with an id or name attribute (ideally a parent element) you can locate your target element based on the relationship. This is much less likely to change and can make your tests more robust.

Since only xpath locators start with “//”, it is not necessary to include the xpath= label when specifying an XPath locator.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 <html>
  <body>
   <form id="loginForm">
    <input name="username" type="text" />
    <input name="password" type="password" />
    <input name="continue" type="submit" value="Login" />
    <input name="continue" type="button" value="Clear" />
   </form>
 </body>
 <html>
  • xpath=/html/body/form[1] (3) – Absolute path (would break if the HTML was changed only slightly)
  • //form[1] (3) – First form element in the HTML
  • xpath=//form[@id='loginForm'] (3) – The form element with @id of ‘loginForm’
  • xpath=//form[input/\@name='username'] (4) – First form element with an input child element with @name of ‘username’
  • //input[@name='username'] (4) – First input element with @name of ‘username’
  • //form[@id='loginForm']/input[1] (4) – First input child element of the form element with @id of ‘loginForm’
  • //input[@name='continue'][@type='button'] (7) – Input with @name ‘continue’ and @type of ‘button’
  • //form[@id='loginForm']/input[4] (7) – Fourth input child element of the form element with @id of ‘loginForm’
  • Expresion in square brackets can further specify an element. A number in the brackets gives the position of the element in the selected set. The function last() selects the last element in the selection.

/AAA/BBB[1]

Select the first BBB child of element AAA
<AAA>
<BBB/>
<BBB/>
<BBB/>
<BBB/>
</AAA>

/AAA/BBB[last()]

Select the last BBB child of element AAA
<AAA>
<BBB/>
<BBB/>
<BBB/>
<BBB/>
</AAA>

Attributes are specified by @ prefix.

//@id

Select all attributes @id
<AAA>
<BBB id = “b1″/>
<BBB id = “b2″/>
<BBB name = “bbb”/>
<BBB/>
</AAA>

//BBB[@id]

Select BBB elements which have attribute id
<AAA>
<BBB id = “b1″/>
<BBB id = “b2″/>
<BBB name = “bbb”/>
<BBB/>
</AAA>

//BBB[@name]

Select BBB elements which have attribute name
<AAA>
<BBB id = “b1″/>
<BBB id = “b2″/>
<BBB name = “bbb”/>
<BBB/>
</AAA>

//BBB[@*]

Select BBB elements which have any attribute
<AAA>
<BBB id = “b1″/>
<BBB id = “b2″/>
<BBB name = “bbb”/>
<BBB/>
</AAA>

//BBB[not(@*)]

Select BBB elements without an attribute
<AAA>
<BBB id = “b1″/>
<BBB id = “b2″/>
<BBB name = “bbb”/>
<BBB/>
</AAA>

Values of attributes can be used as selection criteria. Function normalize-space removes leading and trailing spaces and replaces sequences of whitespace characters by a single space.

//BBB[@id='b1']

Select BBB elements which have attribute id with value b1
<AAA>
<BBB id = “b1″/>
<BBB name = ” bbb “/>
<BBB name = “bbb”/>
</AAA>
//BBB[normalize-space(@name)='bbb']
Select BBB elements which have attribute name with value bbb, leading and trailing spaces are removed before comparison
<AAA>
<BBB id = “b1″/>
<BBB name = ” bbb “/>
<BBB name = “bbb”/>
</AAA>

Function count() counts the number of selected elements

//*[count(BBB)=2]

Select elements which have two children BBB
<AAA>
<CCC>
<BBB/>
<BBB/>
<BBB/>
</CCC>
<DDD>
<BBB/>
<BBB/>
</DDD>
<EEE>
<CCC/>
<DDD/>
</EEE>
</AAA>

//*[count(*)=2]

Select elements which have 2 children
<AAA>
<CCC>
<BBB/>
<BBB/>
<BBB/>
</CCC>
<DDD>
<BBB/>
<BBB/>
</DDD>
<EEE>
<CCC/>
<DDD/>
</EEE>
</AAA>

Function name() returns name of the element, the starts-with function returns true if the first argument string starts with the second argument string, and the contains function returns true if the first argument string contains the second argument string.

//*[name()='BBB']

Select all elements with name BBB, equivalent with //BBB
<AAA>
<BCC>
<BBB/>
<BBB/>
<BBB/>
</BCC>
<DDB>
<BBB/>
<BBB/>
</DDB>
<BEC>
<CCC/>
<DBD/>
</BEC>
</AAA>
//*[starts-with(name(),'B')]
Select all elements name of which starts with letter B
<AAA>
<BCC>
<BBB/>
<BBB/>
<BBB/>
</BCC>
<DDB>
<BBB/>
<BBB/>
</DDB>
<BEC>
<CCC/>
<DBD/>
</BEC>
</AAA>

//*[contains(name(),'C')]

Select all elements name of which contain letter C
<AAA>
<BCC>
<BBB/>
< BBB />
< BBB />
</BCC>
<DDB>
< BBB />
< BBB />
</DDB>
<BEC>
<CCC/>
<DBD/>
</BEC>
</AAA>

The string-length function returns the number of characters in the string. You must use &lt; as a substitute for < and &gt; as a substitute for > .

//*[string-length(name()) = 3]

Select elements with three-letter name
<AAA>
<Q/>
<SSSS/>
<BB/>
<CCC/>
<DDDDDDDD/>
<EEEE/>
</AAA>

Several paths can be combined with | separator.

//CCC | //BBB

Select all elements CCC and BBB
<AAA>
<BBB/>
<CCC/>
<DDD>
<CCC/>
</DDD>
<EEE/>
</AAA>

/AAA/EEE | //BBB

Select all elements BBB and elements EEE which are children of root element AAA
<AAA>
<BBB/>
<CCC/>
<DDD>
<CCC/>
</DDD>
<EEE/>
</AAA>

/AAA/EEE | //DDD/CCC | /AAA | //BBB

Number of combinations is not restricted
<AAA>
<BBB/>
<CCC/>
<DDD>
<CCC/>
</DDD>
<EEE/>
</AAA>

Note :–  All Example are taken from http://www.zvon.org/xxl/XPathTutorial/General/examples.html

Posted in QTP | Leave a Comment »