Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you "visit" a chrome-extension when testing with Cypress?

I'm trying to test my chrome-extension using cypress.io

I can successfully load my extension by adding this to plugins/index.js:

module.exports = (on, config) => {
  on('before:browser:launch', (browser = {}, args) => {
    if (browser.name === 'chrome') {
      args.push('--load-extension=../bananatabs/build')
      return args
    }
  })
}

I can open my extension's index.html on the cypress browser by navigating to chrome-extension://ewoifjflksdjfioewjfoiwe/index.html

But when I try to "visit" it in a test, like this:

context('visit bananatabs', () => {
    beforeEach(() => {
      cy.visit('chrome-extension://inbalflcnihklpnmnnbdcinlfgnmplfl/index.html')
    })

    it('does nothing', () => {
        assert(true);
    });

});

it doesn't work. page reads:

Sorry, we could not load: chrome-extension://inbalflcnihklpnmnnbdcinlfgnmplfl/index.html

In the docs all the examples use http or https protocols, not chrome-extension.

UPDATE

I can see the test page is http://localhost:54493/__/#/tests/integration/visit.spec.js and it contains an iframe with the page I'm testing, which uses chrome-extension:// protocol. I'm not sure that would ever work.

Can this be done?

like image 413
JulianG Avatar asked Jun 15 '18 14:06

JulianG


People also ask

How do I add Chrome extensions to Cypress?

In your project's supports file:const addExtensionCommands = require('cypress-browser-extension-plugin/commands'); addExtensionCommands(Cypress); That's all you need to load a single extension now run cypress by hitting following command. Select the spec file, loadChromeExtension.

Does Cypress work with Chrome?

Cypress currently supports Firefox and Chrome-family browsers (including Edge and Electron). To run tests optimally across these browsers in CI, check out the strategies demonstrated in the cross browser Testing guide.

How do I open Chrome in Cypress?

To launch chromium, run cypress run --browser chromium. To launch Chrome Canary, run cypress run --browser chrome:canary. The Firefox-family browsers have beta support. If you want to use this command in CI, you will need to install these browsers.


1 Answers

Not Currently, but I've opened an issue for just that.

Cypress puts an arbitrary restriction for http/https, and could easily add support for browser specific protocols such as chrome://, resource://, and chrome-extension://

Feel free to throw a :+1: on it!

like image 144
bkucera Avatar answered Sep 19 '22 15:09

bkucera