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?
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.
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With