qtp scripting work a rounds sap

64
QuickTest Professional (QTP) QuickTest Professional (QTP) workarounds workarounds When recording, there are certain clicks which are not correctly recorded by QTP. In those cases, we have to manually add workarounds. In the first part, this document will guide you through the process of inserting appropiate workarounds. The second part of this document deals with various techniques of creating more complex scenarios while the last part is about common errors in the process of scripting with QTP. The newest versions of this document and the template are always available here: \\dwdf029\AP\public\Product_Standard_Workfolder\ Product_standard_coordinators\Performance\Automated test\Documentation + Template Classic workarounds: Workcenter errors (updated 20080926) Changing workcenter names (updated 20080926) Handling drop down menus (updated 20080926) Handling drop down buttons Handling tabs Hitting “Enter” in text fields Opening a new window Clicking on dynamic text labels Dynamically changing window title Collapsing calendar buttons Auto suggestion text fields Recording a click on a view (new 20080926) Superfluous Script Lines (new 20080926)

Upload: handsomeabhi2006

Post on 10-Apr-2015

1.844 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: QTP Scripting Work a Rounds SAP

QuickTest Professional (QTP)QuickTest Professional (QTP)

workaroundsworkarounds

When recording, there are certain clicks which are not correctly recorded by QTP. In those cases, we have to manually add workarounds. In the first part, this document will guide you through the process of inserting appropiate workarounds.

The second part of this document deals with various techniques of creating more complex scenarios while the last part is about common errors in the process of scripting with QTP.

The newest versions of this document and the template are always available here:\\dwdf029\AP\public\Product_Standard_Workfolder\Product_standard_coordinators\Performance\Automated test\Documentation + Template

Classic workarounds:

Workcenter errors (updated 20080926)

Changing workcenter names (updated 20080926)

Handling drop down menus (updated 20080926)

Handling drop down buttons

Handling tabs

Hitting “Enter” in text fields

Opening a new window

Clicking on dynamic text labels

Dynamically changing window title

Collapsing calendar buttons

Auto suggestion text fields

Recording a click on a view (new 20080926)

Superfluous Script Lines (new 20080926)

Advanced techniques:

Setting output values

Parameterizing values

Setting checkpoints

Defining a global variable as a counter

31st June, 2008Le-Huan Stefan Tran

26th September, 2008Rudolf Meier

Page 2: QTP Scripting Work a Rounds SAP

Setting up FUSE in a new action

Passing parameters to a nested action

Errors:

Search error “No records found”

Create “New Sales Order” error

Error running the “Test Batch Runner”

Error using FUSE

Error setting output values

Not working clicks on buttons

2

Page 3: QTP Scripting Work a Rounds SAP

Workcenter errorsWorkcenter errors

Problem: When recording the script

o a wrong workcenter is selected oro the workcenter to be selected is hidden.

Solution:

To ensure that the correct workcenter is selected: When recording, click on the label of the workcenterImportant: Do not click on the image of the workcenter.

Info: The click is now correctly recorded and named by QTP according to the workcenter.

To record a click on a workcenter that is not visible on the initial screen: When recording, navigate to the workcenter using the single arrow button, then click on the label of the work center. QTP will also record the arrow-clicks, they can be removed from the script. See next screen shot.

3

Page 4: QTP Scripting Work a Rounds SAP

4

Page 5: QTP Scripting Work a Rounds SAP

Changing workcenter namesChanging workcenter names

Note added 26-September 2008: This workaround is still valid. However, I have not been able to find abbreviated work center names, so this workaround might be obsolete.

Line of action: Info: Long workcenter names can be displayed in several ways, so QTP could

get confused.For example: “Product and Service Po…” or “Product and Service Portfolio”

Script your scenario: In QTP, record your scenario as usual – including the click on the problematic

workcenter Change the view to “Expert View” Choose the right action with the click on the workcenter

5

Page 6: QTP Scripting Work a Rounds SAP

Open the Object Repository: Menu: Resources \ Object Repository… Expand the nodes to find the desired workcenter in the tree diagram Info: Usually, the desired item is a “WebElement”.

Click on the item Click on the cell of the property “innertext” to modify the value

Insert a regular expression: Click on the button with the symbol <#> Check “Regular expression” Hit “Yes” to treat special characters literally Replace the changing / dynamic part of the text with the wildcard “.+”

