Sunday, May 29, 2011

Working With Text File

The File System object allows us to work with files and folders .We can read, write, create, and delete files and folders using the File System object and the objects that are associated with it.


Creation of Text File:
 
Three ways to create an empty text file:



1.CreateText File method


2.OpenTextFile method of the FileSystemObject object with the ForWriting flag set.


3.OpenAsTextStream method with the ForWriting flag set.

CreateTextFile Method

Creates a specified file name and returns a TextStream object that can be used to read from or write to the file. 
Example:



Const ForReading = 1, ForWriting = 2, ForAppending = 8


Dim fso, f


Set fso = CreateObject("Scripting.FileSystemObject")


Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)


f.Write "Hello world!“


f.Close

Syntax:



For Moving a File:


Object.Move(“Destination path”)


For Copying a File:


Object.Copy(“Destination path”)


For Deleting a File:


Object.Delete

Set MyFile = fso.GetFile("c:\testfile.txt")



MyFile.Move(c:\tmp\testfile.txt)


MyFile.Copy (“c:\QTP\testfile.txt “)


Set f2=fso.Getfile(“C:\QTP\testfile.txt”)


f2.Delete

There are 3 methods to read a file.



Read Method: Read a specified number of characters from a file.


ReadAll Method: Read the entire contents of a text.


ReadLine Method:Read an entire line (up to, but not including, the newline character).

Reads a specified number of characters from a TextStream file and returns the resulting string.  
Write Method
 
Example:



Function WriteToFile


Const ForReading = 1, ForWriting = 2


Dim fso, f


Set fso = CreateObject("Scripting.FileSystemObject")


Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)


f.Write "Hello world!"


WriteLine Method
 
Writes a specified string and newline character to a TextStream file.



Syntax :


object.WriteLine([string])
 
Example:



Const ForReading = 1, ForWriting = 2


Dim fso, f


Set fso = CreateObject("Scripting.FileSystemObject")


Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)


f.WriteLine "Hello world!“


f.WriteLine "VBScript is fun!"

Writes a specified number of newline characters to a TextStream file.


Syntax: object.WriteBlankLines(lines)

WriteBlankLines Method

Example:


Const ForReading = 1, ForWriting = 2

Dim fso, f

Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)

f.WriteBlankLines 2

f.WriteLine "Hello World!"


Syntax: object.Read(characters)

Const ForReading = 1, ForWriting = 2, ForAppending = 8


Dim fso, f

Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)

Read Method

f.Write "Hello world!"


Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)

s= f.Read(5)

Msgbox s

ReadAll Method

Reads an entire TextStream file and returns the resulting string.


Syntax :object.ReadAll( );

Readline Method
 
Example:


Dim fso, f1, ts, s

Const ForReading = 1

Set fso = CreateObject("Scripting.FileSystemObject")

Set f1 = fso.CreateTextFile("c:\testfile.txt", True)

Write Method

Writes a specified string to a TextStream file.


Syntax :

object.Write(string)


Syntax:

object.CreateTextFile(filename[, overwrite[, unicode]])

Object-> Name of a FileSystemObject or Folder object

Filename ->String expression that identifies the file to create.

Overwrite-> “True” if the file can be overwritten and “False” otherwise

Unicode-> value is “True” if the file is created as a Unicode file and “False” if the file is created as a ASCII file.


Example:

Dim fso, f1

Set fso = CreateObject("Scripting.FileSystemObject")

Set f1 = fso.CreateTextFile("c:\testfile.txt", True)

OpenTextFile method

Opens a Specified file and returns a Textstream object that can be used to read from,write to or append to the file.


Syntax: object.OpenasTextStream([iomode, [format]])

Object – Name of the File object

Iomode-Optional (Can be For Reading=1,For Writing=2 ,For Appending=8)

Format: Optional. Used to indicate the format of the opened file.


TristateUseDefault – 2

Tristate True –1

Tristate False 0

0 opens the file as ASCII and –1 opens as Unicode and –2 uses System default.

Example:


Const ForReading = 1, ForWriting = 2, ForAppending = 8

Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Dim fso, f, ts

Set fso = CreateObject("Scripting.FileSystemObject") fso.CreateTextFile "test1.txt" ' Create a file.

Set f = fso.GetFile("test1.txt")


Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)

ts.Write "Hello World"

ts.Close

FileMethod

Syntax:


object.OpenTextFile(filename[, iomode[, create[, format]]])

Object: Always the name of a FileSystemObject.

filename :String expression that identifies the file to open.

iomode :Optional. Can be one of three constants: ForReading, ForWriting, or ForAppending
 
