-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Support browser specific protocols (chrome extensions) #1965
Comments
There's also Add support for testing chrome extensions but it's closed. |
@JulianG that issue was for testing content scripts, which is currently possible. But yeah this is the other half of Chrome extensions |
Would love to see support for this added! |
I’d be very keen to see this - you can already make a fair bit of headway with extensions, but this would be the icing on the cake. |
I would love to see this ability. It would be so great. |
Curious, which pages are you most wanting to test? background.html? popup.html? |
@bkucera For my own use case, I would be able to run Cypress on my extension's popup in order to see if:
I tried Also, Having access to Thanks you for taking time on this. 🙂 |
@bkucera Exactly. My chrome extension uses (In my case it's neither |
In my case I want to test via One thing I had hoped to do was call |
Thanks everyone for the input. I think the use case of @Kocal can currently be done by stubbing |
My popup is now successfuly tested, thanks you all! 😎 Some tips for people who wants to spec their extension's views and mocking
{
"baseUrl": "http://localhost:5000"
}
describe('App', () => {
before(() => {
// Load your popup
cy.visit('/popup/popup.html', {
// If you need to stub `chrome*` API, you should do it there:
onBeforeLoad(win) {
win.chrome = win.chrome || {};
win.chrome.runtime = {
sendMessage(message, cb) {
// ...
cb(some_data);
},
};
},
});
});
}); |
Have you stubbed chrome.* in the end? |
Well, I only use EDIT: some times ago I used jest-webextension-mock for mocking |
I have used sinon-chrome before, it works well for unit/IT testing. Not sure how it compares to jest-webextension-mock. |
For me, the use case would not be testing an extension but testing our app with an extension I want to be able to click some buttons on the extension etc while navigating through our app |
I can see both use cases being strong. Say you're developing an extension that has some UI flows in the popup, it gets pretty annoying to manually test those each time by clicking the extension icon! Regressions are so hard to notice because of the nature of the popup. With Cypress interface, I'd spot the regressions by just running the test command, and notice exactly where it happens. On the other side, you're obviously developing an extension to enhance a browser -- and websites as a result -- so running an "example site" inside Cypress with the extension loaded could be useful to notice things like what the extension might inject, etc. like what @Moejoe90 is suggesting. @bkucera is this being actively worked on? Is there anything the community can do to support? |
@callmenick I'm working on testing a chrome extension that injects html into a third party site, but no Test Runner features are being developed yet. Most likely I'll end up using something from here to allow the extension to detect content in the AUT (application under test), which cypress puts in an iframe |
Cool, thanks for the update. I'm personally interested in the first point, supporting extension protocols so I can visit |
@callmenick you can check #1965 (comment) I guess |
Yeah that's what we're doing now as well @Kocal. Thanks for that! |
Hey everyone, I was able to set up a good workflow (see however below*) for testing chrome extensions that inject HTML onto third party sites. For example, to test an extension that injects HTML inside of Gmail, there were a few things I had to do:
|
Similar to @callmenick above, I'm curious about whether or not Cypress can support simply visit a HTML page from a Chrome extension. If an extension has an HTML page listed in its |
can you share the repository name of this |
Serving doesn't work. The browser says "local" and some specific Chrome extension APIs are undefined... |
For those who are still looking for alternatives or ideas... Try binding puppeteer on a CDP session from the plugins scope, it will enable you to access the Something like this... const { data: debuggerInfo } = await axios.get(
`http://localhost:${this.config.debugPort}/json/version`
)
this.browser = await puppeteer.connect({
browserWSEndpoint: debuggerInfo.webSocketDebuggerUrl,
ignoreHTTPSErrors: true,
defaultViewport: null,
}) Then you would access extension pages from puppeteer instead of cypress, do clicks and stuff, but still using and testing with cypress. |
Is there any news on this issue? Really would like to be able to test my extension. |
can someone please explain how to build the extension and point server to it's dist folder |
is there any guide to implement this ? |
I've switched over to Nightwatch for now. |
same question as @Iskandar47 , any specific guidelines? The introduction is kinda vague and cannot replicate |
Sorry for the late response @Iskandar47 and @Depetrol... The snippet shared corresponds to an issue related to CDP sessions in synpress... The actual implementation is better understood in synpress code at the moment I don't have enough time to do a demo but is basically the same... The solution uses cypress plugins and puppeteer, cypress reveals a WS socket for debugging purposes and the solution then connects that WS endpoint to puppeteer to control the browser in puppeteer side... |
Our team have successfully loaded the browser extension page in cypress: The reason why chrome-extension:// is blocked: cypress runs in-browser and is blocked by chrome security policies Solution: use puppeteer to control the browser behavior externally with CDP (Chrome Devtools Protocol), bypassing the security limitations. Here's how to do it:
run the following code before each test
|
@Depetrol were you able to run these tests in the CI? For me everything works on local (in a fully dockerised setup), but when running in Github Actions it seems that the extension never gets loaded (or at least Puppeteer doesn't find the second tab with the extension within 60 seconds; it's hard to say what's really happening, because Cypress` video/screenshot only includes browser's viewport). |
@Depetrol cool! This looks like what other people try to do with Playwright as well. Here's an example on how to dynamically get the extensionId: https://github.com/xcv58/Tab-Manager-v2/blob/master/packages/integration_test/util.ts#L51-L55 I recently tried Playwright/Puppeteer and Cypress/Puppeteer and both was working ok. Biggest issue I've noticed for both approaches was that neither could provide the screenshots/videos on fail or or a nice trace of commands. I beleive this happens because Puppeteer is taking over. Not sure though. Did you get i.e. screenshots on fail or the commands-trace with your Cypress approach? Is that's what the |
@Tofel Yes. Try to install a new version of Chrome. |
@escapedcat Yes. Cypress will automatically capture screenshots when a failure happens during |
Yeah, that's the default, right? When I tested it using puppeteer (to test an extension) it didn't. It also didn't show a nice command path in the left panel like I'm used to. Might need to try again. |
No it's not ;-) Cypress knows nothing about Puppeteer, which is used to communicate with MetaMask, so it will never take the screenshot of the extension (regardless whether it's the separate tab it's running in or the notification). |
I wished it was that easy, Chrome 101 has memory leaks, which makes it unusable :/ |
@Tofel right, I think that's what i meant. If you use Cypress only per default Cypress will do all these things but once you handle everything with Puppeteer Cypress doesn't get these infos anymore and won't create i.e. screenshots on fail. |
Wow, this is an old thread... I have a need to "visit" a |
The more I dig in the code, it looks like this may be a change to https://www.npmjs.com/package/@cypress/request which seems to do the request and throw the error. Furthermore, it seems like the maintainer wants people moving away from it request/request#3142
|
Did you manage to make it work? |
Support
cy.visit()
with protocols other thanhttp
/https
such as:chrome://
chrome-extension://
resource://
Most notably,
chrome-extension://
will allow users to test the UI of a chrome extension.The text was updated successfully, but these errors were encountered: