Tuesday, December 2, 2008

Compare two text files using standart Windows utility

I faced situation when in my QTP test I need compare two html pages to find out what changed in this HTML code.
I searched some time in Google and tried to find some tool with command line or ActiveX interface,
so I can use it for my test needs. But my efforts did not give acceptable results.
Finally, I decided to use standard Windows utility named fc.exe (abbreviation from 'File Compare').
This utility needs as arguments path to two text files to compare and returns text report with comparison result.
This function below returns result of comparison in text format.
Maybe it helps someone...


'Function that returns True if both text files are the same, returns False if something goes wrong during function execution, and returns list of differences in text format if files are different
'Arguments:
'firstFile
'secondFile
Function compareFiles(firstFile, secondFile)
compareFiles = False
resultOutput = ""
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FilesystemObject")
If fso.FileExists(firstFile) Then
If fso.FileExists(secondFile) Then
Set WshExec = WshShell.Exec("%windir%\system32\fc.exe """& secondFile &""" """& firstFile & """")
Set oTextStream = WshExec.StdOut
text = oTextStream.ReadAll
If InStr(1, text, "FC: no differences encountered", 1) = 0 Then
compareFiles = text
Else
compareFiles = True
End If
'Wait until WshExec terminated
Do Until WshExec.Status = 1
Wait 0.1
Loop
Set WshExec = Nothing
End If
End If
End Function

curr = "E:\BDWizReg.log"
prev = "E:\Copy of BDWizReg.log"

msgbox(compareFiles(curr, prev))

Monday, September 15, 2008

Function ClickLinkByClass

During automation of web-pages I needed function that will find elements on page by specified className, that this link are placed in, and keyword (in case when there are more than one class with className or more than on link in found class). Firstly, I use function described in my prevous post - GetElementsByClassName to get list of elements with specified class, then I use keyword to find needed element or skip search if keyword was not specified. In found element I search for link by tag and then perform search in links html code by keyword, if keyword was not specified I don't perform search and take first found link in element. Fincally I click on link.
Also, if link was successfully found function returns it's value, in other case - returns False.

Code:
'This function used to click on link by indicating class of element, that contains this link
'When there are more than one element with specified class, you should specify keyword by which needed_ element can be identified (for example, ProductName for link to installer on CP)

Function ClickLinkByClass(IE, ClassName, keyword)
ClassArray = GetElementsByClassName(IE, ClassName)
If isEmpty(ClassArray) = False Then
For Each sClass in ClassArray
If keyword = "" Then
Set rightClass = sClass
Exit For
Else 'search class that contains needed keyword
If InStr(1, sClass.innerHTML, keyword, 1) <> 0 Then
Set rightClass = sClass
Exit For
End If
End If
Next
Set ElementsByTag = rightClass.getElementsByTagName("a")
If ElementsByTag.length = 0 Then
'if link was no found in element
ClickLinkByClass = False
Else
'if link was found in element of specified class
For i = 0 to ElementsByTag.Length - 1
someString = RegExp("href="".*""", rightClass.getElementsByTagName("a"_)(i).outerHTML)
If InStr(1, someString, keyword, 1) <> 0 Then
ClickLinkByClass = Mid(someString, 7, len(someString) - 7)
rightClass.getElementsByTagName("a")(i).Click
End If
Next
End If
Else
ClickLinkByClass = False
End If
End Function

Function GetElementsByClassName

Recently I faced with problem that in DOM model there is no function GetElementsByClassName like functions GetElementById or GetElementsByName, so I searched on web for this custom function and found some examples, then I modified it a bit and got such code:

'This function returns all elements found in opened IE page with specified className.
'IE - Internet Explorer object


Function GetElementsByClassName(IE, className)
ReDim Result(0)
Set tags = IE.document.all
For Each tag In tags
If tag.className = className Then
If Result(0) = Empty Then
Set Result(UBound(Result)) = tag
Else
ReDim Preserve Result(UBound(Result)+1)
Set Result(UBound(Result)) = tag
End If
End If
Next
If isEmpty(Result(0)) = False Then
GetElementsByClassName = Result
Else
GetElementsByClassName = Empty
End If
End Function

My QTP web-resources list

Forums with QTP topics:
  1. http://www.sqaforums.com/postlist.php?Cat=0&Board=UBB20, Testing Tools >> HP/Mercury QuickTest Pro
  2. http://it4business.ru/forum/index.php?showforum=26, Форум it4business.ru > Программная инженерия > Тестирование ПО и обеспечение качества > Автоматизированное тестирование ПО > Hewlett-Packard (Mercury) - Quality Center
  3. http://www.advancedqtp.com/forums
  4. http://learnloadrunner.com/forums/
  5. http://forums.sureshkumar.net/testing-tools-qa/
QTP FAQ:
  1. http://www.geekinterview.com/FAQs/QTP-1
  2. http://forums.sureshkumar.net/testing-tools-qa/6245-some-qtp-faqs-useful.html
  3. http://sqa.fyicenter.com/FAQ/QTP-QuickTest-Professional/index.html
Useful web-sites on QTP:
  1. http://qtp.blogspot.com
  2. http://www.knowledgeinbox.com/
  3. http://qtphelper.com/
  4. http://www.advancedqtp.com/
  5. http://qtpexpertise.blogspot.com/
  6. http://www.softwareinquisition.com/
  7. http://mercuryquicktestprofessional.blogspot.com/
  8. http://qtpfaq.wordpress.com/
  9. http://qtpfaq.blogspot.com/
  10. http://quicktesthp.blogspot.com/
  11. http://hpsqtp.blogspot.com/
  12. http://www.topblogarea.com/sitedetails_36525.html
  13. http://www.allinterview.com/Interview-Questions/QTP/page1.html
  14. http://geekswithblogs.net/tmoore/Default.aspx
  15. http://www.querycat.com/search?q=QTP
  16. http://quicktestprofessional.wordpress.com/
  17. http://itknowledgeexchange.techtarget.com/qa-processes
  18. http://www.readablog.com/feed23454.aspx
  19. http://www.learnqtp.com/
  20. http://www.scribd.com/groups/view/12619-qtp-group - present some useful manuals on QTP in PDF format
  21. http://motevich.blogspot.com/
  22. http://groups.google.ru/group/MercuryQTP/topics
  23. http://automated-chaos.blogspot.com/
  24. http://qtpforum.blogspot.com/
  25. http://www.vidbob.com/
  26. http://abouttesting.blogspot.com/

My first post

Hello everybody :)

This is my first post in my QTP notes blog. Now I'm working with QTP and automating test of web-pages and facing some problems which appeared on my professional path. WWW helps me to find answers on how to decide these problems, especially I found many useful blogs on QTP theme.

So I decided to share my experience in QTP with others, because other posts helped me to grow as QTP specialist. I think that it will help me to grow faster in QTP and it will help others novices to find what they want.
Powered By Blogger