6

Page 7: QTP Scripting Work a Rounds SAP

For example: The last part of the name of the workcenter “Product and Service Po…” is dynamic.Change it to: “Product and Service .+”

Hit “OK”

Note: There are various other regular expressions featured by VBScript. Please refer to http://www.aspheute.com/artikel/20000829.htm

Info: The value of the property “Name” is not important for QTP to recognize the workcenter. It is just a unique identifier.So we do not need to insert a regular expression there.

Finished: Now, once long workcenter names have become harmless, we can concentrate

on scripting!

7

Page 8: QTP Scripting Work a Rounds SAP

Handling drop down menusHandling drop down menus

Line of action: Info: QTP has massive problems of handling drop down menus. Info: You have to add those steps manually.

Requirements: In QTP, choose the “Expert View” Choose the right action Delete any lines with a reference to the drop down menu – usually this is the

code line with the click on the “WebButton”

1st step – Navigate to the drop down menu: Start the Internet Explorer and log on Navigate to the page with the drop down menu

8

Page 9: QTP Scripting Work a Rounds SAP

Choose the code line to insert the step: In QTP, choose the “Expert View” Choose the right action Click into the right code line where you want to insert the click on the drop

down menuInfo: To make it clearer, the code line should be an empty line.

Use the “Step Generator”:

9

Page 10: QTP Scripting Work a Rounds SAP

Menu: Insert \ Step Generator… or hit “F7” Click on the button with the colorful cube Change the active window to the Internet Explorer Change the active window back to QTP Click on the button with the outstretched index finger Info: The active window will automatically changed to the Internet Explorer. Now click on the text field of the drop down menu

Important: Do not click on the arrow button.

Make sure that the tree diagram shows the correct field – usually “WebEdit” Hit “OK” Important: Make sure that the “Operation:” is set to “Click” Hit “OK”

2nd step – Navigate to the item (first possibility): Click on the text field to expand the drop down menu Move your mouse cursor several times up and down over the entries of

the drop down menu Move your mouse cursor over the entry you want to select Info: Now, the drop down menu will not collapse when you change the focus to

QTP. For some drop down menus this procedure for keeping the list open when changing focus to QTP does not work. If this is the case, use the second possibility below.

2nd step – Navigate to the item (second possibility): In the QTP script, place the curser on an empty line below the command

entered before when using the step generator. Switch on recording. Record opening the drop down list and selection of the

correct entry. Note that this is not recorded in an executable way by QTP. We just use the lines produced by QTP to keep the list open. Note that the lines produced by this recording have to be removed again later.

10

Page 11: QTP Scripting Work a Rounds SAP

Now close browser windows and FUSE, and execute the script. It will proceed to the point where the entry in the drop down list is supposed to be selected. It will hang at this point as it cannot execute this step. Stop the execution.

Now the drop down is displayed and does not collapse when focus is set to the QTP window and we can proceed.

Remove the lines which were entered by the recording above.

Choose the code line to insert the step: In QTP, click into the right code line where you want to insert the click on the

itemInfo: To make it clearer, the code line should be an empty line.Info: The code line before should be the click to expand the menu.

Use the “Step Generator”: Menu: Insert \ Step Generator… or hit “F7” Click on the button with the colorful cube Change the active window to the Internet Explorer Change the active window back to QTP Click on the button with the outstretched index finger Info: The active window will automatically changed to the Internet Explorer. Now click on the desired item of the drop down menu

Make sure that the tree diagram shows the correct item Hit “OK” Make sure that the “Operation:” is set to “Click” Hit “OK”

11

Page 12: QTP Scripting Work a Rounds SAP

Optional: Insert measurement: When you would like to measure the step with the command “Enter”, you have

to take care of inserting the commands of FUSE properly. Insert the code lines to start FUSE before the two code lines with the

workaround. Insert the code lines to stop FUSE after the two code lines with the

workaround. The workaround to hit “Enter” is now completely surrounded by the commands

of FUSE.

Finished: Info: The drop down menu is now correctly handled.

12

Page 13: QTP Scripting Work a Rounds SAP

Handling drop down buttonsHandling drop down buttons

Line of action: Info: QTP does not record the step when clicking on a item of a drop down

button. Info: You have to add this step manually.

Requirements: In QTP, choose the “Expert View” Choose the right action Make sure that the click to expand the drop down button has been recorded

correctly

Locate the button in the Object Repository: Menu: Resources \ Object Repository… Expand the nodes to find the item of the drop down button

Usually, you have to expand the browser, the page and the frame to find the item “link”.For example: Expand “Home - SAP Business ByDesign”, “Home - SAP Business ByDesign”, “contentAreaFrame” to find the link “Follow-up”.

13

Page 14: QTP Scripting Work a Rounds SAP

Define a new test object: Click on the frame “contentAreaFrame” Menu: Object \ Define New Test Object… Set the “Environment” to “Web” Set the “Class” to “WebElement” Set the “Name” to the name of the item you want to click after you expanded

the drop down buttonFor example: “Phone Call”

Set the “innertext” to the name of the item, too Set the “html tag” to “SPAN” Hit “Add” Important: Make sure the new item is placed as an element of the frame

“contentAreaFrame”. Info: The desired item of the drop down button has been added to the Object

Repository of QTP.

14

Page 15: QTP Scripting Work a Rounds SAP

Choose the code line to insert the step: In QTP, choose the “Expert View” Choose the right action Click into the right code line where you want to insert the click on the item of

the drop down button Info: To make it clearer, the code line should be an empty line. Info: The code line before should be the click to expand the button.

Use the “Step Generator”: Menu: Insert \ Step Generator… or hit “F7” Click on the button with the colorful cube Expand the nodes to find your just created item

15

Page 16: QTP Scripting Work a Rounds SAP

For example: Expand the nodes browser “Home – SAP Business ByDesign”, the page “Home – SAP Business ByDesign”, the frame “contentAreaFrame” and click on the web element “Phone Call”

Hit “OK” Set the “Operation:” to “Drag” Hit “OK”

Insert second drag and final drop command and a wait: Copy the just inserted code line Paste it into the next line Paste it again into the next line Edit manually the command “Drag” of the last just pasted code line to “Drop” Info: You should now have two lines with “Drag” and one with “Drop”.

16

Page 17: QTP Scripting Work a Rounds SAP

Optional: Insert measurement: When you would like to measure the step with the command “Enter”, you have

to take care of inserting the commands of FUSE properly. Insert the code lines to start FUSE before the three code lines with the

commands “Click”, “Drag” and “Drop”. Insert the code lines to stop FUSE after the three code with the commands

“Click”, “Drag” and “Drop”. The workaround to choose an item of the drop down button is now completely

surrounded by the commands of FUSE.

Error – “Duplicate names”: Info: The problem could arise that there are other entries with a similar text

like the entry of the drop down button you want to click on. Info: QTP will throw an exception “Duplicate names” Info: You need to specify the position of the desired

In QTP, menu: Resources \ Object Repository… Expand the nodes to find the just created entry of the drop down button

Usually, you have to expand the browser, the page and the frame. Click on the item Click on the cell “Value” of the property “Type, Value” Click on the button with the three dots

Set “Identifier type:” to “Location” Set “Identifier value:” to the position of the desired entry in the drop down

menuInfo: Counting starts with 0. For example, for the first entry set 0.

Hit “OK”

17

Page 18: QTP Scripting Work a Rounds SAP

Finished: Info: The drop down button is now correctly handled.

18

Page 19: QTP Scripting Work a Rounds SAP

Handling tabsHandling tabs

Line of action: Info: QTP does not record the step when clicking on a tab. Info: You have to add this step manually.

Navigate to the tab: Start the Internet Explorer and log on Navigate to the page with the tab Important: The desired tab should not have been clicked on yet, i.e. the tab

should not be activated yet.

Choose the code line to insert the step: In QTP, choose the “Expert View” Choose the right action Click into the right code line where you want to insert the click on the tab

Info: To make it clearer, the code line should be an empty line.

19

Page 20: QTP Scripting Work a Rounds SAP

Use the “Step Generator”: Menu: Insert \ Step Generator… or hit “F7” Click on the button with the colorful cube Change the active window to the Internet Explorer Change the active window back to QTP Click on the button with the outstretched index finger Info: The active window will automatically changed to the Internet Explorer. Now click on the desired tab Important: The desired tab should not have been clicked on yet, i.e. the tab

should not be activated yet.

Make sure that the tree diagram shows the correct tab Hit “OK” Make sure that the “Operation:” is set to “Click” Hit “OK”

20

Page 21: QTP Scripting Work a Rounds SAP

Finished: Info: The code line with click on the tab has just been correctly inserted.

21

Page 22: QTP Scripting Work a Rounds SAP

Hitting “Enter” in text fieldsHitting “Enter” in text fields

Line of action: Info: We enter a value into a text field of a search mask. To submit the value,

we hit “Enter”. Info: When running the script, the “Enter” command is not working.

Choose the submit command: In QTP, choose the “Expert View” Choose the right action Mark the right code line where you submit the value of the text field Delete this code line

22

Page 23: QTP Scripting Work a Rounds SAP

Insert workaround: Copy and paste the following code lines Modify the parameters in the brackets <…>

Set WshShell = CreateObject("WScript.Shell")wait(Wait_BeforeAction)Browser(<modify>).Page(<modify>).Frame(<modify>).WebEdit(<modify>).Click WshShell.SendKeys "{ENTER}"wait(Wait_AfterAction)Set WshShell = Nothing

Optional: Insert measurement: When you would like to measure the step with the command “Enter”, you have

to take care of inserting the commands of FUSE properly. Insert the code lines to start FUSE before the whole code block with the

workaround. Insert the code lines to stop FUSE after the whole code block with the

workaround. The workaround to hit “Enter” is now completely surrounded by the commands

of FUSE.

23

Page 24: QTP Scripting Work a Rounds SAP

Finished: Info: The submit command via “Enter” should now be appropiately executed.

24

Page 25: QTP Scripting Work a Rounds SAP

Opening a new windowOpening a new window

Line of action: Info: There are situations where a click opens a new window. You want to

record clicks performed on the new window. Info: Because QTP often gets confused concerning several windows, we need

to create a new nested action.

Record to the critical step: Record your scenario to the step when you want to open a new window Perform the step to open the new window In QTP, click on the right code line after the just recorded step

Info: To make it clearer, the code line should be an empty line.

Insert a new nested action: Menu: Insert \ Call to New Action… Set a proper name

For example: 02a_NewWindow Set the “Location:” to “After the current step” Hit “OK” Info: In the new action, you can record all clicks performed on the new window.

The action will be called just after the step opening the new window. The active action is now the just created action.

Record steps on the new window: Now proceed with recording all steps on the new window in this action When you have finished, choose your old action to proceed with your scenario

Optional: Set up FUSE: Note: When you would like to measure a step in the new window with FUSE,

you need to add the buttons of FUSE to the Object Repository of QTP.

25

Page 26: QTP Scripting Work a Rounds SAP

Please refer to the workaround Set up FUSE in a new action in this document.

The buttons of FUSE can now be correctly recognized by QTP. Just add the start and stop commands of FUSE as usual.

Optional: Opening another window from within the new window: Note: When you would like to open a third window from within the second

window, create a new nested action in your just created nested action. Follow the steps analogue to opening a new window

26

Page 27: QTP Scripting Work a Rounds SAP

Clicking on dynamic text labelsClicking on dynamic text labels

Line of action: Info: You want to click on a text labels whose text is partly changing. Info: You have to use regular expressions to make QTP dynamically

recognize the text label.

Record your scenario: In QTP, record your scenario as usual – including the click on the text label

Open the Object Repository: Menu: Resources \ Object Repository… Expand the nodes to find the desired text label in the tree diagram Click on the text label Click on the cell with the desired text to prepare for modifying the text

27

Page 28: QTP Scripting Work a Rounds SAP

Insert a regular expression: Click on the button with the symbol <#> Check “Regular expression” Hit “Yes” to treat special characters literally Replace the changing / dynamic part of the text with the wildcard “.+”

For example: The value in brackets of the text label “Today’s Quotes (2)” is dynamic.Change it to: “Today’s Quotes (.+)”

Note: There are various other regular expressions featured by VBScript. Please refer to http://www.aspheute.com/artikel/20000829.htm

28

Page 29: QTP Scripting Work a Rounds SAP

Finished: The dynamically changing text label is appropiately handled.

29

Page 30: QTP Scripting Work a Rounds SAP

Dynamically changing window titleDynamically changing window title

Line of action: Info: You have a window whose title is dynamically changing. To perform a step

on the window, you need to insert a regular expression to make QTP work properly.

For example: “Sales Order Overview: 8036” could change to “Sales Order Overview: 8037”; you want to click on close.

Record your script and find the button in the Object Repository: In QTP, record your script as usual.

Choose the “Expert View” Choose the right action where the problematic window is used Menu: Resources \ Object Repository… Expand the nodes to find the desired button in the tree diagram

30

Page 31: QTP Scripting Work a Rounds SAP

1st step: Add the property “title” to the “Page” object: Choose the “Page” belonging to the button Click on the button with the green “+” Choose the property “title” Hit “OK”

Insert a regular expression: Click on the cell with the desired text to prepare for modifying the text Click on the button with the symbol <#> Check “Regular expression” Hit “Yes” to treat special characters literally Replace the changing / dynamic part of the text with the wildcard “.+”

31

Page 32: QTP Scripting Work a Rounds SAP

For example: The value of the text label “Sales Order Overview: 8036 - SAP Business ByDesign” is dynamic.Change it to: “Sales Order Overview: .+ - SAP Business ByDesign”

Note: There are various other regular expressions featured by VBScript. Please refer to http://www.aspheute.com/artikel/20000829.htm

2st step: Add the property “title” to the “Browser” object: Choose the “Browser” belonging to the button Click on the button with the green “+” Choose the property “title” Hit “OK”

Insert a regular expression: Click on the cell with the desired text to prepare for modifying the text Click on the button with the symbol <#> Check “Regular expression” Hit “Yes” to treat special characters literally Replace the changing / dynamic part of the text with the wildcard “.+”

For example: The value of the text label “Sales Order Overview: 8036 - SAP Business ByDesign” is dynamic.Change it to: “Sales Order Overview: .+ - SAP Business ByDesign”

Finished: The dynamically changing window title is now correctly handled.

32

Page 33: QTP Scripting Work a Rounds SAP

Collapsing calendar buttonsCollapsing calendar buttons

Line of action: Info: Clicking on a calendar button to open a calendar as well as choosing a

specific month and a day are very problematic.

Record your script and look for the problematic step: In QTP, record your script as usual including the step when clicking on the

calendar button to open the calendar.

Choose the “Expert View” Choose the right action where the problematic calendar button is clicked on Find the line with the problematic click

33

Page 34: QTP Scripting Work a Rounds SAP

Insert commands “Drag” and “Drop”: Copy and paste the line three times into the next lines Change the command “Click” of the first and third code line to “Drag” Change the command “Click” of the second and forth code line to “Drop”

Update Active Screen: Menu: Automation \ Update Run Mode Rightclick into the code line with the first command “Drag” and choose “Run

form Step” Important: Make sure the Internet Explorer is still showing the page with the

calendar button. Important: Make sure the option “Update Active Screen images and values” is

checked. Hit “OK” to run the four code lines

Use the “Step Generator”: In QTP, click into the code line with the second command “Drop” In the active screen, scroll the view to make the expanded calendar visible

Rightclick on the item you want QTP to click on Choose “Step Generator…” Hit “OK” Make sure that the tree diagram shows the correct field – usually

“WebElement” Important: Make sure the “Operation:” is set to “Click” Hit “OK”

34

Page 35: QTP Scripting Work a Rounds SAP

Clicking on further items of the calendar: Insert the extra commands “Drag” and “Drop” and run the steps with the

option updating the active screen activated Work with the active screen and the step generator to insert your desired step

Clean up code: Delete the code lines with the second command “Drag” and the second

command “Drop”

Finished:

35

Page 36: QTP Scripting Work a Rounds SAP

Info: You have just gained the ability to conquer annoying calendar buttons. Level up!!111einself ^^

36

Page 37: QTP Scripting Work a Rounds SAP

Auto suggestion text fieldsAuto suggestion text fields

Line of action: Info: Typing text in a text fields with the feature “auto suggestion” is

problematic.

Delete not working steps: In QTP, choose the “Expert View” Choose the right action Delete the code lines with the commands of entering text or hitting “Enter”

Insert workaround: Insert the following code lines

Set WshShell = CreateObject("WScript.Shell") ' Enter (for search form)wait(Wait_BeforeAction)Browser("New Invoice - SAP Business").Page("New Invoice - SAP Business").Frame("Web Dynpro Innerpage_2").WebEdit("WebEdit").ClickWshShell.SendKeys "<enter text to be typed in>"wait(5)WshShell.SendKeys "{ENTER}"wait(Wait_AfterAction)Set WshShell = Nothing

The step with the “click” on the “WebEdit” has to be manually recorded with the “Step Generator” – cf. “Use the “Step Generator”” of the chapter Handling tabs

Replace the brackets “<…>” with your desired text to be typed in into the text field

Important: You should use only a maximum of four characters.Otherwise, the auto suggestion feature will turn on and ignore all following “Send Keys” commands.

Note 20080917: This is no longer true for GFP, use complete name!

Info: With typing in four characters the auto suggestion feature should suggest your desired entry at the top, so “Enter” will automatically choose the entry.

If not, you can make use of the abbreviation of each entry. Replace the brackets “<…>” with the abbreviation instead.

37

Page 38: QTP Scripting Work a Rounds SAP

Finished: Info: Thank you, thank you, thank you – you’re far too kind! This is finally my

last official act – see you in six months!

38

Page 39: QTP Scripting Work a Rounds SAP

Recording a click on a viewRecording a click on a view

Problem: When running the script

o The click on a view is not executed

Solution:

Record the click using the step generator

Info: The click is now correctly recorded and executed by QTP.

Use the “Step Generator”: Menu: Insert \ Step Generator… or hit “F7” Click on the button with the colorful cube Change the active window to the Internet Explorer Change the active window back to QTP Click on the button with the outstretched index finger Info: The active window will automatically changed to the Internet Explorer. Now click on the desired view.

Make sure that the “Operation:” is set to “Click” Hit “OK”

39

Page 40: QTP Scripting Work a Rounds SAP

Superfluous Script LinesSuperfluous Script Lines

Information:

Some Script Lines are created by QTP which are not needed and can be removed. In particular, this is true for the following line types:

…. WebButton("Submit Query").Click

(can always be removed)

…. WinStatusBar("msctls_statusbar32").Click

(can be removed unless explicitly needed for workaround)

Examples are given in the following screen shot.

40

Page 41: QTP Scripting Work a Rounds SAP

Setting output valuesSetting output values

Line of action: Info: You need to save a value displayed on the screen. Info: Later on, you can use to saved value by inserting it in text fields - cf. the

workaround “Parameterizing values”.

Mark the desired text to save: In QTP, choose the “Expert View” Choose the right action Click into the right code line with the active screen showing the value to save Mark the desired value in the active screen

Insert a text output: Rightclick on the mark and choose “Insert Text Output…”

Important: Do not choose “Insert Output Value…”. Change the “Name:” following the naming convention:

Output_<name of value> Set “Insert statement” to “Before current step”

Click on “Modify…” Change the “Name” following the naming convention:

Value_<name of value> Set “Output Types” to “DataTable” Set “Location in Data Table” to “Global sheet” Hit “OK” two times

41

Page 42: QTP Scripting Work a Rounds SAP

Finished: Info: The marked value will be saved in the global data table of QTP. Info: It can be accessed via parameterzing another value - cf. the workaround

“Parameterizing values”.

42

Page 43: QTP Scripting Work a Rounds SAP

Parameterizing valuesParameterizing values

Line of action: Info: In your script, you have manually entered a specific value into a text field

or a edit box. Now you want to use a dynamic value of the global data table of QTP instead.Example: You want to search for a Sales Order whose ID you have saved before.

Requirements: Info: First of all, it is necessary to set an output value – cf. the workaround

“Setting output values”.

Mark the code line with the specific value: In QTP, choose the “Expert View” Choose the right action Click into the right code line where you have entered the specific value

Parameterize the value: Choose the “Keyword View” Click into the cell of the marked code line named “Value” Click on the just appeared purple button “<#>”

43

Page 44: QTP Scripting Work a Rounds SAP

Choose the value of the global data table: Choose “Parameter” Set “Parameter” to “DataTable” Set “Name:” to your created output value Set “Location in Data Table” to “Global sheet” Hit “OK”

Finished:

44

Page 45: QTP Scripting Work a Rounds SAP

Info: When running the script, QTP will dynamically access the value of the global data table.

45

Page 46: QTP Scripting Work a Rounds SAP

Setting checkpointsSetting checkpoints

Line of action: Info: When you want to verify a displayed value with an expected value, you

can use checkpoints.

Mark the desired text to check: In QTP, choose the “Expert View” Choose the right action Click into the right code line with the active screen showing the value to check Mark the value in the active screen

Insert a checkpoint: Rightclick on the mark and choose “Insert Text Checkpoint…” Change the “Name:” following the naming convention:

Checkpoint_<name of value> Make sure that the “Constant” is set to the right text Set “Insert statement” to “Before current step” Hit “OK”

46

Page 47: QTP Scripting Work a Rounds SAP

Finished: Info: The checkpoint has just been correctly set. Info: After running the script, a result window will pop up showing the success

or failure of the run. When you expand the nodes, you can see the result of the checkpoint.

47

Page 48: QTP Scripting Work a Rounds SAP

Defining a global variable as a counterDefining a global variable as a counter

Line of action: Info: Your scenario loops over a step for a certain number of times. Only at the

last loop, you want to measure the step with FUSE. Solution: You check with an if-structure when the loop counter reaches your

desired value and start / stop FUSE.

Problem: If the step is performed within a nested action, you cannot access the loop counter of the outer action.

Solution: You have to define a global variable in the global data table as a counter.

Define the global variable in the global data table: In QTP, choose the tab “Data Table” in the bottom-left corner. Doubleclick on the header cell named with a character of an unused column,

for example “C” Enter a name for the global variable, for example “Counter” Hit “OK” The global variable has been set and can now be accessed by any action.

Doubleclick on the cell below your just renamed header cell Enter “0” (zero) Hit “Enter” Important: Do not forget to press “Enter” to confirm the value.

48

Page 49: QTP Scripting Work a Rounds SAP

Increment the counter: In QTP, choose the “Expert View” Choose the right nested action where you want to measure the step Copy and paste the following code line into the first code line to increment the

counter Info: When you have named your global variable differently, modify “Counter”

in the code line.

DataTable("Counter", dtGlobalSheet) = DataTable("Counter", dtGlobalSheet) + 1

Insert the if-structure and the commands of FUSE: Insert the following code lines before the step you want to measure

49

Page 50: QTP Scripting Work a Rounds SAP

Info: When you have named your global variable differently, modify “Counter” in the code line.

Info: Modify the value “4” to match your test case.

If DataTable("Counter", dtGlobalSheet) = 4 ThenBrowser(<edit to match the code line>).Page(<edit to match the code

line>).SyncJavaWindow("Measurement GUI").JavaButton("Start").Clickwait DataTable("Wait_BeforeAction", dtGlobalSheet)

End If

Insert the following code lines after the step you want to measure Info: When you have named your global variable differently, modify “Counter”

in the code line. Info: Modify the value “4” to match your test case.

If DataTable("Counter", dtGlobalSheet) = 4 ThenBrowser(<edit to match the code line>).Page(<edit to match the code

line>).Syncwait DataTable("Wait_AfterAction", dtGlobalSheet)JavaWindow("Measurement GUI").JavaButton("Stop").Click

End If

Set up FUSE: Please refer to the workaround Set up FUSE in a new action in this document

Finished: Info: It is now possible to use a global counter that is independent of other

actions.

50

Page 51: QTP Scripting Work a Rounds SAP

Setting up FUSE in a new actionSetting up FUSE in a new action

Line of action: Info: When you would like to measure a step in a new action with FUSE, you

need to add the buttons of FUSE to the Object Repository of QTP.

Preparations: In QTP, run your script to step you want to measure Change the active window to FUSE Change the active window back to QTP Important: Make sure that the current action is the right action with the step to

measure.

Add the buttons of FUSE to the Object Repository: Menu: Resources \ Object Repository… Menu: Object \ Add Object to Local… Click on the “Start” button of FUSE Important: Make sure the “Start” button is active. Otherwise click on the

“Stop” button first.

Menu: Object \ Add Object to Local… Click on the “Stop” button of FUSE Important: Make sure the “Stop” button is active. Otherwise click on the

“Start” button first.

Finished: The buttons of FUSE can now be correctly recognized by QTP. Just add the start

and stop commands of FUSE as usual.

51

Page 52: QTP Scripting Work a Rounds SAP

Passing parameters to a nested actionPassing parameters to a nested action

Line of action: Info: We want to call a nested action passing parameters to control the

program flow. Info: This could be useful when we pass the current loop index and the loop

maximum to a nested action. In this action, we only measure the step when the current loop equals the loop maximum, e.g. when we are in the last loop.

