how to execute tests using the web dynpro abap unit … · how to execute tests using the web...

18
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com © 2012 SAP AG 1 How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework Applies to: SAP NetWeaver 7.31 SP06 SAP NetWeaver 7.40 SP01 Summary The Web Dynpro ABAP unit test framework provides a unit-based environment for the automatic testing of Web Dynpro ABAP applications. You can replay applications in the background and check whether the individual software units return the expected results. Authors: Sabine Kissner, SAP TIP Core UI Development Lisa Monshausen, SAP TIP KM Company: SAP AG Created on: 18.10.2012

Upload: dophuc

Post on 12-Jun-2018

341 views

Category:

Documents


14 download

TRANSCRIPT

Page 1: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 1

How to Execute Tests Using the

Web Dynpro ABAP Unit Test

Framework

Applies to:

SAP NetWeaver 7.31 SP06

SAP NetWeaver 7.40 SP01

Summary

The Web Dynpro ABAP unit test framework provides a unit-based environment for the automatic testing of Web Dynpro ABAP applications. You can replay applications in the background and check whether the individual software units return the expected results.

Authors: Sabine Kissner, SAP TIP Core UI Development

Lisa Monshausen, SAP TIP KM

Company: SAP AG

Created on: 18.10.2012

Page 2: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 2

Table of Contents

Web Dynpro ABAP Unit Test Framework - Overview ........................................................................................ 3

Layers in Web Dynpro ABAP .......................................................................................................................... 3

Creating Web Dynpro ABAP Unit Tests ............................................................................................................. 3

Locating the Test Class................................................................................................................................... 3

Running the Application .................................................................................................................................. 4 Starting and Ending an Application .............................................................................................................................. 4

Triggering a Roundtrip ................................................................................................................................................. 4

Simulating Operations on the Screen .......................................................................................................................... 5

Checking the Application................................................................................................................................. 9

Example .......................................................................................................................................................... 9 Run Application ............................................................................................................................................................ 9

Check Application ...................................................................................................................................................... 13

Checking Methods on the Context without the Unit Test Framework .............................................................. 15

Examples ...................................................................................................................................................... 15

Related Content ................................................................................................................................................ 17

Copyright........................................................................................................................................................... 18

Page 3: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 3

Web Dynpro ABAP Unit Test Framework - Overview

The Web Dynpro ABAP unit test framework allows developers to write tests for Web Dynpro applications using the ABAP Unit test environment.

It enhances the test tools provided by Web Dynpro ABAP. While the Web Dynpro ABAP unit test framework is aimed at developers for testing smaller UI parts, Extended Computer Aided Test Tool (eCATT) is more suitable for testing complete business applications or processes. Usually special applications are written for the unit tests and checks are always done in the actual system. Developers can continue to work on the objects being checked. Using eCATT, you can create checks without any knowledge of developing and execute them on remote systems. Logging in eCATT is much more elaborate than in the ABAP unit test.

The unit test framework simulates browser requests and responses without an actual browser being called. Just like in a real run of the application, the complete Web Dynpro phase model is executed and windows, views, and components are created. Moreover, the adapter layer, which is responsible for the representation of the UI elements in the browser, is processed.

Layers in Web Dynpro ABAP

The Web Dynpro ABAP unit test framework simulates the call of the UI element adapter. For a better understanding of the underlying concept, the layers used in Web Dynpro are described below:

The Web Dynpro runtime layer contains all the objects a Web Dynpro developer knows about (for

example, UI Element classes CL_WD_..., context, components, etc.).

The adapter layer adapts the Web Dynpro UI elements to adapter elements containing the sub-adapter

elements used to build up the UI in the browser.

Each Web Dynpro UI element has a corresponding adapter UI element as a main adapter, but might also

have additional adapters to render smaller parts in the UI element. For example, Web Dynpro UI element

InputField has CL_INPUT_FIELD as the main adapter and CL_INPUT_FIELD_COMBOBOX and

