Skip to Content
Technical Articles

CBTA: How to use Query API for SAP Fiori Applications

If you are trying to record a complex scenario where the elements change dynamically and the regular approach based on standard component is not enough because it takes specific attributes based on row numbers or column position; then you may want to read the documentation that is available in the CBTA documentation regarding Query APIs.

The document is very handy and introduces the concept very clear; however, all the examples exposed are CRM related. In this post, an example of Query API based on Fiori app is shown to bring more material to the discussion.

Query API Exercise

The goal of this exercise is to create a query able to search, using filters and conditions, a project in the Project Mg. app (Action-projectManagementPMO),  using the name or description instead of the location or position in a table.

Fiori%20App%20with%20Projects%20to%20select

Fig. 1 SAP Fiori App with Projects to select

The Test Script

The exercise is very simple, to open the project AM16  and test the app.

CBTA%20script%20with%20Default%20Components

CBTA script with Default Components

The script above selects the project ACME16 with a web click and test the rest of the options with the same type of default component.

The challenge using Default Components!

Even when it is possible to use CBTA Default Components to select the element that contains the project, this action (CBTA_WEB_CLICK) will use the row number associated in the table and that number is static (Fig1. shows the stage during the recording, target = ACME16) that means that if a new project is added (e.g. AAA_PROEJCT) that number (Row = 2) will change and the URI will not match anymore.

The URI uses the “label” and the “.rowindex=2 as part of the location.

label=ACME16 – FB 2.2 Build Template; ui5.type=sap.m.Link;  …… –landingView–LineItemsSmartTable-rows-row2; ui5.data.cust-sap-ui-colindex=2; ../ui5.data.rowIndex=2; ..

Fiori%20App%20with%20an%20extra%20Project

SAP Fiori App with an extra Project

Resolution – Create a Custom Function

For starter, to solve this problem you need to create a custom function; get familiar with the CBTA Runtime Library using CBTA – Runtime Library Manager.pdf.

The code below shows How to create a query UI5 as part of the custom function to search the project using filters such as innerText, and once is located perform a web click action to open that specific  project.

 Function Demo_API_Fiori (Project_Name, pam2, pam3, pam4, options)
	dim controller, query, filter,subfilter
	
	Set controller = Ui5Controller()
	Set query = controller.CreateUi5Query() 'Create the UI5 query object
	
	query.ParentControlUri = "id=__flex0-FlexibleContainer; tag=DIV" 'Limit the query on this area, parent block
	
	Set filter = query.SetFilter()	'Filter Creation
	
	filter.AddCondition "tag", "=", "A"
	filter.AddCondition "className", "=", "sapMLnk sapMLnkMaxWidth"
	filter.AddCondition "innerText", "=", Project_Name
	
	Dim ui5Control, controlURI
	
	Set ui5Control = query.SelectSingle() 'this method resolves the query and returns the first web control that matches the criteria									
	controlURI = Ui5Control.GetControlUri()
	
	If ui5Control Is Nothing Then
		Reportlog "Failed", "Query not Executed", "Value not found"
	Else 
		ui5Control.HighLight "red"
		controller.WebControl_Click controlURI
		Reportlog "Success", "Query  Executed", Project_Name " edited successfully"
	End If
	
End Function

Deploy your Query!

Finally, you need to invoke the custom function in your CBTA script so that the recording searches the name of the project regardless the position. In this example, the function uses the Project_Name as an input parameter and therefore the CBTA_WEB_A_INVOKE_FUNCTION is necessary, otherwise  CBTA_WEB_A_EXECUTESTATEMENT is enough. Pay attention in the parameters below and fill out the values using your own entries, you can find more information in CBTA 3.0 – Runtime Library Manager.pdf.

Details%20of%20CBTA%20Default%20Component%20Invoke%20Function

Details of CBTA Default Component Invoke Function

What Did I Learn?

The Default Components and CBTA front end are designed to adopt an automation test strategy quickly and reliable, also brings the perfect scenario to work together with all the other functionalities in the Test Suite such as BPCA to create robust risk-based testing over your regression test plan. Finally, using custom functions any Test Engineer can improve and manage complex scenario to complement their test cases; CBTA has already many documentation and examples to facilitate the implementation of new code What’s your experience around custom functions?

 

 

 

Be the first to leave a comment
You must be Logged on to comment or reply to a post.