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.

Saturday, 6 February 2021

SAPGuiSession Methods

Close Method : -  Close method to close an SAP GUI for Windows session without displaying a warning message.

Example: - 

SAPGuiSession("Session").Close

CreateSession Method: - Creates a new SAP GUI for Windows session for the current connection.

Example:
SAPGuiSession("Session").CreateSession
SAPGuiSession("Session_2").SAPGuiWindow("SAP Easy Access").Resize 136, 23
Note: CreateSession method to create a new SAP GUI for Windows session and then resizes the new window
Reset Method: - Navigates to the sessions initial screen or to the specified transaction.
Example:
SAPGuiSession("Session").Reset
SAPGuiSession("Session").Reset "/nVA01"
Sync Method: - Sync method Instructs UFT to wait until the SAP GUI for Windows session is available.
Example:
SAPGuiSession("Session").SAPGuiWindow("SAP Easy Access").SAPGuiOKCode("OKCode").Set"sbwp"
SAPGuiSession("Session").SAPGuiWindow("SAP Easy Access").SendKey ENTER
SAPGuiSession("Session").SAPGuiWindow("Business Workplace").SAPGuiButton("New message").Click
SAPGuiSession("Session_2").Sync
Note: Sync method to ensure that a second SAP GUI for Windows session (opened by pressing
'the "New message" button) is loaded before performing operations on it.
GetItem Method:- Returns the value of the item specified by the index.
Example- 
SAPGuiSession("Session").SAPGuiWindow("Create Material").SAPGuiComboBox("Industry sector")._
Select "Food and Related Products"
SAPGuiSession("Session").SAPGuiWindow("Create Material").SAPGuiComboBox("Industry sector").SetFocus
relatedItem = SAPGuiSession("Session").SAPGuiWindow("Create Material").SAPGuiComboBox("Material type").GetItem(10)
If relatedItem = "Finished product" Then
    MsgBox "The Material type comboBox has the correct value in it"
End If
Note: - GetItem method to check that when the "Food and Related Products" option is selected in the 
"Industry sector" combo box, that the tenth item ("Finished product") is displayed in 
the "Material type" combo box.
Select Method: - Selects an item from the combo box list.
Example:
SAPGuiSession("Session").SAPGuiWindow("Create Material").SAPGuiComboBox("Industry sector")._
Select "Food and Related Products"
SAPGuiSession("Session").SAPGuiWindow("Create Material").SAPGuiComboBox("Material type").Select "#4"
SAPGuiSession("Session").SAPGuiWindow("Create Material").SAPGuiComboBox("Material type").SetFocus
SAPGuiSession("Session").SAPGuiWindow("Create Material").SAPGuiButton("Select view(s)").Click
Note: Select method to select the "Food and Related Products" option from the "Industry sector"
combo box and the fourth option from the "Material type" combo box. Then it clicks the
"Select view(s)" button.
SelectKey Method: - Selects the SAP (shortcut) key representing an item in the combo box list.
Example:
SAPGuiSession("Session").SAPGuiWindow("EnjoySAP Demo").SAPGuiTree("TableTreeControl")._
ActivateItem "Workbench Demos;USER INTERFACE;Examples of User Interface Design", "REPTITLE"
SAPGuiSession("Session").SAPGuiWindow("User Interface").SAPGuiMenuBar("mbar").Select "Elements;Dropdown list box"
SAPGuiSession("Session").SAPGuiWindow("User Interface").SAPGuiComboBox("Country").SelectKey "AG"
SAPGuiSession("Session").SAPGuiWindow("User Interface").SAPGuiComboBox("Language").SetFocus
SAPGuiSession("Session").SAPGuiWindow("User Interface").SAPGuiButton("Next screen").Click
Note:-SelectKey method to select the "AG" key from the "Country" box.
SetFocus Method: - Sets the focus on a combo box object in an SAP GUI for Windows application.
Example:
SAPGuiSession("Session").SAPGuiWindow("CPurchase").SAPGuiTextArea("TAControl").Set"This is an editor"
SAPGuiSession("Session").SAPGuiWindow("CPurchase").SAPGuiComboBox("MTEXT-EDITOR").SetFocus
SAPGuiSession("Session").SAPGuiWindow("CPurchase").SAPGuiComboBox("MTEXT-EDITOR").Select"Line editor"

Note: SetFocus method to ensure that the "MEPOTEXT-EDITOR" combo box is in focus before
the "Select" operation is performed.

DoubleClick Method: -Double-clicks inside a text area at the cursor position.

Example: 
SAPGuiSession("Session").SAPGuiWindow("ABAPEditor:").SAPGuiTextArea("TAControl").SetSelectionIndexes 710, 710
SAPGuiSession("Session").SAPGuiWindow("ABAPEditor:").SAPGuiTextArea("TAreaControl").DoubleClick
Note: DoubleClick method to double-click the cursor inside a text area at the position (710,710).

SetSelectionIndexes Method: - Selects the specified section of text in the text area and positions the cursor.

Syntax : object.SetSelectionIndexes (Start, End)

Note: The text is selected from the specified start character and up to, but not including, the end character.
SAPGuiSession("Session").SAPGuiWindow("EnjoySAP Demo").SAPGuiTextArea("TAControl").Set ""+vbCr+"HELLO"+vbCr+""
SAPGuiSession("Session").SAPGuiWindow("EnjoySAP Demo").SAPGuiTextArea("TextAreaControl").SetSelectionIndexes 1,4
Note: SetSelectionIndexes method to highlight the three letters ELL (positions 1, 2 and 3) in the string 
HELLO and position the cursor on the character at position 4 (The letter "O"), which is not highlighted.
SAPGuiSession("Session").SAPGuiWindow("EnjoySAP Demo").SAPGuiTextArea("TextAreaControl").Set ""+vbCr+"HELLO"+vbCr+""
SAPGuiSession("Session").SAPGuiWindow("EnjoySAP Demo").SAPGuiTextArea("TextAreaControl").SetSelectionIndexes 5, 5
Note: SetSelectionIndexes method to position the cursor immediately after the string HELLO in the text area (on character 5).

SetUnprotectedTextPart Method: - Sets the specified text in the predefined unprotected sections of the text area.

Syntax: object.SetUnprotectedTextPart (Part, Text)
SAPGuiSession("Session").SAPGuiWindow("Mer").SAPGuiTextArea("TA").SetUnprotectedTextPart 1,"Purchase Order"+vbCr+""
SAPGuiSession("Session").SAPGuiWindow("Mer").SAPGuiTextArea("TA").SetUnprotectedTextPart 2,"Order Number 5678"+vbCr+""
SAPGuiSession("Session").SAPGuiWindow("Mer").SAPGuiTextArea("TA").SetUnprotectedTextPart 3,"Authorized"+vbCr+ ""
Note: SetUnprotectedTextPart method to type the text Purchase Order, Order Number 5678 
and Authorized in the unprotected sections of the "TextAreaControl" text area. The three text strings are entered
into sections 1, 2, and 3 respectively, starting from the top of the text area.