Skip to content

Commit 1ddbcd2

Browse files
authored
feat(ui5): Add OPA5 guidelines as Skills (#64)
Adding skills for OPA5 integration testing. JIRA: BGSOFUIPIRIN-6914
1 parent 6d72751 commit 1ddbcd2

9 files changed

Lines changed: 204 additions & 1 deletion

File tree

plugins/ui5/.github/plugin/plugin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"ui5",
1414
"sapui5",
1515
"openui5",
16+
"opa5",
1617
"plugin",
1718
"linter",
1819
"api-documentation",

plugins/ui5/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# UI5 Plugin for Coding Agents
22

3-
Complete SAPUI5 / OpenUI5 plugin for coding agents with MCP tools, API documentation access, linting capabilities, and development guidelines.
3+
Complete SAPUI5 / OpenUI5 plugin for coding agents with MCP tools, API documentation access, linting capabilities, development and integration testing guidelines.
44

55
---
66

@@ -42,6 +42,15 @@ Development guidelines for UI Integration Cards (also known as UI5 Integration C
4242
- **i18n** - Bind all user-facing strings to the i18n model; never hardcode
4343
- **Actions** - Use the `actions` property for links and interactions; never inline `<a>` tags or hand-roll URL handlers
4444

45+
#### ui5-best-practices-opa5
46+
47+
Guidelines and debugging workflow for OPA5 integration tests:
48+
49+
- **Failure inspection** - Pause-on-failure mode (`sap.ui.test.qunitPause.pauseRule`) keeps the app live at the failure point for browser inspection
50+
- **TestRecorder tooling** - Temporary `sap.ui.testrecorder.ControlTree` integration to inspect the live control tree and generate reliable OPA5 snippets (UI5 ≥ 1.147)
51+
- **Page object organization** - Placement of actions and assertions across views
52+
- **App teardown** - Cleanup patterns in OPA5 journey tests
53+
4554
---
4655

4756
## Installation

plugins/ui5/plugin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"ui5",
1414
"sapui5",
1515
"openui5",
16+
"opa5",
1617
"plugin",
1718
"linter",
1819
"api-documentation",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: ui5-best-practices-opa5
3+
description: This skill should be used in any OPA5 task - creating, modifying, extending, debugging, fixing or reviewing an integration test. Use when the user asks to "write an OPA5 test", "add an OPA5 journey", "fix the OPA5 test failure" or mentions OPA5 or its components - opaTest, page object, journey, waitFor.
4+
---
5+
6+
# OPA5 Guidelines and Tools
7+
8+
## Handle Special Cases (follow when planning and writing an OPA5 test)
9+
- **Initial Configuration for OPA5 Test** → follow `references/configuration.md`
10+
- **If the test-case spans multiple views** → follow `references/handle-multiple-views.md`
11+
- **Teardown the App** → follow `references/handle-teardown.md`
12+
13+
## Set Up Browser Inspection Tools (follow **before running the OPA5 test**)
14+
**Purpose:** Efficient inspection of test failures with minimal steps.
15+
**Prerequisites:** A tool to load the OPA5 test in the browser and evaluate javascript in the browser window (e.g. MCP Playwright)
16+
**Instructions:** → follow `references/setup-inspection-tools.md`
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Configuration
2+
3+
1. Use this folder layout:
4+
```
5+
test/integration/
6+
├── opaTests.qunit.js ← single entry point
7+
├── pages/
8+
│ ├── Welcome.js ← one page object per view (name matches the view)
9+
│ ├── Items.js
10+
│ └── Browser.js ← cross-view actions (navigation, hash)
11+
├── WelcomeJourney.js ← one journey per feature/functionality
12+
└── FilterItemsJourney.js
13+
```
14+
15+
2. **ALWAYS** enable `autoWait` and define `viewNamespace` globally in `opaTests.qunit.js`.
16+
```javascript
17+
// opaTests.qunit.js
18+
sap.ui.define(["sap/ui/test/Opa5"], (Opa5) => {
19+
"use strict";
20+
Opa5.extendConfig({
21+
autoWait: true,
22+
viewNamespace: "com.myorg.myapp.view."
23+
});
24+
// ...
25+
});
26+
```
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# TestRecorder Tooling
2+
3+
The `sap.ui.testrecorder` library provides the module `sap.ui.testrecorder.ControlTree` that allows to:
4+
- inspect the live control tree in the browser
5+
- retrieve reliable OPA5 snippets for interacting with any part of the control tree
6+
7+
## Prerequisites to Use `sap.ui.testrecorder.ControlTree`
8+
9+
- **UI5 version ≥ 1.147**
10+
- Tool to load the OPA5 test in the browser and evaluate javascript in the browser window (e.g. MCP Playwright)
11+
- **`sap.ui.testrecorder` library loaded** — temporarily add to the app's library declarations in the places listed below (**ORDERED BY PRIORITY**):
12+
1. `ui5.yaml``framework.libraries`: `- name: sap.ui.testrecorder`
13+
2. `manifest.json``sap.ui5.dependencies.libs`: `"sap.ui.testrecorder": {}`
14+
3. `index.html``data-sap-ui-libs` bootstrap attribute: append `,sap.ui.testrecorder`
15+
16+
> After adding to `ui5.yaml` ensure the server is serving the added library before proceeding:
17+
> ```bash
18+
> curl -s -o /dev/null -w "%{http_code}" \
19+
> http://localhost:8080/resources/sap/ui/testrecorder/ControlTree.js
20+
> ```
21+
> If 404, **ALWAYS** start a fresh server on the next free port (8081, 8082, …) and use that port
22+
> for all subsequent browser navigation
23+
24+
> Remove `sap.ui.testrecorder` after use — not needed at runtime.
25+
> Kill after use any started fresh server instance.
26+
27+
## `sap.ui.testrecorder.ControlTree` API
28+
29+
**`ControlTree.search(query)`** — Search the live UI5 control tree.
30+
- Returns `Promise<string>` — a tree snapshot with matching controls and their parents
31+
- `query=""` returns the full tree; `query="anchorBar"` returns filtered results
32+
- Matches against control type short names, non-default property values, and accessibility attributes
33+
- Each node carries a `nodeId="N_M"` (snapshot N, node M) — use these in `ControlTree` methods that require a `nodeId` parameter
34+
35+
**`ControlTree.getControlData(nodeId)`** — Get selector and full control state.
36+
- Returns `Promise<{ selectorSnippet, properties, aggregations, associations, bindings }>`
37+
- `selectorSnippet` — OPA5 `waitFor` code to locate the control (use as the base selector)
38+
- Other fields provide live control state for customizing assertions
39+
40+
**`ControlTree.press(nodeId, settings?)`** — Press a control and get its OPA5 action snippet.
41+
- Returns `Promise<string>` — an OPA5 `waitFor` snippet with `actions: new Press()`
42+
- Also **replays the press** on the running app, advancing the UI state for the next search
43+
- Optional `settings`: `altKey`, `ctrlKey`, `shiftKey`, `xPercentage`, `yPercentage`
44+
45+
**`ControlTree.enterText(nodeId, settings)`** — Type into a control and get its OPA5 action snippet.
46+
- Returns `Promise<string>` — an OPA5 `waitFor` snippet with `actions: new EnterText()`
47+
- Also **replays the text entry** on the running app
48+
- `settings`: `text`, `clearTextFirst` (default `true`), `submitText` (default `true`)
49+
50+
## Example Usage
51+
52+
```javascript
53+
sap.ui.require(["sap/ui/testrecorder/ControlTree"], async (ControlTree) => {
54+
"use strict";
55+
// Navigate to the state where the anchor bar is visible, then:
56+
await ControlTree.search("anchorBar"); // When resolved, inspect the returned markdown snapshot and pick nodeId, e.g. Button nodeId="1_8" text="Methods"
57+
58+
// Use the picked nodeId to interact with the corresponding control
59+
await ControlTree.press("1_8"); // When resolved, save the returned OPA5 snippet; UI has now navigated
60+
61+
await ControlTree.search("selectedSection"); // When resolved, parse returned snapshot and pick nodeId, e.g. ObjectPageLayout nodeId="2_3"
62+
63+
await ControlTree.getControlData("2_3"); // When resolved, save result.selectorSnippet + result.associations → build assertion
64+
});
65+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Page Object Organization Across Multiple Views
2+
3+
**ALWAYS** add the new actions/assertions to the semantically corresponding page object
4+
5+
Example 1:
6+
❌ Anti-Pattern:
7+
Adding selector for a control from `App.view.xml` into the page object for its **nested** view (e.g. into `integration/pages/Detail.js` for `Detail.view.xml`):
8+
```javascript
9+
// integration/pages/Detail.js
10+
iShouldSeeTheAppInFullScreenMode() {
11+
return this.waitFor({
12+
id: "layout",
13+
viewName: "App",
14+
success: function () { ... }
15+
});
16+
},
17+
```
18+
✅ Correct Pattern:
19+
Place the assertion for the `App.view.xml` in page object file `integration/pages/App.js`
20+
21+
Example 2:
22+
❌ Anti-Pattern:
23+
View-specific page object file containing selector for cross-view navigation:
24+
```javascript
25+
// integration/pages/Detail.js
26+
iShouldSeeTheHash(sExpectedHash) {
27+
return this.waitFor({
28+
success: function () {
29+
Opa5.assert.strictEqual(Opa5.getHashChanger().getHash(), sExpectedHash, "The Hash not correct");
30+
}
31+
});
32+
},
33+
```
34+
✅ Correct Pattern:
35+
Place the actions/assertions for cross-view navigation into page object `integration/pages/Browser.js`
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Teardown the App
2+
3+
QUnit requires assertions to validate tests. Teardown methods are NOT assertions.
4+
5+
❌ Incorrect:
6+
```javascript
7+
opaTest("Should clean up", function(Given, When, Then) {
8+
Then.iTeardownMyApp(); // ❌ missing assertion (because teardown is not an assertion)
9+
});
10+
```
11+
12+
❌ Incorrect:
13+
```javascript
14+
opaTest("Should assert state and clean up", function(Given, When, Then) {
15+
Then.onTheWorklistPage.iShouldSeeTheTable()
16+
.and.onTheWorklistPage.iTeardownMyApp(); // ❌ chaining on wrong object
17+
});
18+
```
19+
20+
✅ Correct:
21+
```javascript
22+
opaTest("Should assert state and clean up", function(Given, When, Then) {
23+
Then.onTheWorklistPage.iShouldSeeTheTable() // ✅ assertion before teardown
24+
.and.iTeardownMyApp(); // ✅ correct chaining
25+
});
26+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Set Up Browser Inspection Tools
2+
3+
**Prerequisites:** A tool to load the OPA5 test in the browser and evaluate javascript in the browser window (e.g. MCP Playwright)
4+
5+
## 1. Set Up TestRecorder Tooling (UI5 version ≥ 1.147 only)
6+
**Purpose:**
7+
- Diagnose issues by inspecting the live control tree in the browser, including private/internal controls the test needs to find;
8+
- Collect reliable OPA5 snippets for non-trivial actions and assertions.
9+
**Setup:** Follow `enable-testrecorder-tooling.md` for detailed instructions.
10+
11+
## 2. Enable Pause-on-Failure Mode (all UI5 versions)
12+
**Purpose:** When enabled, execution pauses on the first test failure and the app remains live in the browser exactly as it was at the point of failure — no teardown, no reload happens automatically. The paused state persists until you explicitly navigate away, so you can inspect the actual UI directly (without reloading) in the browser to see why it differs from what the test expected.
13+
**Setup:** Add the following line to your test entry point (right before `Opa5.extendConfig`):
14+
```javascript
15+
// Inside the existing sap.ui.define callback in your test entry point
16+
sap.ui.test.qunitPause.pauseRule = "assert,timeout"; // enables pause on assertion failures and timeouts
17+
// Opa5.extendConfig({...});
18+
```
19+
20+
## Workflow
21+
1. Enable the inspection tools above and load the test in the browser.
22+
2. When the test pauses on failure, inspect the app in the browser. Before changing any code, verify the full causal chain with no gaps. Rule out app-side issues before assuming the test is wrong.
23+
3. Iterate on the test until all journeys pass.
24+
4. Once all journeys pass, remove the `sap.ui.testrecorder` library from the app and the pause-on-failure rule `sap.ui.test.qunitPause.pauseRule`.

0 commit comments

Comments
 (0)