Pages

Monday, March 16

File Handling in QTP - Part 1


Hello Friends!

In this post, we'll see how to handle files using vbscript in QTP.
We'll cover -

  • How to create new file and write data
  • How to open existing file and read data
  • How to open existing file and append data
  • How to delete an existing file

Okie... so lets talk about File System Object (FSO) first. Actually all these things will be done using FSO only!


What is File System Object (FSO)?

File System Object is used to -

1.  creation, manipulation and deletion of text files
2. create, move and Delete folders on hard disk


FSO is the short name for  File System Object.  The FSO Object Model has a rich set of properties, methods and events to process folders and files.

How to create a file?

yeah.. here we go!

Suppose you want to create a file called "myFile.txt" on C:\ drive

Dim objFSO, file_path
file_path = "C:\myFile.txt"

Function CreateFile(file_path)
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set CreateFile = objFSO.CreateTextFile(file_path, True)
End Function

Call CreateFile("C:\myFile.txt")

And it's done! Hunt your C:\ drive.... myFile.txt will be there!

Ggrayyyytt!!

Now, look at this part..

objFSO.CreateTextFile(file_path, True)
objFSO - is an object of type FileSystemObject
CreateTextFile - is a method of FSO
file_path - is the path/location of you file
True - true means - if the file is already there, it will be overwritten.

You can write False also. In that case if file is already there, it'll not be overwritten, and it'll give you following error.