CL_INPUT_FIELD_ITEMBOX as additional adapters.

You need to provide the IDs of the Web Dynpro runtime layer and adapter layer when you write a unit test. For further information on how to find UI element and adapter IDs, see section Simulating Operations on the Screen.

Creating Web Dynpro ABAP Unit Tests

Two different tasks are involved when you want to write a unit test for a Web Dynpro application:

1. Run the application in various steps

2. Carry out checks (e.g. on the context, messaging or UI elements that should be available in a given

step)

You need to create a specific test class for the unit test. Before we explain the different tasks involved in a unit test in more detail, you need to know how to locate the test class.

Locating the Test Class

Web Dynpro unit tests test Web Dynpro applications, and not ABAP classes. However, the Object Navigator (SE80) does not offer a way to connect these two entries (e.g. a where-used list).

Page 4: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 4

A unit test class always belongs to an ABAP class. We suggest that you locate this test class along with the assistance class of the root component of the test application. Keep in mind that components tested using component usage cannot be traced with where-used lists or even with ABAP TREX searches. To avoid this, you should name the tested components somewhere in the test code to allow at least an ABAP TREX search. This ensures that the unit tests on this component can be found after a component has been changed.

You can find examples of components containing test classes in package SWDP_TEST_AUTOMATION.

Running the Application

The first task in a unit test is to run the application in the background through all the screens you want to check and simulate operations on the screen (e.g. selecting a button or entering a value). For this task, you use class CL_WD_WEB_DYNPRO_TESTER and the tester classes for the different Web Dynpro UI elements.

The following methods are provided in class CL_WD_WEB_DYNPRO_TESTER:

CREATE Starts the application and renders the initial screen (WDDOINIT

is executed).

EXIT Closes the application (WDDOEXIT is executed).

EXCECUTE_REQUEST Triggers a roundtrip.

GET_UI_ELEMENT_TESTER Gets tester UI element instance (IF_WDT_...) using UI element ID.

Note:

If you want to test UI elements within multiple UI elements (e.g.

InputFields in Tables) you need to specify which

element/line you want to test. To do this, supply the parameter CONTEXT_ELEMENT for method GET_UI_ELEMENT_TESTER. To retrieve the context element, use method GET_CONTEXT_ROOT_NODE and navigate through the context tree.

GET_UI_ELEMENT_TESTER_BY_ID Gets instance of tester UI element that has not been

implemented yet (IF_WDT_...) using adapter ID.

GET_TOP_WINDOW_CMP_USAGE_PATH Gets the component usage path for popup windows

Starting and Ending an Application

To start and end an application, you use methods CREATE and EXIT of class CL_WD_WEB_DYNPRO_TESTER.

Triggering a Roundtrip

At the end of each step, you call method EXCECUTE_REQUEST to trigger a roundtrip. The phase model is executed.

Page 5: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 5

Simulating Operations on the Screen

To simulate operations on the screen, you use the corresponding UI element tester class.

Getting Tester interface via UI Element ID

To get an interface for a UI element that is already provided by the unit test framework, call method GET_UI_ELEMENT_TESTER of CL_WD_WEB_DYNPRO_TESTER. The interfaces are named according to the corresponding UI element (IF_WDT_xxx, where xxx is the name of the UI element). The interface offers methods to trigger changes and events on the UI element.

When you call method CL_WD_WEB_DYNPRO_TESTER->GET_UI_ELEMENT_TESTER, you need to pass the following parameters:

uielement_id

view_id

component_path.

To find out the values for these parameters, proceed as follows:

1. Run your application.

2. Set the focus on the UI element you want to check.

3. Choose Technical Help in the context menu.

4. Switch to the Views and View Elements tab.

The following dialog box is displayed:

Page 6: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 6

uielement_id

view_id

component_path

Page 7: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 7

Note:

If the components are nested, to create the component_path, you need to list the different component usages and separate them by a full stop.

The code for the example above would look as follows:

