Using QTP, we want to validate whether the particular image on a web page is .jpg, .gif, .bmp or any other extension.
Solution:
- 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 array filename = Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Featured Destination:").GetTOProperty("file name") ' Split using "." as delimiter arrfile = split(filename,".") msgbox arrfile(Ubound(arrfile))
If you want to keep track of further articles on UFT (QTP). I recommend you to subscribe by email below and have new UFT articles sent directly to your inbox.
Andrew says
Hello Ankur,
Really helpful resource you had shared here.
I hope you will keep updating via this blog.
Thanks
Andrew
Rajasekhar says
Nice example…
Venu says
I just want to know where can I get new version of QTP user guide through net.
Anunay says
@Michelle – A better idea is to use descriptive programming with regular expressions. Even with thsi if you are unable to continue, the only way left is using the index or location properties of the object plus the Smart Identification being enabled. However, i do not believe you would ever come to a situation where QTP is unable to identify an object. You may either be missing an addin or something wrong with the software installation or other environment issues.
Michelle says
How to proceed with QTP when QTP doesn’t identify the object? When a object is not being recognized by QTP, what is the work around so that you can continue with automation?
kami says
Ankur
Iam new to testing….i want to know how to do functional testing of a website using QTP…i mean how to test a website with navigation ….i face this question in interviews so plz let me know the proper process….
subbareddy says
i think Venu is right , for example , MS Excel 2007, extension is .xlsx .
Also, Navan –> How would you use Mid function when you donot know the index to start with as the file names varies.
Venu Yalluri says
Navan, reading the last 3 characters using Mid will not work when the file extension is more than 3 characters
Navan says
I think we can also go for regular expression for file name. Since the file extension is always the last three letters prefixed with a .(dot), we can also make use of mid functions.
I think they will be more easy than using an array n then splitting it
1. First take the string into a varible using GETROProperty(filename)
2. Use mid function to read last three letters of string
3. Display it / Use Msgbox / compare it with provided extensions
Manoj Pant says
Do QTP supports a GUI application build using the QT libraray?
Rahul says
Can any body describe “How to use keyword driven framework”?
Please give an example of this…
Thanks in advance……….
Ankur says
@Prabas and Ajay: I think that would work only for File System Objects
Ajay says
Praabas is also right…..
Check with that function.
Thanks
Ajay Garg
Ajay says
hi,
Very Good example.
123 says
Good Example
Praabas says
we can also use GetExtensionName(agr) metod to find the extension of file.Am I right?
shilpi says
Hi..
My self Shilpi & I want to learn QTP online…Can you please help me out for this…
Thaks & Regards
Shilpi
jay says
Good example, short and good!
Shrini Kulkarni says
Ankur,
I would like to have a email conversation with you .. kindly reply me at shrinik@gmail.com
Shrini Kulkarni
http://shrinik.blogspot.com