cypress-browser-extension-plugin icon indicating copy to clipboard operation
cypress-browser-extension-plugin copied to clipboard

Support Cypress v4

Open Strajk opened this issue 4 years ago • 5 comments

Hey, first of all, thx for amazing work on this plugin 👏

Cypress changed before:browser:launch hook in v4, this will make it work

https://github.com/cypress-io/cypress/pull/6293

Strajk avatar Jul 13 '20 05:07 Strajk

Another approach would be to use the following section in cypress/plugins/index.js

const extensionLoader = require('cypress-browser-extension-plugin/loader');

on('before:browser:launch', (browser = {}, launchOptions) => {
    const onBeforeBrowserLaunch = extensionLoader.load({
        source: '/path/to/myext',
        skipHooks: true,
    });

    // explicit call to "browserArgs function" returned by the extensionLoader.load() as we need to 
    // translate the return value for compatibility with Cypress 4.x

    var args = [...launchOptions.args]; // make copy of given args to avoid changing the original array inside onBeforeBrowserLaunch()

    const argsPromise = onBeforeBrowserLaunch(browser, args);

    const launchOptionsPromise = argsPromise
        .then(function(args) {
            launchOptions.args = args;

            return launchOptions;
        });

    return launchOptionsPromise;    
})

Hope this helps others as it seems that the repo owner doesn`t care.

ViRuSTriNiTy avatar Jul 21 '20 21:07 ViRuSTriNiTy

@ViRuSTriNiTy cool solution! 👏

But thas comment at the end was really not needed.

Strajk avatar Jul 23 '20 18:07 Strajk

Hi, just wanted to know if there still was a plan to merge this pr?

hitmands avatar Oct 12 '20 13:10 hitmands

@ejoubaud small little ping :))

btw if you would like to, I can help with maintaining this project. I'm avid user of Cypress and have a lot of experience with it from both large and small projects. It's such a useful plugin that is helping so many people, would be a honor to help :)

Strajk avatar Oct 13 '20 07:10 Strajk

another way of fixing this issue is just changing the documentation:

  on('before:browser:launch', async (browser = {}, launchOptions) => {
    const loader = extension.load({
      source: '/path/to/xt'
      alias: 'coolExtension'
    });

    const args = await loader(browser, []);

    launchOptions.args.push(...args);

    return launchOptions;
  });

https://github.com/ejoubaud/cypress-browser-extension-plugin/issues/5#issuecomment-707320648

hitmands avatar Oct 13 '20 08:10 hitmands