To test this, follow these steps.... n picture'll be clear to you!
  • run the above code
  • open the file and write your name, save and close
  • run the above code again (same)
  • open the file and see- your name will not be there because it's overwritten
  • now change this line in above code and run again.
  • Set CreateFile = objFSO.CreateTextFile(file_path, False
  • this time you will get the error because file is already there and because of False, it will not be overwritten.


Tired?? 

No worries!! In next part of this post, we will reveal all the methods of FSO.

In case of any queries, please post your comments.

50 comments:

  1. Abhikansh ...Thanks a Ton for sharing your knowledge...with us...i have learned a lot..

    -Pankaj

    ReplyDelete
  2. hi this is very useful...

    ReplyDelete
  3. Function CreateFile(file_path)
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set CreateFile = objFSO.CreateTextFile(file_path, True)
    End Function

    Can you please let me know why did you use Set before "CreateFile = objFSO.CreateTextFile(file_path, True)"

    ReplyDelete
  4. what is the meaning testcomplete in automation testing? how can i give the answer to interviewer

    ReplyDelete
  5. TestComplete is a Regression/Functional Testing tool like QTP.

    ReplyDelete
  6. I tried this code to create a file ,file is not created and Testscript doesnt fail it shows done. wht should i do ?

    ReplyDelete
  7. @Aanvi s - make sure you have rights to create a file on given path. try to create a file manually first.

    ReplyDelete
  8. thanks for sharing wonderful blog and keep updating more useful information like this. and you are doing great article.
    Software Testing Training in Chennai

    ReplyDelete

  9. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.

    SAP training in Chennai

    ReplyDelete
  10. thanks for sharing wonderful blog and keep updating more useful information like this. and you are doing great article.
    qtp training in chennai

    ReplyDelete
  11. Your style is very unique compared to other people I've read stuff from. Thanks for posting when you've got the opportunity, Guess I'll just bookmark this web site. gmail login

    ReplyDelete
  12. Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  13. Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website.
    dotnet training in bangalore

    ReplyDelete
  14. I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.


    oracle training in Bangalore

    ReplyDelete
  15. Thanks The information which you provided is very much useful and easy to learn as well... keep rocking and updating... looking further..
    Austere Technologies |Internet Of Things

    ReplyDelete
  16. Really great blog, it's very helpful and has great knowledgeable information.

    Best Cloud Solutions | Austere Technology Solutions

    ReplyDelete
  17. Great article, really very helpful content you made. Thank you, keep sharing.

    Best Software Security Services | Austere Technology Solutions

    ReplyDelete
  18. AWS Training in Bangalore - Live Online & Classroom
    myTectra Amazon Web Services (AWS) certification training helps you to gain real time hands on experience on AWS. myTectra offers AWS training in Bangalore using classroom and AWS Online Training globally. AWS Training at myTectra delivered by the experienced professional who has atleast 4 years of relavent AWS experince and overall 8-15 years of IT experience. myTectra Offers AWS Training since 2013 and retained the positions of Top AWS Training Company in Bangalore and India.


    IOT Training in Bangalore - Live Online & Classroom
    IOT Training course observes iot as the platform for networking of different devices on the internet and their inter related communication. Reading data through the sensors and processing it with applications sitting in the cloud and thereafter passing the processed data to generate different kind of output is the motive of the complete curricula. Students are made to understand the type of input devices and communications among the devices in a wireless media.

    ReplyDelete
  19. Wow, Excellent post. This article is really very interesting and effective.The article you have shared here very awesome. I really like and appreciated your work. I read deeply your article, the points you have mentioned in this article are useful.

    iOS Training

    ReplyDelete
  20. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command

    java training in chennai | java training in bangalore

    java online training | java training in pune

    selenium training in chennai

    selenium training in bangalore

    ReplyDelete
  21. Does your blog have a contact page? I’m having problems locating it but, I’d like to shoot you an email. I’ve got some recommendations for your blog you might be interested in hearing.
    AWS Training in Chennai |Best Amazon Web Services Training in Chennai
    AWS Training in Rajaji Nagar | Amazon Web Services Training in Rajaji Nagar

    Best AWS Training Institute in BTM Layout Bangalore ,AWS Coursesin BTM


    ReplyDelete
  22. Very informative blog, really helpful. Thank you.

    cs course eligibility | ISFS

    ReplyDelete
  23. Wow...Excellent informative blog, really helpful. Thank you.

    Best CMA Training in hyd | ISFS

    ReplyDelete
  24. I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone
    python training in rajajinagar
    Python training in btm
    Python training in usa
    Python training in marathahalli

    ReplyDelete
  25. QTP training in bangalore,QTP training in Bangalore offered by Training in Bangalore with 100% placement assistance. Best QTP training in Bangalore with certified experts
    qtp training in bangalore

    ReplyDelete
  26. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
    Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

    ReplyDelete
  27. IOT Training in Bangalore - Live Online & ClassroomStudents are made to understand the type of input devices and communications among the devices in a wireless media.IOT Training course observes iot as the platform for networking of different devices on the internet and their inter related communication.

    ReplyDelete
  28. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa interview questions and answers
    automation anywhere interview questions and answers
    blueprism interview questions and answers
    uipath interview questions and answers
    rpa training in chennai

    ReplyDelete
  29. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    angularjs Training in electronic-city

    angularjs online Training

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    ReplyDelete
  30. Your article gives lots of information to me. Thanks for sharing.
    acca course in hyderabad | ISFS

    ReplyDelete

  31. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
    Advanced AWS Interview Questions And Answers, Top 250+AWS Interviews Questions and Answers 2018
    Advanced AWS Interview questions and answers | Top 110 AWS Interview Question and Answers
    Advanced AWS Training in Bangalore | Best Amazon Web Services Training in Bangalore
    Advanced AWS Training in Pune | Best Amazon Web Services Training in Pune
    Advanced AWS Online Training | Best Online AWS Certification Course in india

    ReplyDelete
  32. I am sure this post has helped me save many hours of browsing other related posts just to find what I was looking for. Many thanks!
    python course in pune
    python course in chennai
    python course in Bangalore

    ReplyDelete
  33. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog.

    rpa training in chennai |rpa course in chennai|
    rpa training in bangalore | best rpa training in bangalore | rpa course in bangalore | rpa training institute in bangalore | rpa training in bangalore | rpa online training

    ReplyDelete