Watch this short video to learn about OPA5, its advantages, and limitations.
Performing Integration Tests with One-Page Acceptance (OPA5) Tests
Objective
Integration Tests with OPA5
OPA5 and Bootstrapping
As we have already seen in the QUnit-lesson, the start of the OPA-tests is also implemented using a different html-file. The file is called the opaTests.qunit.html file and contains the bootstrapping code for the execution of OPA-tests. The bootstrapping file is generated by the SAP Business Applicaton Studio during project generation.
Let us now look at bootstrapping, library loading, and test initiation.
Note
OPA5: Anatomy of a Test Case
Each test case scenario is implemented in a different JavaScript file.
The following two figures describe the anatomy of an OPA5 test case.


The above figure shows a test implementation. The test case is set to check whether or not the component with the namespace sap.training.optest.integration.button can be loaded or not.
The function opaTest is the main aspect for defining integration tests with OPA. Its parameters define a test name and a callback function that gets executed with the following OPA5 helper objects to write meaningful tests that read like a user story.
- Given: On the given object, we can call arrangement functions like iStartMyUIComponent to load our app in a separate iFrame for integration testing.
- When: Contains custom actions that we can execute to get the application into a state that allows us to test the expected behavior.
- Then: Contains custom assertions that check a specific constellation in the application and the teardown function that removes our iFrame again.
OPA5 Control Retrieval by ID
The OPA5 framework provides us different possibilities to get a reference to a UI control on the view. One option is to get a reference by the id of the control. The following figure shows the key aspects involved in the retrieval of a control by ID.

Note
OPA5 Control Retrieval without ID
Besides the retrieval of a UI control by id, it is also possible to use so called matchers. The following figure shows matchers retrieving a control without an ID but using a matcher. In this case, a sap.ui.test.matchers.PropertyStrictEquals is used. We want to get all controls of type sap.m.Button, where the property text contains the value Press me. You can find more matcher implementations in the namespace sap.ui.test.matchers of the SAPUI5-API-documentation (https://ui5.sap.com/#/api/sap.ui.test.matchers).

Write OPA Tests
In this demonstration, you will write OPA tests.
Caution
Please be aware that depending on the environment you use for the demonstration, you might get some errors. This needs to be performed directly on a PC. It might not work in a virtual environment such as the training landscape.
Steps
Import the opa.tar project into your Business Application Studio.
Locate the CHECKopa.tar file in your training files.
Select the menu File→Open Folder....
Select or Enter the /home/user/projects/ folder and choose OK.
Select the menu File→Import Project...
Select the CHECKopa.tar file and choose OK.
Run your application. Choose the Press me button. A dialog appears with the message Button pressed.

Open the context menu on your project folder (CHECKopa).
Select Preview Application.
Choose start fiori run –open ".." on the opened dialog.
If prompt, select Open on the dialog in the bottom right corner.
Implement a test function with the name iShouldFindAButton in the webapp/test/integration/pages/Main.js file and check if the Main-view implemented in the previous task contains a control with the id helloButton.
Attribute-value Pairs for this.waitFor
Attribute Value viewName sViewName id helloButton success Callback function with one parameter named oButton errorMessage Did not find the hellobutton timeout 3 Open the webapp/test/integration/pages/Main.js file.
Implement the iShouldFindAButton function after the iShouldSeeThePageView function, using the following code:
Code Snippet123456789101112iShouldFindAButton: function () { return this.waitFor({ viewName: sViewName, id: "helloButton", success: function (oButton) { }, errorMessage: "Did not find the hello-Button", timeout: "3" }); }Implement the success function. Trigger the press event on the passed oButton object and print out an assertion of type ok. Use the following code:
Code Snippet123oButton.$().trigger("press"); Opa5.assert.ok(oButton.getId(), "Button with the given ID found");Save your work. Your implementation should now look like the following:

Add the assertion iShouldFindAButton to the webapp/test/integration/NavigationJourney.js file.
Open the NavigationJourney.js file and add theiShouldFindAButton as a new assertion. Add the following code after the iShouldSeeThePageView() assertion:
Code Snippet1Then.onTheViewPage.iShouldFindAButton();Save your changes. Your code should look like the following:

Start your application in int-tests mode. A new browser tab opens and the test case starts. When the test is complete, you can expand the test result to get more details. The results screen should look like the one shown in the following figure.

Open the context menu on our project folder (CHECKopa).
Select Preview Application.
Choose int-tests fiori run –open ".." on the opened dialog.
If prompted, choose Open on the dialog in the bottom right corner.
A new browser tab opens, and the test case starts. When the test is complete, you can expand the test result to get more details.