Prepare your script: In QTP, record your scenario as usual – including the call to a nested action Choose the “Expert View” Choose the nested action to which you want to pass parameters

Insert input parameters: Menu: Edit \ Action \ Action Properties… \ Parameters Click on the button with the green “+” next to the “Input parameters” Enter a “Name” for your parameter Choose a “Type” Note: You might also modify the “Default Value”.

Repeat the last three steps with every parameter you want to pass Hit “OK”

Call the nested action with parameters: Choose the action which calls the nested action Look for the code line with the call of the nested action

For example: RunAction "Action3", oneIteration Now complete the code line with your desired parameters

o Each parameter has to be seperated by a comma “,”o For example: RunAction "Action3", oneIteration, “Hello World!”, 10

Important: The order of the parameters corresponds to the order of the input parameters you have created.

Note: Instead of using specific values you can also parameterize the parameters.

52

Page 53: QTP Scripting Work a Rounds SAP

Finished: Note: You are now capable of using an advanced technique to control your

program flow.

53

Page 54: QTP Scripting Work a Rounds SAP

Search error “No records found”Search error “No records found”

Line of action: Info: We enter a value into a text field of a search mask. When hitting “Go”,

the just entered value disappears and it says “No records found”.

Choose the set command: In QTP, choose the “Expert View” Choose the right action Mark the right code line where you insert the value into the text field

54

Page 55: QTP Scripting Work a Rounds SAP

Duplicate this code line: Copy the marked code line Insert it into the next line

Finished: Info: The inserted value should now be kept. The search should be successful.

55

Page 56: QTP Scripting Work a Rounds SAP

Create “New Sales Order” errorCreate “New Sales Order” error

Problem: When we create a “New Sales Order”, you enter the “Product ID” and then the

“Quantity”. When hitting “Enter”, the “Product ID” disappears.

Solution: Enter the “Quantity” first Then type in the “Product ID” Click into the “Quantity” text field again Hit “Enter”

56

Page 57: QTP Scripting Work a Rounds SAP

Error running the “Test Batch Runner”Error running the “Test Batch Runner”

Problem: When runnning the “Test Batch Runner” of QTP, several items like buttons are

not recognized. You might have the SAP plugin installed, so QTP is not able identify items

correctly.

Solution: Menu: Start \ Control Panel \ Add and Remove Programs / Programs and

Features Select “QuickTest Professional SAP Plugin” Uninstall

57

Page 58: QTP Scripting Work a Rounds SAP

Error using FUSEError using FUSE

Problem: FUSE crashes throwing a dump. The button “Stop” does not work.

Solution: Update your SAP GUI.

Make sure that the properties of the action “01_LogOn” and “03_LogOff” are set correctly.

58

Page 59: QTP Scripting Work a Rounds SAP

Error setting output valuesError setting output values

Problem: Using the advanced technique to set an output value does not work. The desired value is not stored in the global data table

Insert output value: In the active screen of QTP, mark the desired value. Instead of rightclicking and choosing “Insert Text Output…”, choose “Insert

Output Value” Info: Now the whole item is stored in the global data table instead of just the

desired value.

Choose the right property: In the following window, check the property containing your desired value. For example: Check “innertext” to gain the number of the sales order.

Make sure the “Location” is set to “Global sheet” Modify the names as you like

59

Page 60: QTP Scripting Work a Rounds SAP

Cut the stored value: To extract the desired value of the stored string insert the following code line.

Modify the parameters in the brackets:

DataTable("<match output value name>", dtGlobalSheet) = Replace(DataTable("<match output value name>", dtGlobalSheet), "<enter string to be deleted> ", "")

For example, we want to get the number of in the string “SalesOrder: 8331”:DataTable("value_myOutput", dtGlobalSheet) = Replace(DataTable("value_myOutput", dtGlobalSheet), "SalesOrder: ", "")

Finished: Now the output value is ready to be used in further steps.

60

Page 61: QTP Scripting Work a Rounds SAP

Not working clicks on buttonsNot working clicks on buttons

Problem: When running a script with correctly recorded click on a button, the click might

fail.

Change command “Click”: In QTP, choose the active screen and the right action. Locate the step with the click on the desired button. Copy and paste the code line

Replace the “Click” of the first line with “Drag” Replace the “Click” of the second line with “Drop

Finished: This is a very common workaround to fix those kinds of errors.

61