cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.8k stars 3.17k forks source link

Support browser specific protocols (chrome extensions) #1965

Open kuceb opened 6 years ago

kuceb commented 6 years ago

Support cy.visit() with protocols other than http/https such as:

Most notably, chrome-extension:// will allow users to test the UI of a chrome extension.

NorseGaud commented 1 year ago

Wow, this is an old thread... I have a need to "visit" a chrome-extension:// URL and load the extension in the current window. I don't need anything else and can run all of my tests once it's loaded. Nothing more, nothing less.

NorseGaud commented 1 year ago

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 https://github.com/request/request/issues/3142

The best thing for these new modules is for request to slowly fade away, eventually becoming just another memory of that legacy stack. Taking the position request has now and leveraging it for a bigger share of the next generation of developers would be a disservice to those developers as it would drive them away from better modules that don’t have the burden of request’s history.

NorseGaud commented 1 year ago

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: Load the following code in cypress/plugins/index.js

const axios = require('axios');
const puppeteer = require('puppeteer');
. . .

This doesn't work. Even with the tweaks to get it to work with the latest puppeteer,await theFrame.goto never completes and all you see is the following with an eventual timeout

Screen Shot 2022-11-22 at 8 51 01 PM
NanoRoss commented 1 year ago

Did you manage to make it work?