webdriverio / webdriverio/webdriverio

[🐛 Bug]: `multiRemoteBrowser.addLocatorStrategy` throws `scope.strategies.get is not a function`

Open
#15,540 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug 🐛 multi remote
Dominant language
TypeScript
Stars
9.8k
Forks
2.7k
Avg merge
2d 13h
Merged PRs (30d)
69

Description

Have you read the Contributing Guidelines on issues?
WebdriverIO Version

latest

Node.js Version

latest

Mode

Standalone Mode

Which capabilities are you using?
N/A
What happened?

Adding a LocatorStrategy on a multi-remote browser throws scope.strategies.get is not a function. It sounds like this is not supported. Moreover, not sure how this should behave, or if it should just not exist...

What is your expected behavior?

Either it does not crash, or addLocatorStrategy is not on the interface since it is not a thing

How to reproduce the bug.
                it('should addLocatorStrategy on multi-remote', async () => {
                    multiRemoteBrowser.addLocatorStrategy('selectHeader', (selector: any) => document.querySelector(selector) as HTMLElement)
                })
Relevant log output
TypeError: scope.strategies.get is not a function
    at MultiRemoteDriver.addLocatorStrategy (webdriverio/packages/webdriverio/build/node.js:9926:26)
    at Context.<anonymous> (webdriverio/e2e/wdio/headless/multiRemoteTest.e2e.ts:322:40)
    at Context.executeAsync (webdriverio/packages/wdio-utils/build/index.js:1133:10)
    at Context.testFrameworkFnWrapper (webdriverio/packages/wdio-utils/build/index.js:1213:34)
Code of Conduct
  • I agree to follow this project's Code of Conduct
Is there an existing issue for this?
  • I have searched the existing issues
Potential Fix

The below changes around https://github.com/dprevost-LMI/webdriverio/blob/5a12a5e5b341cda14d3076f8f48a19da7f8f8a83/packages/webdriverio/src/multiremote.ts#L78, fixes the issue but the question is more: how should locator strategy behavior on multi-remote before fixing this issue

        // Fixes `Cannot read properties of undefined (reading 'get')`
        const strategies = wrapperClient.__propertiesObject__.strategies?.value
        propertiesObject.strategies = {
            value: strategies instanceof Map ? strategies : new Map()
        }

        for (const commandName of wrapperClient.commandList) {
            // Fixes `scope.strategies.get is not a function`
            if (typeof wrapperClient[commandName] !== 'function') {
                continue
            }

            propertiesObject[commandName] = {
                value: this.commandWrapper(commandName),
                configurable: true
            }
        }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/webdriverio/src/multiremote.ts around line 78 and reproduce the failure from the multiRemoteTest.e2e.ts case at line 322. Determine the intended multi-remote behavior for addLocatorStrategy, then add regression coverage showing that behavior and verify the scope.strategies error no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.