What are the various ways of generating Statements in Expert View?
a. Generating Statements in the Expert View or a Function Library
We can generate statements in the following ways:
a. Generating Statements in the Expert View or a Function Library
We can generate statements in the following ways:
- We can use the Step Generator (Insert > Step Generator) to add steps that use methods and functions.
- We can manually insert VBScript statements that use methods to perform operations. QTP includes IntelliSense, a statement completion feature that helps you select the test object (tests only), method, property, or collection (tests only) for your statement and to view the relevant syntax as you type in the Expert View or a function library.
- When you start to type a VBScript keyword in the Expert View or a function library, QTP automatically adds the relevant syntax or blocks to your script, if the Auto-expand VBScript syntax option is enabled.
b. Generating a Statement for an Object
When you type in the Expert View or a function library, IntelliSense (the statement completion feature included with QTP) enables you to select the test object (tests only), method, property, or collection (tests only) for your statement from a drop-down list and view the relevant syntax.
The Statement Completion option is enabled by default. You can disable or enable this option in the Editor Options dialog box.
When the Statement Completion option is enabled:
• If you type an object followed by an open parenthesis (, for example, Page(, QTP displays a list of all test objects of this type in the object repository. If there is only one object of this type in the object repository, QTP automatically enters its name in quotes after the open parenthesis. (Tests only)
• If you type a period after a test object in a statement, QTP displays a list of the relevant test objects (tests only), methods, properties, collections (tests only), and registered functions that you can add after the object you typed.
• If you type the name of a method or property, QTP displays a list of available methods and properties. Pressing CTRL+SPACE automatically completes the word if there is only one option, or highlights the first method or property (alphabetically) that matches the text you typed.
• If you type the name of a method or property, QTP displays the syntax for it, including its mandatory and optional arguments. When you add a step that uses a method or property, you must define a value for each mandatory argument associated with the method or property.
• If you press CTRL+SPACE, QTP displays a list of the relevant test objects (tests only), methods, properties, collections (tests only), VBScript functions, user-defined functions, VBScript constants, and utility objects that you can add. This list is displayed even if you typed an object that has not yet been added to the object repository. If the test contains a function, or is associated with a function library, the functions are also displayed in the list.
• If you use the Object property in your statement, if the object data is currently available in the Active screen (tests only) or the open application, QTP displays native methods and properties of any run-time object in your application.
c. To generate a statement using statement completion in the Expert View or a function library:
1. Confirm that the Statement completion option is selected (Tools > View Options > General tab).
2. Perform one of the following:
o If you are working in a function library, skip to step 4.
o If you are working in the Expert View, type an object followed by an open parenthesis (.

If there is only one object of this type in the object repository, QTP automatically enters its name in quotes after the open parenthesis. If more than one object of this type exists in the object repository, QTP displays them in a list.

3. Double-click an object in the list or use the arrow keys to choose an object and press ENTER. QTP inserts the object into the statement.
4. Perform one of the following:
o If you are working in the Expert View, type a period (.) after the object on which you want to perform the method.

o If you are working in a function library, type the full hierarchy of an object, for example:
Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury).WebEdit("username").
5. Type a period (.) after the object description, for example ("username"). QTP displays a list of the available methods and properties for the object.
Tip: You can press CTRL+Space or choose Edit > Advanced > Complete Word after a period, or after you have begun to type a method or property name. QTP automatically completes the method or property name if only one method or property matches the text you typed. If more than one method or property matches the text, the first method or property (alphabetically) that matches the text you typed is highlighted.
6. Double-click a method or property in the list or use the arrow keys to choose a method or property and press ENTER. QTP inserts the method or property into the statement. If the method or property contains arguments, QTP displays the syntax of the method or property in a tooltip, as shown in this example from the Expert View.
In the above example, the Set method has one argument, called Text. The argument name represents the text to insert in the box.
Tip: You can also place the cursor on any method or function that contains arguments and press CTRL+SHIFT+SPACE or choose Edit > Advanced > Argument Info to display the statement completion (argument syntax) tooltip for that item.
7. Enter the method arguments after the method according to the displayed syntax.
Note: After you have added a step in the Expert View, you can view the new step in the Keyword View. If the statement that you added in the Expert View contains syntax errors, QTP displays the errors in the Information pane when you select the Keyword View.
Automatically Completing VBScript Syntax
When the Auto-expand VBScript syntax option is enabled and you start to type a VBScript keyword in the Expert View or a function library, QTP automatically recognizes the first two characters of the keyword and adds the relevant VBScript syntax or blocks to the script. For example, if you enter the letters if and then enter a space at the beginning of a line, QTP automatically enters:
If Then
End If
The Auto-expand VBScript syntax option is enabled by default. You can disable or enable this option in the Editor Options dialog box.
If you enter two characters that are the initial characters of multiple keywords, the Select a Keyword dialog box is displayed and you can select the keyword you want. For example, if you enter the letters pr and then enter a space, the Select a Keyword dialog box opens containing the keywords private and property.

You can then select a keyword from the list and click OK. QTP automatically enters the relevant VBScript syntax or block in the script.
When you type in the Expert View or a function library, IntelliSense (the statement completion feature included with QTP) enables you to select the test object (tests only), method, property, or collection (tests only) for your statement from a drop-down list and view the relevant syntax.
The Statement Completion option is enabled by default. You can disable or enable this option in the Editor Options dialog box.
When the Statement Completion option is enabled:
• If you type an object followed by an open parenthesis (, for example, Page(, QTP displays a list of all test objects of this type in the object repository. If there is only one object of this type in the object repository, QTP automatically enters its name in quotes after the open parenthesis. (Tests only)
• If you type a period after a test object in a statement, QTP displays a list of the relevant test objects (tests only), methods, properties, collections (tests only), and registered functions that you can add after the object you typed.
• If you type the name of a method or property, QTP displays a list of available methods and properties. Pressing CTRL+SPACE automatically completes the word if there is only one option, or highlights the first method or property (alphabetically) that matches the text you typed.
• If you type the name of a method or property, QTP displays the syntax for it, including its mandatory and optional arguments. When you add a step that uses a method or property, you must define a value for each mandatory argument associated with the method or property.
• If you press CTRL+SPACE, QTP displays a list of the relevant test objects (tests only), methods, properties, collections (tests only), VBScript functions, user-defined functions, VBScript constants, and utility objects that you can add. This list is displayed even if you typed an object that has not yet been added to the object repository. If the test contains a function, or is associated with a function library, the functions are also displayed in the list.
• If you use the Object property in your statement, if the object data is currently available in the Active screen (tests only) or the open application, QTP displays native methods and properties of any run-time object in your application.
c. To generate a statement using statement completion in the Expert View or a function library:
1. Confirm that the Statement completion option is selected (Tools > View Options > General tab).
2. Perform one of the following:
o If you are working in a function library, skip to step 4.
o If you are working in the Expert View, type an object followed by an open parenthesis (.

If there is only one object of this type in the object repository, QTP automatically enters its name in quotes after the open parenthesis. If more than one object of this type exists in the object repository, QTP displays them in a list.

3. Double-click an object in the list or use the arrow keys to choose an object and press ENTER. QTP inserts the object into the statement.
4. Perform one of the following:
o If you are working in the Expert View, type a period (.) after the object on which you want to perform the method.

o If you are working in a function library, type the full hierarchy of an object, for example:
Browser("Welcome: Mercury Tours").Page("Book a Flight: Mercury).WebEdit("username").
5. Type a period (.) after the object description, for example ("username"). QTP displays a list of the available methods and properties for the object.
Tip: You can press CTRL+Space or choose Edit > Advanced > Complete Word after a period, or after you have begun to type a method or property name. QTP automatically completes the method or property name if only one method or property matches the text you typed. If more than one method or property matches the text, the first method or property (alphabetically) that matches the text you typed is highlighted.6. Double-click a method or property in the list or use the arrow keys to choose a method or property and press ENTER. QTP inserts the method or property into the statement. If the method or property contains arguments, QTP displays the syntax of the method or property in a tooltip, as shown in this example from the Expert View.
In the above example, the Set method has one argument, called Text. The argument name represents the text to insert in the box.Tip: You can also place the cursor on any method or function that contains arguments and press CTRL+SHIFT+SPACE or choose Edit > Advanced > Argument Info to display the statement completion (argument syntax) tooltip for that item.
7. Enter the method arguments after the method according to the displayed syntax.
Note: After you have added a step in the Expert View, you can view the new step in the Keyword View. If the statement that you added in the Expert View contains syntax errors, QTP displays the errors in the Information pane when you select the Keyword View. Automatically Completing VBScript Syntax
When the Auto-expand VBScript syntax option is enabled and you start to type a VBScript keyword in the Expert View or a function library, QTP automatically recognizes the first two characters of the keyword and adds the relevant VBScript syntax or blocks to the script. For example, if you enter the letters if and then enter a space at the beginning of a line, QTP automatically enters:
If Then
End If
The Auto-expand VBScript syntax option is enabled by default. You can disable or enable this option in the Editor Options dialog box.
If you enter two characters that are the initial characters of multiple keywords, the Select a Keyword dialog box is displayed and you can select the keyword you want. For example, if you enter the letters pr and then enter a space, the Select a Keyword dialog box opens containing the keywords private and property.

No comments:
Post a Comment