Create: Optional. Boolean value that indicateas whether a new file can be created if the specified filename doesn't exist. The value is True if a new file is created, False if it isn't created. If omitted, a new file isn't created.

Friday, May 27, 2011

QTP DataTable

Introduction:

The Data Table is a Microsoft Excelsheet with columns and rows representing the data

The Data Table contains one Global tab plus an additional tab for each action.
The Data Table assists you in parameterizing your test.
To view the Data Table, click the Data Table toolbar button

DataTable Parameters:
Data Table parameters enable you to create a data-driven test, component, or action that runs several times using the data you supply. In each iteration, QTP uses a different value from the Data Table
 

Setting DataTable Parameter Options:
Data Table parameters enable you to create a data-driven test (or action) that runs several times using the data you supply. For each iteration, QTP uses a different value from the Data Table.


When Data Table is selected as the parameter type, the Parameter Options dialog box enables you to configure your parameter to use values from the Data Table.

Global Datasheet:

The Global sheet contains the data that replaces parameters in each iteration of the test. If you create a Global parameter called Arrivals, the Global sheet might look like this:
Run Time DataTable:
During the run session, QTP creates a run-time Data Table associated with your test.It displays the run-time data in the Data Table pane so that any changes to the Data Table can be seen as they occur.The final data from the run-time Data Table is displayed in the Run-Time Data Table in the Test Results window

The Run-Time Data Table displays the parameterized values that were used, as well as any output values stored in the Data Table during the run.The Run-Time Data Table can be viewed from the Test results window.

Run Time Data Table Methods:

AddSheet Method
DeleteSheet Method
Export Method
ExportSheet Method
GetCurrentRow Method
GetRowCount Method
GetSheet Method
GetSheetCount Method
Import Method
ImportSheet Method
SetCurrentRow Method
SetNextRow Method
SetPrevRow Method

AddSheet Method
Adds the specified sheet to the run-time Data Table and returns the sheet so that properties can be directly set for the new sheet in the same statement.

Syntax:
DataTable.AddSheet(SheetName)
Example
Variable=DataTable.AddSheet ("MySheet").AddParameter("Time", "8:00")


DeleteSheet Method
Deletes the specified sheet from the run-time Data Table.

Syntax
DataTable.DeleteSheet SheetID
The SheetID can be the sheet name or index. Index values begin with 1.
Example
DataTable.DeleteSheet "MySheet"
MySheet gets deleted from Data Table

Export Method
Saves a copy of the run-time Data Table in the specified location

Syntax
DataTable.Export(FileName)
Example:
DataTable.Export ("C:\flights.xls")

ExportSheet Method
Exports a specified sheet of the run-time Data Table to the specified file.

If the specified file does not exist, a new file is created and the specified sheet is saved.
If the current file exists, but the file does not contain a sheet with the specified sheet name, the sheet is inserted as the last sheet of the file.
If the current file exists and the file contains the specified sheet, the exported sheet overwrites the existing sheet.
Syntax:
DataTable.ExportSheet(FileName, DTSheet)
Example:
DataTable.ExportSheet "C:\name.xls" ,1

GetCurrentRowCount
Returns the current (active) row in the first sheet in the run-time Data Table

Syntax:
DataTable.GetCurrentRow
Example
row = DataTable.GetCurrentRow
Reporter.ReportEvent 1, "Row Number", row



GetRowCount Method
Returns the total number of rows in the longest column in the first sheet in the run-time Data Table

Syntax
DataTable.GetRowCount
Example:
rowcount = DataTable.GetSheet("MySheet").GetRowCount
Reporter.ReportEvent 2, "There are " &rowcount, "rows in the data sheet."

GetSheet Method
Returns the specified sheet from the run-time Data Table

Syntax
DataTable.GetSheet(SheetID)
Example
MyParam=DataTable.GetSheet ("MySheet").AddParameter("Time", "8:00")

GetSheetCount Method
Returns the total number of sheets in the run-time Data Table

Syntax
DataTable.GetSheetCount
Example
Sheetcount = DataTable.GetSheetCount

Import Method
Imports the specified Microsoft Excel file to the run-time Data Table.

Syntax
DataTable.Import(FileName)
Example
DataTable.Import ("C:\flights.xls")

ImportSheet Method
Imports a sheet of a specified file to a specified sheet in the run-time Data Table.
The data in the imported sheet replaces the data in the destination sheet
Syntax
DataTable.ImportSheet(FileName, SheetSource, SheetDest)
Example:
DataTable.ImportSheet "C:\name.xls" ,1 ,"name"

