Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getObject() not working on contexts retrieved from getContexts() in wdi5 #660

Open
CPUCloudCode opened this issue Feb 28, 2025 · 1 comment

Comments

@CPUCloudCode
Copy link

Describe the bug
When retrieving row contexts from a UI5 table (e.g. sap.ui.table.AnalyticalTable) via getContexts(0, 1),
calling .getObject() on an individual context fails in wdi5, even though it works correctly in the browser console.

To Reproduce
Steps to reproduce the behavior:

  1. Use wdi5 to retrieve a UI5 Table (e.g. Analytical Table) and its binding:
const table = await browser.asControl<Table>({
    selector: {
        controlType: "sap.ui.table.AnalyticalTable",
        interaction: "root"
    }
});
  1. Retrieve row contexts from the "rows" binding:
const binding = await table.getBinding("rows") as ODataListBinding;
const rowContext = await binding.getContexts(0, 1) as any;
  1. Try to get the object directly from the first context:
const singleContext = await rowContext[0];
const object = await singleContext.getObject(); // ❌ Fails here
console.log(object);
  1. See error:
$> TypeError: singleContext.getObject is not a function

Expected behavior
Calling .getObject() on a binding context retrieved from getContexts() should return the corresponding data object, just like when executing the same code in the browser console.

Logs/Console Output
In wdi5:

$> TypeError: singleContext.getObject is not a function

However, in the browser console, this works correctly:

sap.ui.getCore()
  .byId("<tableId>")
  .getBinding("rows")
  .getContexts(0, 1)[0]
  .getObject();

Returns:

{
  "__metadata": { ... },
  "TradingContract": "XXXXX",
  "TradingContractItem": "10",
  "ActiveVariantsCount": 1,
  "Caliber": "11 ST",
  ...
}

Workaround
Instead of using .getObject(), fetching the data manually via getProperty() on the table model works:

const rowPath = rowContext[0].sPath;
const model = await table.getModel();
const rowData = await model.getProperty(rowPath);
console.log("Workaround:", rowData["TradingContract"]); // ✅ Works

It also works if you embedd the function into a browser.execute()

const result = await browser.execute(() => {
    const table = sap.ui.getCore().byId("<tableId>");
        
    const binding = table.getBinding("rows");
            
    if (!binding) {
        console.error("❌ Binding not found");
        return null;
    }
    // @ts-ignore
    const contexts = binding.getContexts(0, 1);
        
    if (contexts.length === 0) {
        console.warn("⚠️ No contexts found.");
        return null;
    }
        
    return contexts[0].getObject();
}) as any;
        
console.log("🚀 UI5 Table Data:", result);

Screenshots
Image

Runtime Env:

  • wdi5/wdio-ui5-service-version: 2.0.10
  • UI5 version: 3.11.5
  • wdio-version (output of wdio --version): 8.41.0
  • node-version (output of node --version): v20.18.1
  • OS: SAP BAS Linux workspace
  • Browser + Version: Mozilla Firefox (115.9.1esr) and geckodriver 0.36.0

Additional context
Here is some more context that can be included in the bug report to help the maintainers understand the issue better.

🔍 Issue Summary

  • The issue occurs when trying to use .getObject() on a context retrieved via .getContexts() in wdi5.
  • The same code works in the browser console but fails in browser.execute() inside wdi5 tests.
  • This suggests a possible limitation in how wdi5 retrieves objects from UI5 models or a WebdriverIO execution context issue.
    💻 WDIO Configuration
capabilities: [
        {
            // maxInstances can get overwritten per capability. So if you have an in-house Selenium
            // grid with only 5 firefox instances available you can make sure that not more than
            // 5 instances get started at a time.
            maxInstances: 1,
            browserName: "firefox",
            "moz:firefoxOptions": {
                args: [
                    "-headless",
                    "--width=1920",
                    "--height=1080",
                    "--disable-gpu",
                    "--no-sandbox",
                ],
                prefs: {
                    "devtools.console.stdout.content": true // Leitet die Konsole nach stdout
                }
            },
            acceptInsecureCerts: true,
            "wdi5:authentication": {
                provider: "BasicAuth",
            },
        }
    ],
@Siolto
Copy link
Collaborator

Siolto commented Mar 4, 2025

Hi @CPUCloudCode,

thanks for the very detailed description! I will have a look at this in the next few days and check if this is a bug or a limitation we need to communicate.

Regards
Simon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants