Your automated test failures highlight three interconnected challenges with testing extended Fiori applications. Here’s a comprehensive solution addressing each layer:
1. Fiori UI5 Extension Impact on Test Automation:
UI5 flexibility extensions introduce dynamic element generation that breaks traditional Selenium selectors. When you extend a standard Fiori app, the framework:
- Generates unique view IDs for each session/instance
- Applies extension fragments asynchronously after base app loads
- Creates composite IDs combining view prefix + control ID + suffix
- May render controls in different DOM positions than expected
Your error shows the classic symptom: input[id*='customCostCenter'] fails because the actual ID is __xmlview2--customCostCenter-inner which changes between test runs.
2. Automated Test Script Maintenance Strategy:
Implement a three-tier selector strategy:
Tier 1 - Add Stable Test Attributes (Development Phase):
Modify your UI5 flexibility extension to include test hooks:
<Input id="customCostCenter"
value="{CostCenter}"
data-test-id="schedule-cost-center"
data-test-type="input"/>
This requires updating your extension definition but provides maximum stability.
Tier 2 - UI5-Aware Selectors (Current Tests):
Update Selenium tests to use UI5-specific selector patterns:
// Instead of exact ID match
driver.findElement(By.id('customCostCenter'))
// Use partial match with control-specific suffix
driver.findElement(By.css('[id$="customCostCenter-inner"]'))
// Or use UI5 control properties
driver.findElement(By.css('input[data-sap-ui*="CostCenter"]'))
Tier 3 - Smart Waits for Async Rendering:
Implement UI5-aware wait conditions:
const waitForUI5Ready = async () => {
await driver.wait(() => {
return driver.executeScript(
'return window.sap && sap.ui.getCore().isInitialized()'
);
}, 10000);
await driver.wait(() => {
return driver.executeScript(
'return sap.ui.getCore().getUIDirty() === false'
);
}, 5000);
};
3. OData Service Metadata Synchronization:
Verify the backend metadata reflects your extensions:
Check metadata exposure:
/sap/opu/odata/sap/ZSCHEDULE_SRV/$metadata
Look for your custom properties:
<Property Name="CostCenter" Type="Edm.String" MaxLength="10"/>
<Property Name="ProjectCode" Type="Edm.String" MaxLength="24"/>
If missing, the UI5 extension might be client-side only. For proper testing, extend the OData service backend:
- Extend CDS view to include custom fields
- Regenerate OData service with transaction SEGW
- Clear metadata cache in /IWFND/MAINT_SERVICE
- Refresh Fiori app metadata in /UI5/APP_INDEX_CALCULATE
Comprehensive Test Suite Update:
Phase 1 - Immediate Fix (works with current code):
Update test selectors to use suffix matching and add explicit waits:
await waitForUI5Ready();
const costCenterField = await driver.findElement(
By.css('input[id$="customCostCenter-inner"]')
);
await driver.wait(until.elementIsVisible(costCenterField), 5000);
await costCenterField.sendKeys('CC-12345');
Phase 2 - Sustainable Solution (requires dev coordination):
- Add
data-test-id attributes to all custom UI5 controls
- Create a test selector library mapping logical names to test IDs
- Implement page object pattern with UI5-aware element location
- Add metadata validation tests that verify OData service exposes custom fields
- Create UI5 initialization helpers for consistent wait strategies
Phase 3 - Framework Migration (long-term):
Consider migrating to UI5-native test frameworks:
- UIVeri5: SAP’s official UI5 test framework with built-in control recognition
- Wdi5: WebDriver bridge for UI5 with selector API based on control properties
- OPA5: For unit/integration testing during development
These frameworks understand UI5 control lifecycle and extension mechanisms, eliminating selector brittleness.
Root Cause Summary:
Your tests fail because:
- UI5 flexibility generates dynamic IDs that change between sessions
- Extension controls render asynchronously after base app initialization
- Selenium’s standard waits don’t account for UI5’s rendering lifecycle
- Test selectors assume static IDs from standard (non-extended) apps
The solution requires both immediate selector fixes and architectural changes to your test framework for long-term maintainability of extended Fiori app testing.
This draft is based on general SAP S/4HANA knowledge. It has not been verified against your specific version and environment. Practitioners: verify the steps and share your experience below.