Archive

Archive for July, 2009

E-mail address validation

We will discus how to validate email field,
given below,
E-Mail Address = “A@b.c”;                — Valid
E-Mail Address = “A@b.cnet”;         — Invalid
E-Mail Address = “A@b.c_”;             — Invalid
E-Mail Address = “A@bcnn”;            — Invalid
E-Mail Address = “Ab.cnn”;               — Invalid
E-Mail Address = “A@bc”;                  — Invalid
E-Mail Address = “A@bat@.cnn”;   — Invalid
E-Mail Address = “A@bat/.com”;    — Invalid

conditions are,

  1. Must not be too short and too long
  2. Only one @ in email address
  3. Only one period ‘.’ or two periods in email
  4. No more than 3 characters after the final period (reverse find is 0 based not 1 based) com/ org/net/mil/gov/co.in/co.uk and etc
  5. Should not have an underscrode after @
  6. Allowed characters 0-9 A-Z _ . before @

Example E-Mail is thiyagarajannv@yahoo.com

I have devided Email ID in 4 parts in above email id,

  1. In first part we have to check invalid condition input spaces, Left blank, use special character, symbols etc before email in @.
  2. In Second part we have to check invalid condition input other specail character [!#$%^&*()_-:;”‘?/|\) at the place of @. left thisfield as blank. input spaces.etc
  3. In third part we have to check invalid invalid domain.
  4. In fourth part we have to check only valid suffix(.com,.co.in,.edu,.info,.org,.in etc)

very time EmailID should be in well manner.

like thiyagarajannv@yahoo.com and etc.

File Handling Using QTP

QTP File Handling

Many times we have may need to interact with text files using QTP. Interaction can be (but not limited to) in the form of reading input from a file or writing output to a file.

We can use FSO (FileSystemObject) object to do this.

What is FSO?
FSO stands for File System Object. This is used to support text file creation and manipulation through the TextStream object and is contained in the Scripting type library (Scrrun.dll).
The FSO Object Model has a rich set of properties, methods and events to process folders and files.

How to create a file?
We first create a FSO object using CreateObject.

Secondly we create a text file using CreateTextFile.
For Example: Suppose you want to create a file called “test.txt” located in C:\

Dim fso, file, file_actual_location
file_ actual_location = “C:\file_ actual _location”
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set file = fso.CreateTextFile(file_ actual _location, True)

How to open a file?

Set file= fso.OpenTextFile(“C:\file_ actual_location”, ForWriting, True)
//2nd argument can be ForReading, ForWriting, ForAppending
//3rd argument is “True” if new file has to be created if the specified file doesn’t exist else false, blank signify false.

How to read content from a file?
Use ReadLine() method
For example:

Set file= fso.OpenTextFile(“C:\file_ actual_location”, ForReading, True) //2nd argument should always be “ForReading” in order to read contents from a file
Do while file.AtEndofStream <> True
data = file.ReadLine()
msgbox data
Loop

How to write content to a file?
You can use  Write() or WriteLine() Methods to write text into a file. The difference between the Write() and WriteLine() Method is that the latter automatically inserts a new line character while the former doesn’t insert a new line character.
For example:

Set file= fso.OpenTextFile(“C:\file_ actual_location”, ForWriting, True) //2nd argument should always be “ForWriting” in order to write contents to a file
file.Write(“This is test is”)
file.Write(“file created.”)
//Output will be:
This is test is file created.
while
file.WriteLine(“This is test is “)
file.Write(“file created.”)
//Output will be:
This is test is
file created.

How to delete file?
Use DeleteFile() method to delete a file from a particular location
Foe Example:

file_location = “C:\file_actual_location”
Set fso = CreateObject(“Scripting.FileSystemObject”)
fso.DeleteFile(file_ actual_location)