Thursday, February 3, 2011

Find the number of lines in text file


Function NoOfLineInTextFile() As Integer
      Dim objFSO, strTextFile, strData, arrLines, LineCount
      Const ForReading = 1
      strTextFile = "d:\StringFile.txt"
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      strData = objFSO.OpenTextFile(strTextFile, ForReading).ReadAll
      arrLines = Split(strData, vbCrLf)
      LineCount = UBound(arrLines) + 1
      Set objFSO = Nothing
      MsgBox "Number of lines available in : " & LineCount
      NoOfLineInTextFile = LineCount
End Function

Read a Flat file and updated specific word.

Problem: Find the ‘QQ’ word and next word should replace with user input

Logic:
  1. Read Line by Line from text file and storing into Array
  2. Updating array if QQ word found
  3. Writing into File again
StringFile.txt contains:

11;12;xxxxxxxx;6666;77777;7777777;uuuu;ayex345;QQ;yyy;w434;ccc;
1q5;9s9;2f; 
' ################ Function call #########################
call ReadFromFile()

' ############### Function defination #####################
Function ReadFromFile()

          Const ForReading = 1
          Set objFSO = CreateObject("Scripting.FileSystemObject")
          Set objFile = objFSO.OpenTextFile("d:\StringFile.txt", ForReading)
          Dim arrFileLines()
          i = 0
          Do Until objFile.AtEndOfStream
                ReDim Preserve arrFileLines(i)
                 arrFileLines(i) = objFile.ReadLine
                i = i + 1
         Loop
         objFile.Close

         Call UpdateArrayValue(arrFileLines) ' Update array
         Call WriteArrIntoFiles(arrFileLines) ' writing file

End Function

Function UpdateArrayValue(arrFileLines)
     
       For K = 0 to Ubound(arrFileLines)
               NewArr = Split(arrFileLines(K), ";")
               For j = 0 To UBound(NewArr)
                        If NewArr(j) = "QQ" Then
                                    NewArr(j + 1) = "xxx"   ' xxx is user input value
                        End If
               Next
               UpdatedNewArr = Join(NewArr, ";")
               arrFileLines(K) = UpdatedNewArr
      Next
End Function

Function WriteArrIntoFiles(Arr)

              Const ForWriting = 2
              Set objFSO = CreateObject("Scripting.FileSystemObject")
              Set f = objFSO.GetFile("d:\StringFile.txt")
              Set Ln = f.OpenAsTextStream(ForWriting)
              For j = 0 To UBound(Arr)
                    Ln.WriteLine (Arr(j))
              Next
              Ln.Close
End Function

Test Object Model Concept

The test object model is a large set of object types or classes that QuickTest uses to represent the objects in your application. Each test object class has a list of properties that can uniquely identify objects of that class and a set of relevant methods that QuickTest can learn about it.

A test object is an object that QuickTest creates in the component to represent the actual object in your application. QuickTest stores information on the object that will help it identify and check the object during the run session.

A run-time object is the actual object in your application on which methods are performed during the run session

Each Test object Properties contains:

1. Name ( Logical Name )
2. Class ( Button, Edit box, Combo box etc)
3. Physical Property ( Test Object details)
        a. HTML Property Name
        b. Value of HTML Property

Understanding How QuickTest Identifies Objects during the Run Session

During a run session, QuickTest searches for a run-time object that exactly matches the description of the test object it learned previously. It expects to find a perfect match for both the mandatory and any assistive properties it used to create a unique description while learning the object. As long as the object in the application does not change significantly, the description learned is almost always sufficient for QuickTest to uniquely identify the object. This is true for most objects, but your application could include objects that are more difficult to identify during subsequent run sessions.
QuickTest uses process of elimination with its Smart Identification mechanism to identify an object, even when the learned description is no longer accurate. Even if the values of your test object properties change, QuickTest maintains your component's reusability by identifying the object using Smart Identification.

Understanding How QuickTest Learns Objects

Object being learned and stores it as a test object, determining in which test object class it fits. In the same way, QuickTest might classify the test object as a standard Windows dialog box (Dialog), a Web button (WebButton), or a Visual Basic scroll bar object (VbScrollBar)

Then, for each test object class, QuickTest has a list of mandatory properties that it always learns; When QuickTest learns an object, it always learns these default property values, and then "looks" at the rest of the objects on the page, dialog box, or other parent object to check whether this description is enough to uniquely identify the object. If it is not, QuickTest adds assistive properties, one by one, to the description, until it has compiled a unique description; If no assistive properties are available, or if those available are not sufficient to create a unique description, QuickTest adds a special ordinal identifier, such as the object's location on the page or in the source code, to create a unique description.

Keyword- Driven concept in QTP

Keyword-driven testing is a technique that separates much of the programming work from the actual test steps so that the test steps can be developed earlier and can often be maintained with only minor updates, even when the application or testing needs change significantly.
Using the keyword-driven approach, test automation experts have full access to the underlying test and object properties, via an integrated scripting and debugging environment that is round-trip synchronized with the Keyword View.

New Features in QTP 9.5

QuickTest now offers the following new features.


  1. Process Guidance. QuickTest offers a special Process Guidance tool that lets you navigate through the core activities of important testing processes to learn how to best perform those processes.
  2. Maintenance Run Mode. Maintenance Run Mode enables you to run your test or component and to update your steps and repositories as the test or component runs to reflect changes in the application.
  3. New QuickTest IDE Panes. QuickTest has introduced the Test Flow pane, Resources pane, Available Keywords pane, and Missing Resources pane to help you create and manage tests and components faster and easier.
  4. All-in-one QuickTest Installation. The QuickTest installation enables you to install any or all QuickTest add-ins.
  5. Checkpoint and Output Objects in the Object Repository. When you insert a checkpoint or output value, it is created as an object and stored in your local object repository.
  6. Test Your PowerBuilder Applications in QuickTest. QuickTest now offers the PowerBuilder Add-in for testing your Power Builder applications.
  7. Extend QuickTest Web Support for your Custom Web Objects. The new QuickTest Professional Web Add-in Extensibility enables you to provide high-level support for third-party and custom Web controls that are not supported out-of-the-box by the Web Add-in.
  8. Accelerate SAP Testing with HP Business Process Testing for SAP Applications. The HP Business Process Testing for SAP Applications solution enables you to automatically create and manage components and flows that represent screens and transactions in your SAP application.