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

addCommand does not work for multiremote with wdio testrunner #2073

Merged
merged 2 commits into from Dec 5, 2018

Conversation

christian-bromann
Copy link
Member

The problem

Custom commands, registered via the addCommand on the global multi browser instance in wdio testrunner, does not work for the respective browser instances. Seems like the command is not registered on each single browser instance.

But it's working fine in standalone mode.

The following code fails in wdio-testrunner in multiremote mode:

browserA = browser.select("browserA");
browserB = browser.select("browserB");

browser.addCommand("myCustomCommand", async function () {
  await this.pause(500);
});

browser.myCustomCommand() // works, executes custom commands on all browsers

browserA.myCustomCommand() // does not work -> browserA.myCustomCommand is not a function
browserB.myCustomCommand() // does not work -> browserB.myCustomCommand is not a function

I created a sample repo to reproduce (see below).

Environment

Link to Selenium/WebdriverIO logs

1) multiremote custom command called on browserA should work:
browserA.myCustomCommand is not a function

Code To Reproduce Issue

https://github.com/zinserjan/webdriverio-multiremote-experiments

@amitaibu
Copy link

amitaibu commented Aug 1, 2017

Hi @christian-bromann !

Is there a plan to make this work soon? Currently if we want to convert tests to multi remote, we have to duplicate the custom commands, and keep tabs at what is core and what is custom.

@christian-bromann
Copy link
Member

@amitaibu I recommend to use page objects instead of custom commands. This has not a high priority.

@amitaibu
Copy link

amitaibu commented Aug 1, 2017

Indeed we're using page objects. I was just hoping to remove some of the duplication, but as there's already a solution it's good enough for now. Thanks for the update!

btw, would be interesting to see one day how you execute multiremote on TVs 😉

@christian-bromann christian-bromann added help wanted Issues that are free to take by anyone interested webdriverio Bug 🐛 and removed Enhancement labels Sep 18, 2018
@christian-bromann christian-bromann self-assigned this Dec 4, 2018
@christian-bromann
Copy link
Member

There was indeed an issue not being able to register custom command on a multiremote instance. E.g.

    matrix.addCommand('go', async function (url) {
        await this.url(url + '#custom')
        await this.pause(4000)
        return this.getCurrentUrl()
    })

Would still not attach the go function to the multiremote instance. This was not a problem when using standard WebdriverIO.

The behavior described by @zinserjan in the initial issue still exists though. After some testing I realised that this would be not a nice experiences because the return value of a multiremote command call is always an array of results. So you would never be able to use the same logic with a multiremote instance than with a standard one, e.g.

browser.addCommand('myCustomCommand', async function (param) {
    const commandResult = await this.execute(() => 'foobar')
    return { param, commandResult }
})

commandResult would be ['foobar', 'foobar'] in multiremote but in normal just foobar. Therefor the custom command function can't be used in both modes.

I think this is ok and an expected behavior.

@codecov
Copy link

codecov bot commented Dec 4, 2018

Codecov Report

Merging #2073 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2073      +/-   ##
==========================================
+ Coverage   96.38%   96.38%   +<.01%     
==========================================
  Files         124      124              
  Lines        2652     2656       +4     
  Branches      547      548       +1     
==========================================
+ Hits         2556     2560       +4     
  Misses         87       87              
  Partials        9        9
Impacted Files Coverage Δ
packages/webdriverio/src/index.js 93.93% <100%> (+0.83%) ⬆️
packages/webdriver/src/monad.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00ed9de...fea604d. Read the comment docs.

Copy link
Member

@abjerstedt abjerstedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing stands out to me

@christian-bromann christian-bromann merged commit 37a2dfe into master Dec 5, 2018
@christian-bromann christian-bromann deleted the cb-multiremote-fix branch December 5, 2018 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 help wanted Issues that are free to take by anyone interested webdriverio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants