webdriverio-community / wdio-vscode-service

A service to test VSCode extensions from end to end using WebdriverIO
https://webdriverio-community.github.io/wdio-vscode-service/
MIT License
29 stars 22 forks source link

TreeItem `getActionButton` results in a `TypeError: Cannot read properties of null (reading 'indexOf')` #121

Open tylor-metrics opened 4 weeks ago

tylor-metrics commented 4 weeks ago

I have run into an issue, not 100% sure that I have identified the root cause correctly yet though, so this may be a red-herring.

However, this change did help me move forward.

The getActionButton function in the TreeItem class in pageObjects/sidebar/viewItem.js appears to throw because it is unable to find an action Button.

Current:

    async getActionButton(label) {

        const actions = await this.getActionButtons()
        if (actions.length > 0) {
            return actions.find((item) => item.getLabel().indexOf(label) > -1)
        }
        return undefined
    }

Suggested Change:


    async getActionButton(label) {
        const actions = await this.getActionButtons()
        if (actions.length > 0) {
            for (let item of actions) {
                let itemLabel = await item.getLabel() ?? await item.elem.getAttribute('aria-label');
                if (itemLabel.indexOf(label) > -1) {
                    return item;
                }
            }
        }
        return undefined;
    }

This basically, checks both the label and the aria-label.

However, that begs the question, why (in my case) is it not finding the button by label currently? I am still not sure yet.

This is what the DOM ends up looking like. The label prop passed to getActionButton(label) is the text in the aria-label such as Action Item 1 or Action Item 2.

Screenshot 2024-06-12 at 10 57 32 AM

christian-bromann commented 3 weeks ago

@tylor-metrics thanks for the fix. Please confirm if the change fixes the issue.