Using QTP, we want to validate whether the particular image on a web page is .jpg, .gif, .bmp or any other extension.
- We will take the example of Mercury demo application http://newtours.demoaut.com/.
- The image to be checked is shown in red ellipse above.
- Now “Object spy” on the object.
- Find the property containing filename. Usually the name of the property would be file name itself. The value for this case is featured_destination.gif.
- Put this value into a array using GetTO property.
- Now make use of split function with . (dot) as delimiter.
- The last value of the array would be your required file extension. Usually the 2nd value inside an array would be the file extension, but in case developer assigns the name as featured.destination.gif [Notice the two dots] then it might create a problem that’s why always take the last value of the array.
Here is the script for the process given above:
Dim filename, arrfile'Put filename into the arrayfilename = Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Featured Destination:").GetTOProperty("file name")' Split using "." as delimiterarrfile = split(filename,".")msgbox arrfile(Ubound(arrfile))
Ankur JainFounder at LearnQTPLoves blogging and automation.
Latest posts by Ankur Jain (see all)
- Free Webinar: The Latest In Mobile Test Automation & Extension to QTP - April 20, 2013
- MD5 Checksum: Verify Integrity of UFT(QTP) Download - December 28, 2012
- UFT(QTP) 11.5 is available for download - December 21, 2012