Skip to content
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

Cypress --browser option not working on Windows when given a path argument #6389

Closed
amrsa1 opened this issue Feb 10, 2020 · 20 comments · Fixed by #8743
Closed

Cypress --browser option not working on Windows when given a path argument #6389

amrsa1 opened this issue Feb 10, 2020 · 20 comments · Fixed by #8743
Labels
existing workaround good first issue Good for newcomers OS: windows pkg/launcher This is due to an issue in the packages/launcher directory type: bug

Comments

@amrsa1
Copy link

amrsa1 commented Feb 10, 2020

Current behavior:

im running the following command after updating cyrpess to 4.0.1
npm run cypress --browser c:\Users\amrka\appData\local\Mozilla Fireforx\firefox.exe
but still unable to see firefix among the list of browser in cypress

part of the log

C:\Users\amrka\Desktop\ATT MNC\mc-testing-framework>npm run cypress --browser c:\Users\amrka\appData\local\Mozilla Fireforx\firefox.exe

mc-testing-framework@1.0.0 cypress C:\Users\amrka\Desktop\ATT MNC\mc-testing-framework
cypress open "Fireforx\firefox.exe"

image

Desired behavior:

I should be able to see firefox among browser list in cypress

Versions

Firefox

@flotwig
Copy link
Contributor

flotwig commented Feb 10, 2020

@amrkamel1 how did you install Firefox? I haven't seen it at this path before. Currently, Cypress will only look for Firefox installed in Program Files, which is why you are running into this.

@flotwig
Copy link
Contributor

flotwig commented Feb 10, 2020

Actually, it seems like --browser is broken on Windows, so passing a path will not work here.

@flotwig flotwig changed the title Still cypress is unable to detect firefox on windows Cypress --browser option not working for Firefox on Windows Feb 10, 2020
@flotwig
Copy link
Contributor

flotwig commented Feb 10, 2020

I spent some time looking in to why --browser doesn't work on Windows. It comes down to how we determine what type of browser was passed, so we know how to automate it.

This logic in the launcher is used to filter browsers:

const detectBrowserByVersionString = (stdout: string): FoundBrowser => {
const browser = find(goalBrowsers, (goalBrowser: Browser) => {
return goalBrowser.versionRegex.test(stdout)
})
if (!browser) {
throw notDetectedAtPathErr(stdout)
}

This works for Linux and macOS, because stdout is something like 'Mozilla Firefox 72.0a1'. But on Windows, stdout will be Version=72.0.0001 or similar, since it comes from wmic.

Since google-chrome --version and firefox --version don't work on Windows, we have to keep using WMIC.

The core issue here is that there needs to be some way for the launcher to determine what browser is passed. There could be a naive check, like if the path contains "firefox", assume it's firefox.

Or there could be a convention like --browser firefox:C:\Program Files\Mozilla Firefox\firefox.exe.

Open to ideas on how to detect the browser type, so --browser on Windows can be fixed.

@amrsa1
Copy link
Author

amrsa1 commented Feb 10, 2020

@amrkamel1 how did you install Firefox? I haven't seen it at this path before. Currently, Cypress will only look for Firefox installed in Program Files, which is why you are running into this.

Nothing regular flow i have downloaded firefox installer then install it by default it went to that path stating above and its not in programeFiles but anyway will try again install it in program files

update :

its working fine when i have changed the path to C:\Program Files\Mozilla Firefox\firefox.exe

@arvinder06
Copy link

arvinder06 commented Feb 12, 2020

For me it hangs after below and nothing happen. Windows 10
using --browser firefox --headless
(without headless it is working fine)


  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    4.0.1                                                                              │
  │ Browser:    Firefox 73 (headless)                                                              │
  │ Specs:      1 found (login.spec.js)                                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  login.spec.js                                                                   (1 of 1)
undefined
Your project has set the configuration option: `chromeWebSecurity: false`

This option will not have an effect in Firefox. Tests that rely on web security being disabled will not run as expected.
undefined

@AaronRohrbacher
Copy link

AaronRohrbacher commented Feb 24, 2020

@amrkamel1 how did you install Firefox? I haven't seen it at this path before. Currently, Cypress will only look for Firefox installed in Program Files, which is why you are running into this.

Nothing regular flow i have downloaded firefox installer then install it by default it went to that path stating above and its not in programeFiles but anyway will try again install it in program files

update :

its working fine when i have changed the path to C:\Program Files\Mozilla Firefox\firefox.exe

Users on (annoying) Windows GPOs, such as myself, will often have Firefox installed in their user-local AppData folders (C:\Users\[windows user name]\AppData\Local\Mozilla Firefox). Would be great if a fix came available for us!

@flotwig
Copy link
Contributor

flotwig commented Feb 25, 2020

@AaronRohrbacher I haven't tried it, but I believe this should work in the meantime if you add it to your plugins file:

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

  config.browsers.push({
    name: 'firefox',
    family: 'firefox',
    channel: 'stable',
    displayName: 'Firefox',
    version: '73.0.1',
    path: 'C:\\Users\\[windows user name]\\AppData\\Local\\Mozilla Firefox\\firefox.exe',
    majorVersion: '73'
  })

  return config
}

https://docs.cypress.io/guides/guides/launching-browsers.html#Customize-available-browsers

@jennifer-shehane jennifer-shehane changed the title Cypress --browser option not working for Firefox on Windows Cypress --browser option not working on Windows Mar 11, 2020
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Mar 11, 2020
@kyle-mcknight
Copy link

kyle-mcknight commented Mar 12, 2020

Will this work for cypress run? The docs only mention it for cypress open. I would need it to work with run for CI. And does it have to be an absolute path? This isn't much of a workaround for actual projects if so :/

@kyle-mcknight
Copy link

Will this work for cypress run? The docs only mention it for cypress open. I would need it to work with run for CI. And does it have to be an absolute path? This isn't much of a workaround for actual projects if so :/

I've answered my own question, it does not have to be an absolute path and it does work with cypress run

@jennifer-shehane jennifer-shehane changed the title Cypress --browser option not working on Windows Cypress --browser option not working on Windows when given a path argument Mar 12, 2020
@flotwig
Copy link
Contributor

flotwig commented Mar 12, 2020

After discussing with the team a bit, I think the way we can go about fixing this issue on Windows is using the .exe name to determine the expected browser type.

For example, for these paths:

  • C:\...\firefox.exe would launch it as Firefox
  • C:\...\chrome.exe would launch it as Chrome

@EmmanuelDemey
Copy link

We are facing the same problem. When trying to use chromium, it looks like the wmic command do not return the version on Windows, but launch the browser itself.

@flotwig flotwig added the good first issue Good for newcomers label May 20, 2020
@flotwig flotwig removed their assignment May 20, 2020
@flotwig flotwig added the pkg/launcher This is due to an issue in the packages/launcher directory label May 20, 2020
@stevejefferies
Copy link

Ran into this earlier today and started to look into this. @flotwig would your suggested fix of using the executable name work in the case of chrome vs chromium given both would be detected as chrome? (both are chrome.exe by default).

From a WMIC perspective both Chrome and Chromium appear identical so is hard to detect between the two. The only difference in the two is the author field ("The Chromium Authors" vs "Google LLC") which feels a little hacky, but would provide enough of a basis to differentiate.

@flotwig
Copy link
Contributor

flotwig commented May 22, 2020

Ran into this earlier today and started to look into this. @flotwig would your suggested fix of using the executable name work in the case of chrome vs chromium given both would be detected as chrome? (both are chrome.exe by default).

Good point, though it would only be a cosmetic issue, Chrome and Chromium are treated identically in Cypress.

From a WMIC perspective both Chrome and Chromium appear identical so is hard to detect between the two. The only difference in the two is the author field ("The Chromium Authors" vs "Google LLC") which feels a little hacky, but would provide enough of a basis to differentiate.

We could use the filename matching in addition to an extra WMIC column to determine if it's Chromium or Chrome based on the author field...

...this is starting to feel kinda hacky, I think we just need a way for users to specify the browser's name straight up, instead of adding more things to try and autodetect it. I think a convention like this could work:

  • --browser=C:\foo\firefox.exe -> launches as Firefox
  • --browser=C:\foo\chrome.exe -> launches as Chrome
  • --browser=C:\foo\chrome.exe:chromium -> launches as Chromium
  • --browser=C:\foo\bar.exe -> errors and complains about not being able to tell what kind of browser it is, shows examples of correct usage
  • --browser=C:\foo\bar.exe:chrome -> launches as Chrome

@codenamics
Copy link

Hey,

Any update on that? workarounds are not working for me?

@flotwig
Copy link
Contributor

flotwig commented Jul 27, 2020

@codenamics Nobody from the team is currently working on this, but we would welcome a PR that implements the fix described in #6389 (comment)

@Nashati
Copy link

Nashati commented Sep 23, 2020

Hi,
Any update on this?
does the latest version have the same issue?

@Zacharias3690
Copy link
Contributor

I'd like to give this a shot.

@flotwig
Copy link
Contributor

flotwig commented Oct 2, 2020

@Zacharias3690 feel free to go ahead and open a PR. Tag me if you have any questions about the repo that are not answered by the CONTRIBUTING.md.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 9, 2020

The code for this is done in cypress-io/cypress#8743, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Oct 9, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 14, 2020

Released in 5.4.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.4.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
existing workaround good first issue Good for newcomers OS: windows pkg/launcher This is due to an issue in the packages/launcher directory type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.