lo_table ?= mo_wd_tester->get_ui_element_tester( view_id = 'VIEW_TABLE'

uielement_id = 'SALV_WD_UIE_TABLE'

component_path = 'FPM_LIST_UIBB_FPM_LIST_UIBB_TEST_ALV_CP_1_00_.SALV_WD_TABLE_CC' ).

If you want to test popups (e.g. F4 helps) that originate in other components, you get the component path of the popup window via method GET_TOP_WINDOW_CMP_USAGE_PATH and not by calling the technical help.

The following UI element tester interfaces are currently available:

BreadCrumb

Button

CheckBox

CTable

DropDownByKey

InputField

LinkToAction

Panel

PanelStack

RadioButton

Table

ToolbarButtonChoice

ToolbarDropDownByIndex

Tray

TreeByKeyTableColumn

Getting Generic Tester Interface via Adapter ID

If you need a tester interface for a UI element which has not been implemented yet, you can use a generic interface for any UI element. To get the tester UI element instance using the adapter ID, call method GET_UI_ELEMENT_TESTER_BY_ID of class CL_WD_WEB_DYNPRO_TESTER.

When you call method CL_WD_WEB_DYNPRO_TESTER->GET_UI_ELEMENT_TESTER_BY_ID, you need to provide the adapter IDs. You can find them in the following ways:

Calling technical help:

1. Run the application with the URL parameter sap-wd-stableids=X.

This leads to an adapter ID that has the form

‘comp_name.comp_counter:viewname.WD_ui_element_id’. Without adding this URL parameter, the

adapter ID is a four character string.

2. Call the technical help. The IDs are displayed in the Technical Help dialog box on the View Element

Adapter tab:

Page 8: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 8

As you can see in the dialog box, the adapter ID for the UI element from the example above

(uielement_id = 'SALV_WD_UIE_TABLE') has the following adapter ID:

SALV_WD_TABLE.ID_37E4F3F23FD2A39E0268A6ADE4351601:VIEW_TABLE.SALV_WD_UIE_TABLE

Setting a breakpoint:

1. Run the application with the URL parameter sap-wd-stableids=X.

2. Set an external breakpoint at the end of method

CL_NW7_VIEW_ELEMENT_ADAPTER->DISPATCH_NW7_EVENT:

The method is called for each roundtrip and handles the event raised by the browser. Variable i_event_name contains the event name and variable i_event_parameters contains the list of parameters that must be provided for the parameter in the UR methods.

3. Debug the relevant step in your application. Do not forget to switch on system debugging (in the

debugger, choose Settings System Debugging On/Off).

The adapter ID is the attribute M_ID of l_event_handler. The content of i_event_name and i_event_parameters must be supplied in method RAISE_EVENT of the tester instance.

Page 9: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 9

Note:

Sometimes two methods are offered to trigger the same action (e.g. in IF_WDT_BREAD_CRUMB). To

simulate that a BreadCrumb is selected in the browser window, you can use methods

RAISE_SELECT_WD or RAISE_SELECT_UR. If you call RAISE_SELECT_WD, you have to supply the UI

element ID of the BreadCrumb step, as defined in SE80. If you call RAISE_SELECT_UR, you have to

supply the adapter ID of the BreadCrumb step. If you want to execute a step in a

MultipleBreadCrumbStep, you must use method RAISE_SELECT_UR since in this case a UR adapter

but no Web Dynpro UI element is available for a step.

Checking the Application

In the second step, you check the current status of the application after a roundtrip and whether the application returns the expected result. You can check context, messaging, or UI elements that should be visible in a given step.

The following methods of class CL_WD_WEB_DYNPRO_TESTER are provided to carry out these checks:

GET_CONTEXT_MENU Gets method for the context menu that is displayed (only

application-defined entries)

GET_CONTEXT_ROOT_NODE Gets method for the root element of the context

GET_MESSAGES Gets method for Web Dynpro messages

GET_UI_ELEMENT Gets method for Web Dynpro UI element (CL_WD_...)

GET_UI_ELEMENT_PROPERTY Checks the values of the UI element properties

visibility, enabled, readOnly and required, and

whether the settings for these properties have been changed

in personalization.

GET_TOP_WINDOW_CMP_USAGE_PATH Gets the component usage path for popup windows

Example

Let us look at an example to help clarify how to execute tests with the Web Dynpro ABAP unit test framework.

In this example, we will perform a Web Dynpro unit test on the editor for the Web Dynpro ABAP component configuration (application CONFIGURE_COMPONENT). We will go step-by-step through the two main tasks that are involved: run application and check application.

You can find sample code in method implementation RUN_CONFIGURATOR2 in class CL_WD_WEB_DYNPRO_TESTER.

Run Application

In the first part, you define the screens you want to check and the operations on the screen you want to simulate.

Page 10: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 10

1. Start Application

To simulate that the user starts the configuration editor for the component he or she wants to configure, you can use the following code:

METHOD run_configurator2 .

DATA: tester TYPE REF TO cl_wd_web_dynpro_tester,

l_root_node TYPE REF TO if_wd_context_node,

l_node TYPE REF TO if_wd_context_node,

l_check_value TYPE string,

l_check_number TYPE i,

l_tst_inp_field TYPE REF TO if_wdt_input_field,

l_tst_button TYPE REF TO if_wdt_button,

l_tst_checkbox TYPE REF TO if_wdt_checkbox ,

l_tst_toolbarbutton TYPE REF TO if_wdt_button .

DATA lv_vis TYPE wdui_visibility.

DATA lo_uielement TYPE REF TO cl_wd_uielement.

DATA lt_messages TYPE if_wd_message_manager=>ty_t_messages.

DATA l_check_integer TYPE string.

DATA lt_change_log TYPE wdr_context_change_list.

DATA l_url_addition TYPE string.

l_url_addition = '&CONFIG_ID=WDR_UNIT_TEST_DEP'.

tester = cl_wd_web_dynpro_tester=>create( application = 'configure_component' url_addition = l_u

rl_addition ).

2. Select CheckBox

To simulate that the user selects the Advanced Settings CheckBox, you can use the following code:

l_tst_checkbox ?= tester-

>get_ui_element_tester( component_path = 'SELECTION_SCREEN' view_id = 'ENTRY_MAIN' uielement_id = 'EXTENDED_IS_EXTENDED' ).

l_tst_checkbox->raise_change( checked = abap_true ).

tester->execute_request( ).

To find out the values for the parameters component_path, view_id and uielement_id, proceed as

follows:

1. Run application CONFIGURE_COMPONENT.

2. Set the focus on the Advanced Settings CheckBox.

3. Choose Technical Help in the context menu.

Page 11: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 11

4. Switch to the Views and View Elements tab. The dialog box displays the parameter values:

3. Enter wrong value in InputField

To simulate that the user enters a wrong value in the Configuration Variant InputField, you can use the

following coding:

l_tst_inp_field ?= tester-

>get_ui_element_tester( component_path = 'SELECTION_SCREEN' view_id = 'ENTRY_MAIN' uielement_id = 'EXTENDED_CONF_VARIANT_DD' ).

l_tst_inp_field->raise_change( EXPORTING value = 'jakfjjjfkfjalfj' ).

tester->execute_request( ).

4. Choose Display Mode button in ToolBar

Page 12: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 12

To simulate that the user chooses Continue in Display Mode in the ToolBar, you can use the following

coding:

l_tst_toolbarbutton ?= tester-

>get_ui_element_tester( component_path = 'SELECTION_SCREEN' view_id = 'ENTRY_MAIN' uielement_id = 'BUTTON_DISPLAY' ).

l_tst_toolbarbutton->raise_press( ).

tester->execute_request( ).

5. Clear value of InputField

To simulate that the user clears the value of the Configuration Variant InputField, you can use the

following code:

l_tst_inp_field->raise_change( EXPORTING value = '' ).

tester->execute_request( ).

6. Expand tree

To simulate that the user expands the Tree in the second Panel, you can use the following code:

DATA: l_tst_table TYPE REF TO if_wdt_table .

l_tst_table ?= tester-

>get_ui_element_tester( component_path = 'IMPL_COMP_CONFIG' view_id = 'CURR_VIEW_ELEMENTS' u

ielement_id = 'VIEW_ELEMENTS' ).

l_tst_table-

>raise_cellexpand( rowindex = '1' cellid = 'WDR_ADAPT_IMPLICIT_EDITOR.ID_4CC32FF10471C2E98D

F8B6A7B3717799:CURR_VIEW_ELEMENTS.VIEW_ELEMENT.1' ) .

tester->execute_request( ).

7. Select line in Tree

Page 13: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 13

To simulate that the user selects the second line in the Tree, you can use the following coding:

l_tst_table->raise_cellselect(

cellid = 'WDR_ADAPT_IMPLICIT_EDITOR.ID_4CC32FF10471C2E98DF8B6A7B3717799:CURR_VIEW_ELEMENTS.VIEW_ELEMENT.2'

celltype = 'SapTableHierarchicalCell'

rowindex = '2'

colindex = '1' ).

tester->execute_request( ).

8. Select entry in drop down list box

To simulate that the user selects the item Personalized Elements in the dropdown list box, you can use the following code:

DATA: l_tst_toolbar_dropdow_by_idx TYPE REF TO if_wdt_toolbar_dropdown_by_idx .

l_tst_toolbar_dropdow_by_idx ?= tester-

>get_ui_element_tester( view_id = 'COMP_CONFIG_MAIN' uielement_id = 'IMPL_PANEL_TOOLBAR_NAV_DDBI' ).

l_tst_toolbar_dropdow_by_idx->select( key = '2' ).

tester->execute_request( ).

9. Close the application

To simulate that the user closes the browser window, call the following method:

tester->exit( ).

Check Application

The following section includes examples of checks that can be performed for our example application (CONFIGURE_COMPONENT).

1. Check if UI element is visible

The Configuration Type InputField should only be visible after the user has selected the Advanced

Settings CheckBox. You can check this in the following way:

Insert the following code before step 2 in this example (Select CheckBox):

lo_uielement = tester->get_ui_element( component_path = 'SELECTION_SCREEN'

view_id = 'ENTRY_MAIN'

uielement_id = 'EXTENDED_CONF_TYPE_DD').

tester->get_ui_element_property( EXPORTING ui_element = lo_uielement

IMPORTING visible = lv_vis ).

cl_abap_unit_assert=>assert_equals(

Page 14: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 14

exp = cl_wd_uielement=>e_visible-none

act = lv_vis ).

Insert the following coding after step 2 in this example (Select CheckBox):

lo_uielement = tester->get_ui_element( component_path = 'SELECTION_SCREEN'

view_id = 'ENTRY_MAIN'

uielement_id = 'EXTENDED_CONF_TYPE_DD').

tester->get_ui_element_property( EXPORTING ui_element = lo_uielement

IMPORTING visible = lv_vis ).

cl_abap_unit_assert=>assert_equals(

exp = cl_wd_uielement=>e_visible-visible

act = lv_vis ).

2. Check messages

A message is expected after the user entered a wrong value in the Configuration Variant InputField and

chose the Continue in Display Mode button (step 3 and 4 in this example). To check this, you can use the following code:

lt_messages = tester->get_messages( ).

cl_abap_unit_assert=>assert_equals(

exp = '1'

act = lines( lt_messages ) ).

3. Check context of table

The context of the table displayed after the user chose Personalized Elements contains two lines. To check this, you can use the following code:

DATA lo_root TYPE REF TO if_wd_context_node.

lo_root = tester->get_context_root_node( EXPORTING component_path = 'IMPL_COMP_CONFIG'

controller_id = 'CURR_ADAPTATIONS' ).

cl_abap_unit_assert=>assert_equals(

exp = '2'

act = lo_root->get_child_node( 'IMPLICIT_DATA' )->get_element_count( ) ).

ENDMETHOD. "run_configurator2

Page 15: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 15

Checking Methods on the Context without the Unit Test Framework

This section describes a procedure for checking the methods on the context without using the Unit Test Framework.

To create a controller with a local context and to test methods on this context, you use method CREATE_CONTEXT in class CL_WD_TEST_CONTROLLER. Being purely class-based, this procedure works without a Web Dynpro application.

There are two ways of creating a context using method CREATE_CONTEXT:

You pass the name of an existing component and controller to the import parameter of method

CREATE_CONTEXT:

The context structure is built using the existing node info.

You do not pass the name of component and controller:

Only an empty root node is created. You build the context dynamically by creating new node info.

Examples

The following section includes two examples of testing a loop method on a context. In the first example, you use existing node info, and, in the second example, you create the context dynamically.

Example 1:

method test_sflight_context.

data lr_context_root type ref to if_wd_context_node.

data lr_context_node type ref to if_wd_context_node.

data ls_flight type sflight.

data lv_count type I.

" create empty root node

lr_context_root = cl_wd_test_controller=>create_context(

i_component_name = 'WDR_TEST_CONTEXT'

i_controller_name = 'TESTCASE04'

).

" get reference to subnode,

lr_context_node = lr_context_root->get_child_node( name = 'SFLIGHT' ).

" Call your method here. We fill the context directly instead

do 10 times.

ls_flight-carrid = sy-index.

ls_flight-fldate = sy-datum.

lr_context_node->bind_structure(

new_item = ls_flight

set_initial_elements = ABAP_FALSE

).

enddo.

" check number of entries

lv_count = lr_context_node->get_element_count( ).

cl_abap_unit_assert=>assert_equals(

exp = 10

act = lv_count

Page 16: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 16

).

endmethod.

Example 2:

method test_pure_context.

data lr_context_root type ref to if_wd_context_node.

data lr_context_node type ref to if_wd_context_node.

data lr_context_node_info type ref to if_wd_context_node_info.

data ls_flight type sflight.

data lv_count type I.

" create empty root node

lr_context_root = cl_wd_test_controller=>create_context( ).

" get node info

lr_context_node_info = lr_context_root->get_node_info( ).

" create new node info (cardinality 0..n)

lr_context_node_info = lr_context_node_info->add_new_child_node(

static_element_type = 'SFLIGHT'

name = 'NEW_NODE'

* is_mandatory = ABAP_FALSE

* is_multiple = ABAP_TRUE

).

" get reference to subnode

lr_context_node = lr_context_root->get_child_node( name = 'NEW_NODE' ).

" Call your method here. We fill the context directly instead

do 10 times.

ls_flight-carrid = sy-index.

ls_flight-fldate = sy-datum.

lr_context_node->bind_structure(

new_item = ls_flight

set_initial_elements = ABAP_FALSE

).

enddo.

" check number of entries

lv_count = lr_context_node->get_element_count( ).

cl_abap_unit_assert=>assert_equals(

exp = 10

act = lv_count

).

endmethod.

Page 17: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 17

Related Content

SAP Online Help – SAP NetWeaver 7.3 EhP 1 – Unit Test

SAP Online Help – SAP NetWeaver 7.3 EhP 1 – eCATT and Web Dynpro ABAP

Page 18: How to Execute Tests Using the Web Dynpro ABAP Unit … · How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework SAP ... (eCATT) is more suitable for testing complete

How to Execute Tests Using the Web Dynpro ABAP Unit Test Framework

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2012 SAP AG 18

Copyright

© Copyright 2013 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.

Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.

Oracle is a registered trademark of Oracle Corporation.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.

HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.

Java is a registered trademark of Oracle Corporation.

JavaScript is a registered trademark of Oracle Corporation, used under license for technology invented and implemented by Netscape.

SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.

Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.

All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.