SetCurrentRow Method
Sets the specified row as the current (active) row in the run-time Data Table.
Syntax
DataTable.SetCurrentRow(RowNumber)
Example
DataTable.SetCurrentRow (2)

SetNextRow Method
Sets the row after the current (active) row as the new current row in the run-time Data Table.
Syntax
DataTable.SetNextRow
Example
DataTable.SetNextRow

SetPreRow Method
Sets the row above the current (active) row as the new current (active) row in the run-time Data Table.

Syntax
DataTable.SetPrevRow
Example
DataTable.SetPrevRow

Data Table Properties

GlobalSheetProperties
RawValueProperties
LocalSheetProperties


GlobalSheet Properties
Returns the first sheet in the run-time Data Table

Syntax
DataTable.GlobalSheet
Example
ParamValue=DataTable.GlobalSheet.AddParameter("Time", "5:45")

LocalSheet Properties
Returns the current (active) local sheet of the run-time Data Table.

Syntax:
DataTable.LocalSheet
Example
MyParam=DataTable.LocalSheet.AddParameter("Time", "5:45")

RawValue Property
Retrieves the raw value of the cell in the specified parameter and the current row of the run-time Data Table

Syntax
DataTable.RawValue ParameterID [, SheetID]
Example
FormulaVal=DataTable.RawValue ("Date","ActionA")

Value Property


This is a DataTable’s default property. It retrieves or sets the value of the cell in the specified parameter and the current row of the run-time Data Table

Syntax
DataTable.Value(ParameterID[,SheetID]) = NewValue
Example
DataTable.Value(“Destination”,”ActionA”) = “New York”

Name Property

Returns the name of the run-time data sheet

Syntax
DTSheet.Name
Example
SheetName = DataTable.LocalSheet.Name













 

Wednesday, May 25, 2011

Object Repository

Object Repository is the collection of object properties used by QTP to identify the objects on the application .

Object repository is split into two components
1.Logical Name
2.Physical Description

Logical name is accomadated in script and repository to link script and repository.
Physical description is accomadated in repository to uniquely identify the objects.

Choosing the Object Repository Mode

The object repository per-action mode is easiest to use when you are creating simple record and run tests, especially under the following conditions


You have only one, or very few, tests that correspond to a given application, interface, or set of objects

You do not expect to frequently modify test object properties

You generally create single-action tests

The shared object repository mode is generally the preferred mode when:


You have several tests that test elements of the same application, interface, or set of objects

You expect the object properties in your application to change from time to time and/or you regularly need to update or modify test object properties

You often work with multi-action tests and regularly use the Insert Copy of Action and Insert Call to Action options

When working in object repository per-action mode:


QuickTest creates a new (blank) object repository for each action

As you record operations on objects in your application, QuickTest automatically stores the information about those objects in the appropriate action object repository

When you create a new action, QuickTest creates another new object repository and again begins adding test objects to the repository as you record



When you record on the same object in your application in two different actions, the object is stored as a separate test object in each object repository

When you save your test, all of the action object repositories are automatically saved with the test as part of each action within the test. The action object repository is not accessible as a separate file (as is the shared object repository)

Updating Test Objects in Object Repository Per-Action Mode


Modifying the test object properties, values, or names in one object repository does not affect the information stored for the same test object in another object repository or in other tests

If you parameterize objects in one action, the parameterization applies only to the objects in that current action

Splitting and Copying Actions in Object Repository Per-Action Mode


When you split an action in your test while using the object repository per-action mode:

QuickTest makes a copy of the action object repository

The two actions have identical object repositories containing all of the objects that were in the original object repository

If you add objects to one of the split actions, the new objects are added only to the corresponding action object reposit

When you insert a copy of an action into your test:


The copied action's action object repository is copied along with the action steps

You can edit the object repository of the copied action as you would any other object repository in the test

Understanding the Shared Object Repository Mode

When working in shared object repository mode: QuickTest uses the same test object from the shared object repository file when you record on the same object in two different actions or in different tests or components.


QuickTest adds new objects to the object repository as you record steps on the object

QuickTest uses the existing information and does not add the object to the object repository if you record operations on an object that already exists in the shared object repository (i.e. the object has the same test object description)




QuickTest saves changes to the shared object repository file when you save your open test or component or when you click Save in the Object Repository dialog box if the shared object repository is not locked and/or opened in read-only mode

Updating Test Objects in Shared Object Repository Mode


Shared object repository mode enables you to:

Easily maintain your tests or components when an object in your application changes

Manage all the objects for a suite of tests or components in one central location



When you modify the test object properties, names, parameterization settings, and so forth, in your shared object repository for an open test or component, QuickTest applies the change to all the tests or components that use the same shared object repository file

Parameterizing Test Objects in Shared Object Repository Mode


When you parameterize an object property in a shared object repository, there are several issues you should consider:

When you parameterize an object property (with any type of parameter), the change applies to all tests or components that already contain that object

When you parameterize an object property that is part of an object's description, and then record on the object in your application again, QuickTest creates a new test object in the shared object repository. This is because the description of the object in the object repository is not identical to the one in the application

Renaming Objects in a Shared Object Repository


If you rename objects in a shared object repository in one test or component and save the changes, when you open another test or component using the same shared object repository, that test or component updates the object name in all steps of the test or component. This process may take a few moments. If you save the changes to the second test or component, the renamed steps are saved.

However, if you close the second test or component without saving, then the next time you open the same test or component, it will again take a few moments to update the object names in the test or component steps

Splitting and Copying Actions in Shared Object Repository Mode .


When you insert a copy of an action into a test that uses a shared object repository, keep in mind:

Only the action itself is copied and not its corresponding object repository.

The copied action will use the same shared object repository as the test into which it is being copied.

When you insert copies of actions from tests using a different shared object repository or per-action repository mode, you must ensure that all the objects contained in the action are in the test's shared object repository. If the action uses objects that are not in the shared object repository, the test may fail


Choose Test > Settings > Resources tab


In the Object repository type area, select Per-action or Shared

If you selected Shared, specify the shared object repository file you want to use as the object repository file. To specify a file, enter the object repository file name or click the browse button and select a resource file from the Open dialog box. To create a new shared object repository file, enter a new file name in the Shared box

If you want to make your selection the default setting for new tests, click Set as Default

Click OK to save and close the Test Settings dialog box


Setting the Object Repository Mode


Consider the following when setting a default shared object repository file:


Any existing or open tests or components will not be affected by setting a different, default shared object repository file

All new tests or components will attempt to access your default shared object repository

If the shared object repository file's path is relative, QuickTest searches for the shared object repository file in the current test's folder and then in the Folders tab of the Options dialog box

It is recommended that you ensure that the path for the shared object repository is absolute or listed in the Folders tab of the Options dialog box


If you choose to set a file with a relative path or one that is in the current test's folder as the default shared object repository, QuickTest may not be able to locate the file when creating a new test

If the default shared object repository file is in Quality Center, you must be connected to Quality Center when you create a new test


 





Sunday, May 22, 2011

Introduction To QTP

QUICK TEST PROFESSIONAL

A powerful functional and regression testing  automation tool designed by mercury interactive.

QTP is easier to use and implement for both technical and non technical tester in comparison to other testing tools available in the market.

QTP uses VBScript as a scripting language , which is very easy to learn and use and implement the logics.

Environments supported

Windows Applications




(MFC)

Visual Basic

.Net

J2EE

XML

Java

ActiveX

Web Technologies


HTML


DHTML

JavaScript

Enterprise Applications


SAP


Oracle

PeopleSoft

Siebel

Browser Supported

IE


Netscape

AOL

Operating System


Windows XP


Windows 2K

Windows 98

Windows NT

Windows ME


Introduction To Automation Testing

1.Limitaions Of manual testing

a.Time consuming.
b.Chances of making mistakes when doing repatative work.
c.Require more human resources.

2.Advantages of automation tools

a.Faster test execution
b.Reliable
c.Repeatability
d.Progmamming capability
e.Reusability

3.Test cases to be automated

a.Tests that needs to be run for every build of the application(Sanity test and regression test)
b.Tests that use multiple data for same actions.
c.Load/Stress testing

More Repeatative Execution ! Better Candidates for Automation.

4.Tests cases not to be automated

a.Usability testing
b.One time testing
c.ASAP testing
d.Adhoc/Random testing



Wednesday, May 11, 2011

Tracebility Matrix

Traceability matrix is used to map between requirements and test cases.It is used to check all requirements are tested or not?.A document showing the relation between test requirement and test case.To check whether the testcases are mapped with the requirement.

Suppose a requirement contains 100 requiremets , then we should have atleast one testcase to veryfy each and every requirement , this is called farward tracebility.

If you trace back from test case to requirement ,all test case should point to atleast one requirement this is called backword tracibility.

There should not be any requirement without any test cases and there should not be any test case which is not pointed to some requirement.

The content of the tracibility matrix looks like the below image ...