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

christian-bromann commented Dec 4, 2018

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

christian-bromann commented Aug 1, 2017

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

@amitaibu

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

christian-bromann commented Dec 4, 2018

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

This comment has been minimized.

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.

v5 Release automation moved this from In progress to Reviewer approved Dec 5, 2018

@abjerstedt
Copy link
Member

abjerstedt left a comment

Nothing stands out to me

christian-bromann added some commits Dec 4, 2018

@christian-bromann christian-bromann force-pushed the cb-multiremote-fix branch from a0b1955 to fea604d Dec 5, 2018

@christian-bromann christian-bromann merged commit 37a2dfe into master Dec 5, 2018

5 checks passed

codecov/patch 100% of diff hit (target 96.38%)
Details
codecov/project 96.38% (+<.01%) compared to 00ed9de
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
licence/cla Contributor License Agreement is signed.
Details

v5 Release automation moved this from Reviewer approved to Done Dec 5, 2018

@christian-bromann christian-bromann deleted the cb-multiremote-fix branch Dec 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.