Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Wednesday 24 June 2015

Reverse a string without using strreverse in Vb script

Dim  MyStr, nCnt, i, RevStr

MyStr = inputbox("Enter the String:")
nCnt = Len(MyStr)

For i = 1 to nCnt
     RevStr = Mid(MyStr,i,1)&RevStr
Next

Msgbox "Reversed String is "&RevStr


OutPut:
-----------
Enter the String: UFT
Reversed String is: TFU

Difference between byval and byref in vbscript

ByVal: Byval refers to the actual value of the variable.

Example:
Function fun1(Byref variable1)
variable1=variable1+1
End function

Dim x
x=3
'Pass parameter to the function byval
fun1 x

Msgbox x

Result:3

ByRef: ByRef refers to the location of where the value is stored. 

Examples: 
Function fun1(Byref variable1)
variable1=variable1+1
End function

Dim x
x=3
'Pass parameter to the function byref
fun1 x

Msgbox x

Result:4

Tuesday 23 June 2015

Object Identification Workflow

Below are the steps that will follow to identify a object-


Step 1- QuickTest first attempts to identify the test object using the object’s description properties.


Step 2- If QuickTest finds one or more objects matching the test object’s description and VRI is also defined then it attempts to identify the object using the visual relation identifier.


Step 3- After the visual relation identifier is applied, if no objects or more than one object is found, the visual relation identifier fails, and QuickTest continues to identify with Smart Identification (when defined for that test object class).


Step 4- If no VRI is defined and if no objects or more than one object is found after Smart Identification is applied, QTP will use Ordinal Identifier mechanism.







Visual Relation Identifier-



A visual relation identifier is a set of definitions that enable you to identify the object in the application according its neighboring objects in the application. You can select neighboring objects that will maintain the same relative location to your object, even if the user interface design changes. This enables you to help QuickTest in creating more stable object repositories that can withstand predictable changes to the application’s user interface.

One can define visual relations in the Visual Relation Identifier dialog box, which is accessible from the local or shared object repository, and from the Object Properties dialog box

Visual Relation Categories (Relation Details Area) Category Description-

1- Horizontal - enables you to define related objects according to their horizontal location relative to the object to identify. The following options are available:

➤ Left
➤ Right
➤ In line (horizontally)

2- Vertical- enables you to define related objects according to their vertical location relative to the object to identify. The following options are available:

➤ Above
➤ Below
➤ In line (vertically)

3- Distance and hierarchy- enables you to define related objects according to their distance or hierarchical location relative to the object to identify. The following options are available:

➤ Closest on the X-axis
➤ Closest on the Y-axis
➤ Closest on both axes
➤ Contains

Considerations for Working with Visual Relation Identifiers-

Consider the following when working with visual relation identifiers:

1- If you define a visual relation identifier for a test object, then that test object’s ordinal identifier (if it exists) is not used during the test object identification process.

2- If you add a related object that was not previously in the object repository, then the test object for the related object is added to that object repository.

3-Visual relation identifiers are used only during a run session, or when identifying objects in the application. Therefore, even if you define related objects for a specific test object, if QuickTest re-learns the object, it uses only the identification properties that are defined in the Object Identification dialog box for that test object class.

4- A test object cannot be used as a related object to itself.

5- If you delete a test object (A) that is used in the visual relation identifier for another test object (B), you must make sure to remove the deleted test object A from the Related Object list for test object B.

6- Visual relation identifiers are not supported for WebService test objects.

Ordinal Identifier-

An ordinal identifier assigns a numerical value to a test object that indicates its order or location relative to other objects with an otherwise identical description (objects that have the same values for all properties). This ordered value provides a backup mechanism that enables QuickTest to create a unique description to recognize an object when the defined properties are not sufficient to do so.

Note: When visual relation identifiers are used, the Ordinal identifier option is disabled in the Object Repository Manager or window.

QuickTest can use the following types of ordinal identifiers to identify an object:

Index- Indicates the order in which the object appears in the application code relative to other objects with an otherwise identical description. 

Location- Indicates the order in which the object appears within the parent window, frame, or dialog box relative to other objects with an otherwise identical description. 

CreationTime- (Browser object only.) Indicates the order in which the browser was opened relative to other open browsers with an otherwise identical description.

Smart Identification-

When QuickTest uses the learned description to identify an object, it searches for an object that matches all of the property values in the description. In most cases, this description is the simplest way to identify the object, and, unless the main properties of the object change, this method will work.

If QuickTest is unable to find any object that matches the learned object description, or if it finds more than one object that fits the description, then QuickTest ignores the learned description, and uses the Smart Identification mechanism (if defined and enabled) to try to identify the object.

The Smart Identification dialog box enables you to create and modify the Smart Identification definition that QuickTest uses for a selected test object class. Configuring Smart Identification properties enables you to help QuickTest identify objects in your application, even if some of the properties in the object’s learned description have changed.

The Smart Identification mechanism uses two types of properties:

Base Filter Properties- The most fundamental properties of a particular test object class; those whose values cannot be changed without changing the essence of the original object. For example, if a Web link’s tag was changed from <A> to any other value, you could no longer call it the same object.

Optional Filter Properties- Other properties that can help identify objects of a particular class. These properties are unlikely to change on a regular basis, but can be ignored if they are no longer applicable. 

If QuickTest successfully uses Smart Identification to find an object after no object matches the learned description, the step is assigned a Warning status in the Run Results, and the result details for the step indicate that the Smart Identification mechanism was used.

Smart Identification Process-

If QuickTest activates the Smart Identification mechanism during a run session (because it was unable to identify an object based on its learned description), it follows the following process to identify the object:

1- QuickTest "forgets" the learned test object description and creates a new object candidate list containing the objects (within the object’s parent object) that match all of the properties defined in the Base Filter Properties list.

2- QuickTest filters out any object in the object candidate list that does not match the first property listed in the Optional Filter Properties list. The remaining objects become the new object candidate list.

3- QuickTest evaluates the new object candidate list:

If the new object candidate list still has more than one object, QuickTest uses the new (smaller) object candidate list to repeat step 2 for the next optional filter property in the list.

If the new object candidate list is empty, QuickTest ignores this optional filter property, returns to the previous object candidate list, and repeats step 2 for the next optional filter property in the list.

If the object candidate list contains exactly one object, then QuickTest concludes that it has identified the object and performs the statement containing the object.

4- QuickTest continues the process described in steps 2 and 3 until it either identifies one object, or runs out of optional filter properties to use. If, after completing the Smart Identification elimination process, QuickTest still cannot identify the object, then QuickTest uses the learned description plus the ordinal identifier to identify the object.

If the combined learned description and ordinal identifier are not sufficient to identify the object, then QuickTest stops the run session and displays a Run Error message.


Monday 22 June 2015

Regular expression & methods with Examples

The name regular expression name comes from mathematics where it is defined as
A regular expression is a particular meta-syntax for specifying regular grammars, which has many useful applications.
A regular expression basically is a pattern, describing a String which is processed by some sort of software, which can be called as regular expression engine. The engines processes the regular expression and try to match the pattern to the given string.
* Here, the words/letters in blue denotes a regular expression and green denotes the matches.
Meta-Characters
The opening square bracket [, the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening round bracket ( and the closing round bracket ), these special charaters are often called as Meta-characters. If you need to use any of these characters as a literal in a regular expression, you need to escape them with a backslash else it will be treated as a special character.
e.g. if you have the regular expression as a\+b+c, the first plus sign will be treated as a literal character and the other will have a special meaning.
Single Character
A period (.) matches a single character except the line break character (\n).
e.g. .ired matches Fired, HiredWired etc.
Character Sets
Square bracket ([]) can be used to match a character from a given set. e.g. to match a or i in Fired orFared, we can use F[ia]red.
A hyphen inside the square bracket denotes the range of characters. e.g. [0-9] matches a single digit between 0 to 9. More than one range can be used inside one sqaure bracket like [0-9a-z]
When a caret(^) is the the first character just after the opening bracket ‘[^’, it matches any character except the ones specified in the set.
e.g. q[^x] matches qu in ‘quicktest’.
Repetition
An asterisk(*) matches zero or more occurance of the preceding character.
e.g. Ple*ase matches PleasePleeasePleeeeeeeeeeeeeeeeeaseplase.
A plus sign(+) matches one or more occurance of the preceding character.
e.g. Ple+ase matched PleasePleeasePleeeeeeeeeeeeeeeeease but not plase.
A question mark(?) matches zero or one occurance of the preceding character.
e.g. Ple?ase matches Please or Plase only.
Grouping
We can place parenthesis around multiple tokens to group them together. The containig sequence is treated as a unit.
e.g. QuickTest(Professional)  In this, the string ‘Professional’ is treated as a single unit and we can apply a quantifier to this group if required.
QuickTest(Professional)? matches QuickTest or QuickTestProfessional.
Alternation
a vertical line(|) matches one of the given expression.
e.g. day|night matches day in ‘for so many days and nights’
if the regular expression is applied again it will match night.
Anchors
anchors matches the position.
^ matches at the beginning of the string.
$ matches at the end of the string.
\w matches any alphanumeric character and the underscore.
\W matches any character other than alphanumeric and underscore
\b matches at the start and/or end of the string only for if it is a word character.
\B matches every position where \b cannot match.
Usually these operator are combined into one single expression to match the expected search criteria that we need.
e.g’
[0-9] matches single-digit numbers 0 to 9[1-9][0-9] matches double-digit numbers 10 to 99
^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$ matches a date in yyyy-mm-dd
\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b will match an email address.
More Expressions & Explanation

1>Match any single character (.)
Example: “lear.” will match “learn”, “lear1” or “lear%”

2>Match the preceding character zero or more times (*)
Example: “zo*” matches either “z” or “zoo”.

3>Match any string starting with text specified just before the pattern (.*)
Example: “learn.*” will match any string starting with “learn”. Let us say you encounter a string “We are on learnqtp” but you see that the characters after the string “learn” keeps changing. In such a case you can simple make a regular expression as “We are on learn.*”

4>Match the beginning of a line (^)
Example: “^learnqtp” will match any line that starts with “learnqtp” hence it will match learnqtp, learnqtp.com but not www.learnqtp.com

5>Match the end of a line ($)
Example: “learnqtp$” will match any line that ends with “learnqtp” hence it will match learnqtp, www.learnqtp but not www.learnqtp.com

6>Match the preceding character one or more times (+)
Example: “zo+” matches “zoo” but not “z”.

7>Match the preceding character zero or one time (?)
Example: “a?ve?” matches the “ve” in “never”.


Regexp object:-
                        Regexp object is used to integrate QTP with regular expression utilization. This object consist of 3 properties and 3 methods

A)    Pattern:- we can use this property to store expected expression for matching.
Syntax:-      set r=new regexp
                   r.pattern=”regexp”
                   r.global=true/false
B)  Global:- We can use this property to specify pattern matching on given text until end of text.
Syntax:-       set r=new regexp
                   r.pattern=”regexp”
                   r.global=true/false
c)    Ignorecase:- We can use this property to specify case sensitiveness.

Syntax:-       set r=new regexp
                   r.pattern=”[A-Z][a-z]+”
                   r.global=true
                    r.ignorecase=true

In example code, a string will be matched with pattern which start’s with lowercase also. Because ignorecase is true.

D) Execute( ):- We can use this method to apply given pattern on given text and find matched values in text.

            Ex:-     set r=new regexp
                        r.pattern=”[0-9]+”
                        r.global=true
                       x=”jky345 acd 23 jkil34dd”
                      set y=r.execute(x)
                      for each z in y
                           print(z.value)
                      next
E)Test:- We can use this to apply given pattern on given text for matching. If pattern was matched with matched with text , then this method returns true.

            Ex:-     set r=new regexp
                        r.pattern=”[0-9]+”
                        r.global=true
                        x=”544755”
                        if r.test(x) then
                                    print(“matched”)
                        else
                                    print(“mismatched”)
                        end if
A)    Replace( ):We can use this method to replace matched text with other text.

            Ex:-     set r=new regexp
                        r.pattern=”[0-9]+”
                        r.global=true
                        x=”my name is 5”
                        r.replace(x,”A”)
                        print(x)

Ex:-8 To copy one file text into another file.

                        Option explicit
                        Dim fso,fo,l,fo1,fo2
                        Set fso=createobject(“scripting.filesystemobject”)
                        Set fo1=fso.opentextfile(“c:\sample1.txt”,1,false)
                        Set fo2=fso.opentextfile(“c:\sample2.txt”,2,true)
                        While fo1.atendofstream< >true
                                    l=fo1.readline
                                    fo2.writeline(l)
                        wend
                        fo1.close
                        fo2.close
                        set fo1=nothing
                        set fo2=nothing
                        set fso=nothing

Ex:-9 Write vbscript in qtp , to copy numbers in file1 into file2.
           
                        Option explicit
                        Dim fso,fo1,fo2,l,nums,num
                        Set fso=createobject(“scripting.filesystemobject”)
                        Set fo1=fso.opentextfile(“c:\sample1.txt”,1,false)
                        Set fo2=fso.opentextfile(“c:\sample2.txt”,2,true)
                        While fo1.atendofstream< >true
                                    l=fo1.readline
                                    set r=new regexp
                                    r.pattern=”[0-9]+”
                                    r.global=true
                                    set nums=r.execute(l)
                                    for each num in nums
                                                fo2.writeline(num.value)
                                    next
                                    set numns=nothing
                                    set r=nothing
                        wend
                        fo1.close
                        fo2.close
                        set fo1=nothing
                        set fo2=nothing
                        set fso=nothing


Ex:-10 To copy alphanumeric only from file1 to file2.

Option explicit
Dim fso,fo1,fo2,l,nums,num,r
Set fso=createobject(“scripting.filesystemobject”)
Set fo1=fso.opentextfile(“c:\sample1.txt”,1,false)
Set fo2=fso.opentextfile(“c:\sample2.txt”,2,true)
While fo1.atendofstream< >true
            l=fo1.readline
            set r=new regexp
            r.pattern=”[0-9]+[a-z]+”
            r.global=true
            set nums=r.execute(l)
            for each num in nums
                        fo2.writeline(num.value)
            next
wend
fo1.close
fo2.close
set fo1=nothing
set fo2=nothing
set fso=nothing


Ex:-11  To copy dates in file1 into file2. Here date is “mm/dd/yy”
Option explicit
Dim fso,fo1,fo2,l,nums,num,r
Set fso=createobject(“scripting.filesystemobject”)
Set fo1=fso.opentextfile(“c:\sample1.txt”,1,false)
Set fo2=fso.opentextfile(“c;\sample2.txt”,2,true)
  While fo1.atendofstream< >true
            l=fo1.readline
      set r=new regexp
r.pattern=”(([0][0-9])|([1][0-2]))[/](([0][0-9])|([1][0-9])|([2][0-9])|([3][0-1]))[/][0-9]{2}”
          r.global=true
     set nums=r.execute(l)
         for each num in nums
                   fo2.writeline(num.value)
         next
     set nums=nothing
     set r=nothing
wend
set fo1=nothing
set fo2=nothing
set fso=nothing