cypress-io / cypress

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

Passing custom Chrome profile directory (user data dir) not working on Mac and Linux #18308

Open AJM-v opened 3 years ago

AJM-v commented 3 years ago

Current behavior

We would like to use a custom Chrome profile directory for our Cypress tests. The application we are testing uses a Web SQL database which needs to be loaded into the Chrome browser. We tried this command which should be a valid chromium argument.

launchOptions.args.push('--user-data-dir=/Users/testuser/dev/chrome')

But when we run Cypress we see that the Chrome Profile Path is being overwritten by Cypress:

image

Desired behavior

The Chrome Profile Path from the launchOptions '--user-data-dir=/Users/testuser/dev/chrome' is used.

Test code to reproduce

Our setup:

The code we tried in our index.js (plugins folder):

module.exports = (on, config) => {

  on('before:browser:launch', (browser = {}, launchOptions) => {

    launchOptions.args.push('--user-data-dir=/Users/testuser/dev/chrome')

    launchOptions.args.push('--auto-open-devtools-for-tabs')

    return launchOptions
  })

};

Steps to reproduce:

  1. Add launchOptions argument with --user-data-dir like mentioned above
  2. Open Cypress dashboard (npx cypress open)
  3. Run 1 test in Chrome
  4. Chrome browser opens, type chrome://version in URL bar
  5. --user-data-dir=/Users/testuser/dev/chrome is listed in the Command Line panel, but I also see --user-data-dir=/Users/xxxxx/Library/Application Support/Cypress/cy/production/browsers/chrome-stable/interactive listed, and that is the Profile Path which is being used by Cypress

Cypress Version

8.4.0

Other

Also tested on a Windows 10 environment and there this code is working fine when testing headed in Chrome.

AlexMurphy commented 2 years ago

@AJM-v Did you find a solution to this?

We have a use case that also requires custom Chrome profiles,

AJM-v commented 2 years ago

@AJM-v Did you find a solution to this?

We have a use case that also requires custom Chrome profiles,

@AlexMurphy Nope, our dev team is creating a workaround for the app we are testing so that we don't have to use a custom chrome profile.

lughino commented 2 years ago

Same issue here on mac. Cypress team could you have a look please?

mike1936 commented 1 year ago

Same issue on Windows, both --user-data-dir and --remote-debugging-port settings are overwritten.

lucassardois commented 1 year ago

This issue still happen on cypress version 12 when using the run command from the CLI such as npx cypress run --headed --no-exit --browser chrome. I guess it's because when we run cypress it generate a new temp chrome profile to make the test isolated and this override this setting.

Is there any workaround?

zapplebee commented 1 year ago

I can tell that Cypress is intentionally overwriting this arg here.

https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/browsers/chrome.ts#L692

But there seems to be no escape hatch to chose it yourself.

PK-Tests commented 1 year ago

Our case also requires this approach (we are setting up mic permissions before test). I tried running this in plugins/index.js:

export default (on, config) => {
    on('before:browser:launch', (browser = {}, launchOptions) => {
        launchOptions.args.push('--user-data-dir=../chromeProfile/Default');
    })
}
kaviththiranga commented 1 year ago

We have the same requirement. We are trying to run VSCode (Electron) with cypress and we need to override --user-data-dir

cypress-app-bot commented 3 months ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

drptbl commented 3 months ago

This issue is a blocker for many things for us and it's still occurring.

jennifer-shehane commented 3 months ago

We did add an option recently to IGNORE_CHROME_PREFERENCES. You can see the code path here: https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/browsers/chrome.ts#L111C19-L111C44

I haven't tried this specific use case, but it may be an option to opt out of the overwriting behavior that is causing problems with Cypress overwriting. Interested to hear if that works for anyone.