Wednesday, February 9, 2011

Script to Check if file exists or not

'Check if file exists
On Error Resume Next
dim objFSO

strFile="c:\file.txt"
set objFSO=CreateObject("Scripting.FileSystemObject")

if objFSO.FileExists(strFile) then
   wscript.Echo strFile & " exists"
   'insert any other code you want to execute if file exists
else
   wscript.Echo "Cannot find " & strFile
   'insert any other code or error handling you want to execute
   'if file does not exist
end if

set objFSO=Nothing

Append to an existing text file

'Append to an existing text file
On Error Resume Next
dim objFSO
dim objFile

Const ForAppending=8
'specify filename and path for file to open
strFile="c:\file.txt"

set objFSO=CreateObject("Scripting.FileSystemObject")
set objFile=objFSO.OpenTextFile(strFile,ForAppending)
objFile.WriteLine Now & " this is an appended line"
objFile.Close

set objFile=Nothing
set objFSO=Nothing

Script to Delete a file from system

'Delete file
On Error Resume Next
dim objFSO

'specify filename and path for file to create
strFile="c:\file.txt"

set objFSO=CreateObject("Scripting.FileSystemObject")
'to force deletion, set to TRUE otherwise set to FALSE
objFSO.DeleteFile strFile,TRUE





Create a text file example

'create a text file example
On Error Resume Next
dim objFSO
dim objFile

'specify filename and path for file to create
strFile="c:\file.txt"
set objFSO=CreateObject("Scripting.FileSystemObject")
'if file already exists, value of TRUE forces overwriting file
set objFile=objFSO.CreateTextFile(strFile,TRUE)
objFile.WriteLine "This is an entry into my logfile"
'write 3 blank lines
objFile.WriteBlankLines(3)
objFile.WriteLine "Here is the last line of my logfile"
wscript.Echo "See " & strFile & " for results"
'close file
objFile.Close
set objFSO=Nothing
set objFile=Nothing

Write Log Report in QTP with the help of Class


' Calling class method.
dim fineName
set objLogger = new Logger fileName = objLogger.createLogFile()
objLogger.getInput "1",Date,"Login","User can Login","Login successfully","Pass"
objLogger.writeLogDetails fileName

' Class defination


Class Logger
           dim slNo
           dim dtTime
           dim functionName
           dim expectedResult
           dim actualResult
           dim status
           dim path

             Function createLogFile()

                            path = inputbox("Enter the log path:")
                            driveName = "d:\" 
                            Fullpath = driveName & path 
                            set fso = CreateObject("Scripting.FileSystemObject")
                            set f1 = fso.CreateTextFile(FullPath, True)

                             If (fso.FileExists(Fullpath)) Then
                                    msgbox Fullpath & " exists."                            
                             Else
                                    msgbox = Fullpath & " doesn't exists."
                             End If                            
                             createLogFile=Fullpath
            End Function

  Function getInput(VslNo,VdtTime,VfunctionName,VexpectedResult,VactualResult,Vstatus)      
                            slNo = Vslno
                            dtTime = VdtTime
                             functionName = VfunctionName 
                             expectedResult = VexpectedResult
                             actualResult = VactualResult
                             status = Vstatus
            End Function 

            Function writeLogDetails(fpath)
                            f1.writeLine = slNo
                            f1.writeLine = dtTime
                            f1.writeLine = functionName
                            f1.writeLine = expectedResult
                            f1.writeLine = actualResult
                            f1.writeLine = status
                           msgbox "write Done"
           End function
End Class

Tuesday, February 8, 2011

What is Output Values and types of Output Values ?

An output value is a step in which one or more values are captured at a specific point in your test or component and stored for the duration of the run session. The values can later be used as input at a different point in the run session.

Output values are stored only for the duration of the run session. When the run session is repeated, the output values are reset.

You can insert an output value by using commands on the Insert menu or by clicking the arrow beside the Insert Checkpoint button on the Test toolbar. This displays a menu of options that are relevant to the selected step in the test tree.

Types of Output Values

1: Page Output Values:
You can create a page output value from a Web page property value. When you run the test,
QuickTest retrieves the current value of the property and stores it in the run-time Data Table as an
output value.

2: Text Output Values:
QuickTest allows you to create text output values by adding one of the following to your test:
     Text Output Value—enables you to output the text displayed in a screen or Web page, according to 
              specified criteria. It is supported for all environments.
     Standard Output Value—enables you to output an object’s text property. This is the preferred way of
             outputting the text displayed in many Windows applications.
     Text Area Output Value—enables you to output the text string displayed within a defined area of a
            Windows-application screen, according to specified criteria. It is supported for Standard
            Windows, Visual Basic, and ActiveX environments.

3: Standard Output Values:
You can create a standard output value from an object property value. When you run the test, QuickTest
retrieves the current value of the property and enters it in the run-time Data Table as an output value.

4: Image Output Values:
You can create an image output value from the property value of a Web image. When you run the test,
QuickTest retrieves the current value of the property and enters it in the run-time Data Table as an output
value.

5: XML Output Values:
You can create an XML output value from an element value or attribute of an XML file or Web page/frame.
When you run the test, QuickTest retrieves the current value of the element or attribute and enters it in the
run-time Data Table as an output value.

When you run your test, you can view summary results of the XML output value in the Test Results window.
You can also view detailed results by opening the XML Output Value Results window.

6: Table Output Values:
You can create a table output value from the contents of a table cell. When you run the test, QuickTest
retrieves the current value of a table cell and enters it in the run-time Data Table as an output value.

7: Database Output Values:
You can create a database output value from the contents of a database cell. When you run the test,
QuickTest retrieves the current value of a database cell and enters it in the run-time Data Table as an output
value.

Types of environment variables in QTP

There are three Types of Environment Variables in qtp
 1: User-Defined Internal
2: User-Defined External
3: Build-in

1: User-Defined Internal

User defined internal variables are the variables that you define within the test. They are saved with the test and accessible only within the test in which they were defined.

        • In the Edit value section of the Object Properties, Object Repository, Method Arguments, or 
          Checkpoint Properties dialog box, click Other as the type of parameter you want to use.
       • Click the Edit Parameter Options button next to the parameter type box. The Parameter Options

         dialog box opens.
       • Select Environment in the Parameter Types box.
       • Accept the default name or enter a new name to add a new user-definedinternal environment

          parameter, or select an existing environment variable name from the Name box. If you select an 
         existing internal parameter, you can modify the value.
       • If you created a new parameter or selected an existing user-defined-internal parameter, enter the value

         for the parameter in the Value box.
       • Select the Regular Expression check box if needed and Enter the regular expression
       • Click OK to save your changes and close the dialog box.

2: User-Defined External

User defined external variables are the variable that you pre-defined in the active external environment variables file. You can create as many files as you want and select an appropriate file for each test. Note that external environment variable values are designated as read-only within the test.

To define these variables create an external environment variables file
To select the active external environment-variables file:
      • Choose Test > Settings to open the Test Settings dialog box.
      • Click the Environment tab.
      • Select the Load variables and values from external file (reloaded each test run) check box.
      • Use the browse button or enter the full path of the external environment- variables file you want to use
         with your test.

3: Build-in



Built-in variables, such as Test path and Operating system. They are accessible from all tests, and are designated as read-only.
Steps to add or modify environment variable parameters: