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

Including auth credentials in baseUrl causes browser to never connect in headless mode #1598

Closed
cherednyk-tcm opened this issue Apr 16, 2018 · 16 comments
Labels
type: regression A bug that didn't appear until a specific Cy version release type: user experience Improvements needed for UX

Comments

@cherednyk-tcm
Copy link

cherednyk-tcm commented Apr 16, 2018

Current behavior:

After update of cypress from 1.4.2 to 2.1.0 browser never connected in headless mode.

Console output

(Tests Starting)

Timed out waiting for the browser to connect. Retrying...

Timed out waiting for the browser to connect. Retrying again...

The browser never connected. Something is wrong. The tests cannot run. Aborting...

  (Tests Finished)

Steps to reproduce:

removed folders:
node_modules
cypress

removed @ types/cypress from package.json
changed cypress version in package.json from 1.4.2 to 2.1.0

Then installed dependencies and started tests in default headless mode

npm install

cypress run

Versions

OS: Windows 10 / macOS High Sierra v 10.13.4
Cypress: 2.1.0

same behavior on Windows and macOS

package.json

  "devDependencies": {
    "@ bahmutov/add-typescript-to-cypress": "2.0.0",
    "@ types/chai": "4.1.1",
    "@ types/chai-as-promised": "7.1.0",
    "@ types/mocha": "2.2.48",
    "@ types/node": "9.3.0",
    "chai": "4.1.2",
    "chai-as-promised": "7.1.1",
    "cypress": "2.1.0",
    "dotenv-safe": "5.0.1",
    "mocha": "5.0.5",
    "mochawesome": "3.0.2",
    "tslint": "5.9.1",
    "typescript": "2.8.1"
  }

cypress.json

{
  "integrationFolder": "dist/specs",
  "reporter": "mochawesome"
}
@jennifer-shehane
Copy link
Member

Does the run work when running cypress open?

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Apr 17, 2018
@cherednyk-tcm
Copy link
Author

Yes, cypress open works on version 2.1.0.
On version 1.4.2 both modes work ok: cypress run and cypress open.

@jennifer-shehane
Copy link
Member

Yeah, I don't see why this should be happening from the information provided. Could you run DEBUG=cypress:* cypress run and share the .log?

@cherednyk-tcm
Copy link
Author

Here's the log

@jennifer-shehane
Copy link
Member

  • Are you visiting a site with basic auth credentials in the url?
  • Do the tests run when visiting another url without basic auth credentials in the url?

@cherednyk-tcm
Copy link
Author

Yes, the app requires basic auth credentials, they are passed in the url.
I started the app on localhost with turned off basic auth, then removed credentials from the url in tests, and this problem disappeared, tests are now working in headless mode.
Looks like cypress is not backward compatible for this feature.

@fbring
Copy link

fbring commented May 2, 2018

I had a similar issue when I updated from 1.3.0 to 2.1.0.

I removed the auth credentials from the baseUrl and pasted them into the options of cy.visit().

Before

{
   "baseUrl": "https://name:secret@domain.io"
}

After

cy.visit('/', {
   auth: {
      username: 'name',
      password: 'secret',
   },
});

Now it works for me. Maybe this is helpful.

@jennifer-shehane
Copy link
Member

@IgorCherednyk were you able to try the workaround as described by @fbring ?

@jennifer-shehane jennifer-shehane added stage: awaiting response Potential fix was proposed; awaiting response and removed stage: needs information Not enough info to reproduce the issue labels May 2, 2018
@AyWa
Copy link

AyWa commented May 11, 2018

Hi,

I had the same issue as you describe.
However if I was installing cypress in a new folder, I was able to use chrome for the test they provide, but not with my test suite.

So after investigation, my problem was coming from plugins/index

I used to have:

  on('before:browser:launch', (browser = {}, args) => {
    // console.log(browser, args) // see what all is in here!
  
    // browser will look something like this
    // {
    //   name: 'chrome',
    //   displayName: 'Chrome',
    //   version: '63.0.3239.108',
    //   path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    //   majorVersion: '63'
    // }
  
    // args are different based on the browser
    // sometimes an array, sometimes an object
  
    if (browser.name === 'chrome') {
      args.push('--headless')
      args.push('--disable-dev-shm-usage')
  
      // whatever you return here becomes the new args
      return args
    }
  })

and it was working totally fine before 2.X. But with 2.X chrome can't open. However if I remove this code, everything run correctly. So I think there is a breaking change there. Maybe you have similar problem ?

problem of the code was args.push('--headless')

So does there is an other way to put chrome in headless ?

@jennifer-shehane
Copy link
Member

@AyWa No, there is currently not a way to run Chrome headlessly in Cypress.

We could probably have a better error for this situation.

@AyWa
Copy link

AyWa commented May 11, 2018

Got it, indeed could be cool, if cypress throw an error, or maybe even a little help like:
The browser never connected. Something is wrong. The tests cannot run. Aborting , Please check your plugin configuration

@jennifer-shehane jennifer-shehane added stage: ready for work The issue is reproducible and in scope type: user experience Improvements needed for UX and removed stage: awaiting response Potential fix was proposed; awaiting response labels Nov 28, 2018
@lydell
Copy link

lydell commented Mar 21, 2019

Observations:

If user:pass@ is present in baseUrl, cypress run won’t work. It doesn’t matter if the server actually has basic auth enabled or not.

cypress run --headed also fails if credentials are present in the URL, but cypress open works.

Here’s my solution:

Cypress.Commands.overwrite("visit", (originalFn, url, options) =>
  originalFn(url, {
    auth: { username: "user", password: "pass" },
    ...options,
  })
);

@jennifer-shehane jennifer-shehane changed the title Browser never connected in headless mode after update to cypress 2.1.0 Including auth credentials in baseUrl causes browser to never connect in headless mode Mar 29, 2019
@jennifer-shehane jennifer-shehane added the type: regression A bug that didn't appear until a specific Cy version release label Mar 29, 2019
@devsh4
Copy link

devsh4 commented Apr 18, 2019

I had a similar issue. Below workaround works just fine.

Before
cypress.json

{
   "baseUrl": "https://name:secret@domain.io"
}

In Test

cy.visit();

After
cypress.json

{
"env": {
    "url": "https://name:secret@domain.io"
   }
}

In Test

cy.visit(Cypress.env("url"));

@spras
Copy link

spras commented May 6, 2019

Same behavior here :

Steps to reproduce:

Please use this repo https://github.com/spras/issue-cypress to reproduce this behavior.

There're a docker-compose with an ultra simple webapp, with BASIC Authentification.
There's 2 tests :

  1. issue_headless_spec.js visit http://user:pass@localhost/
  2. issue_spec.js visit '/', it require 'http://user:pass@localhost' in the baseUrl to pass

Start the website : docker-compose up -d web

Run in headless mode the tests with baseUrl :

CYPRESS_baseUrl='http://user:pass@localhost/' DEBUG=cypress:server:request  $(npm bin)/cypress run

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    3.2.0                                                                              │
  │ Browser:    Electron 59 (headless)                                                             │
  │ Specs:      2 found (issue_headless_spec.js, issue_spec.js)                                    │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running: issue_headless_spec.js...                                                       (1 of 2) 

Timed out waiting for the browser to connect. Retrying...

Timed out waiting for the browser to connect. Retrying again...

The browser never connected. Something is wrong. The tests cannot run. Aborting...

  (Results)

  ┌──────────────────────────────────────┐
  │ Tests:        0                      │
  │ Passing:      0                      │
  │ Failing:      1                      │
  │ Pending:      0                      │
  │ Skipped:      0                      │
  │ Screenshots:  0                      │
  │ Video:        true                   │
  │ Duration:     0 seconds              │
  │ Spec Ran:     issue_headless_spec.js │
  └──────────────────────────────────────┘


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  /Users/spras/Devl/workspace_php/issue-cypress/cypress/videos/issue_headless_spec.js.mp4 (8 seconds)


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running: issue_spec.js...                                                                (2 of 2) 

Timed out waiting for the browser to connect. Retrying...

Timed out waiting for the browser to connect. Retrying again...

The browser never connected. Something is wrong. The tests cannot run. Aborting...

  (Results)

  ┌─────────────────────────────┐
  │ Tests:        0             │
  │ Passing:      0             │
  │ Failing:      1             │
  │ Pending:      0             │
  │ Skipped:      0             │
  │ Screenshots:  0             │
  │ Video:        true          │
  │ Duration:     0 seconds     │
  │ Spec Ran:     issue_spec.js │
  └─────────────────────────────┘


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  /Users/spras/Devl/workspace_php/issue-cypress/cypress/videos/issue_spec.js.mp4 (6 seconds)


====================================================================================================

  (Run Finished)


      Spec                                                Tests  Passing  Failing  Pending  Skipped 
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✖ issue_headless_spec.js                      0ms        -        -        1        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✖ issue_spec.js                               0ms        -        -        1        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    2 of 2 failed (100%)                          0ms        -        -        2        -        -  

When i run the same command without the baseUrl parameter, there's no timeout, of course the second test fail in 404.

DEBUG=cypress:server:request  $(npm bin)/cypress run
====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    3.2.0                                                                              │
  │ Browser:    Electron 59 (headless)                                                             │
  │ Specs:      2 found (issue_headless_spec.js, issue_spec.js)                                    │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running: issue_headless_spec.js...                                                       (1 of 2) 


  My Issue Test
  cypress:server:request sending request as stream { auth: { username: 'user', password: 'pass' }, failOnStatusCode: true, method: 'GET', body: null, headers: { accept: 'text/html,*/*', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/3.2.0 Chrome/59.0.3071.115 Electron/1.8.2 Safari/537.36' }, gzip: false, url: 'http://localhost/', followRedirect: [Function], strictSSL: false } +0ms
  cypress:server:request setting request jar cookies [] +92ms
  cypress:server:request setting request jar cookies [] +1s
    ✓ Does not do much! (125ms)


  1 passing (2s)


  (Results)

  ┌──────────────────────────────────────┐
  │ Tests:        1                      │
  │ Passing:      1                      │
  │ Failing:      0                      │
  │ Pending:      0                      │
  │ Skipped:      0                      │
  │ Screenshots:  0                      │
  │ Video:        true                   │
  │ Duration:     1 second               │
  │ Spec Ran:     issue_headless_spec.js │
  └──────────────────────────────────────┘


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  /Users/spras/Devl/workspace_php/issue-cypress/cypress/videos/issue_headless_spec.js.mp4 (0 seconds)


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running: issue_spec.js...                                                                (2 of 2) 


  My Issue Test
  cypress:server:request sending request as stream { auth: null, failOnStatusCode: true, method: 'GET', body: null, headers: { accept: 'text/html,*/*', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/3.2.0 Chrome/59.0.3071.115 Electron/1.8.2 Safari/537.36' }, gzip: false, url: 'http://localhost:57350/', followRedirect: [Function], strictSSL: false } +2s
  cypress:server:request setting request jar cookies [] +58ms
    1) Does not do much!


  0 passing (364ms)
  1 failing

  1) My Issue Test Does not do much!:
     CypressError: cy.visit() failed trying to load:

/

We failed looking for this file at the path:

/Users/spras/Devl/workspace_php/issue-cypress/

The internal Cypress web server responded with:

  > 404: Not Found
      at Object.cypressErr (http://localhost:57349/__cypress/runner/cypress_runner.js:65727:11)
      at Object.throwErr (http://localhost:57349/__cypress/runner/cypress_runner.js:65692:18)
      at Object.throwErrByPath (http://localhost:57349/__cypress/runner/cypress_runner.js:65719:17)
      at http://localhost:57349/__cypress/runner/cypress_runner.js:56262:31
      at visitFailedByErr (http://localhost:57349/__cypress/runner/cypress_runner.js:55840:12)
      at http://localhost:57349/__cypress/runner/cypress_runner.js:56243:22
      at tryCatcher (http://localhost:57349/__cypress/runner/cypress_runner.js:131273:23)
      at Promise._settlePromiseFromHandler (http://localhost:57349/__cypress/runner/cypress_runner.js:129291:31)
      at Promise._settlePromise (http://localhost:57349/__cypress/runner/cypress_runner.js:129348:18)
      at Promise._settlePromise0 (http://localhost:57349/__cypress/runner/cypress_runner.js:129393:10)
      at Promise._settlePromises (http://localhost:57349/__cypress/runner/cypress_runner.js:129468:18)
      at Async._drainQueue (http://localhost:57349/__cypress/runner/cypress_runner.js:126197:16)
      at Async._drainQueues (http://localhost:57349/__cypress/runner/cypress_runner.js:126207:10)
      at Async.drainQueues (http://localhost:57349/__cypress/runner/cypress_runner.js:126081:14)
      at <anonymous>




  (Results)

  ┌─────────────────────────────┐
  │ Tests:        1             │
  │ Passing:      0             │
  │ Failing:      1             │
  │ Pending:      0             │
  │ Skipped:      0             │
  │ Screenshots:  1             │
  │ Video:        true          │
  │ Duration:     0 seconds     │
  │ Spec Ran:     issue_spec.js │
  └─────────────────────────────┘


  (Screenshots)

  - /Users/spras/Devl/workspace_php/issue-cypress/cypress/screenshots/issue_spec.js/My Issue Test -- Does not do much! (failed).png (1280x720)


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  /Users/spras/Devl/workspace_php/issue-cypress/cypress/videos/issue_spec.js.mp4 (0 seconds)


====================================================================================================

  (Run Finished)


      Spec                                                Tests  Passing  Failing  Pending  Skipped 
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔ issue_headless_spec.js                    00:01        1        1        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✖ issue_spec.js                             338ms        1        -        1        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    1 of 2 failed (50%)                         00:01        2        1        1        -        -  

When i run the same, with the baseUrl, in the UI, everything is OK :

CYPRESS_baseUrl='http://user:pass@localhost/' DEBUG=cypress:server:request  $(npm bin)/cypress open
GET /__/ 200 22.562 ms - -
GET /__cypress/runner/cypress_runner.css 200 9.140 ms - -
GET /__cypress/runner/cypress_runner.js 200 7.496 ms - -
GET /__cypress/runner/fonts/fontawesome-webfont.woff2?v=4.7.0 200 4.260 ms - 77160
GET /__cypress/iframes/__all 200 20.557 ms - 826
GET /__cypress/tests?p=cypress/integration/issue_headless_spec.js-353 200 856.677 ms - 690
GET /__cypress/tests?p=cypress/integration/issue_spec.js-301 200 853.829 ms - 639
GET /__cypress/tests?p=cypress/support/index.js-215 200 1219.674 ms - -
  cypress:server:request sending request as stream { auth: { username: 'user', password: 'pass' }, failOnStatusCode: true, method: 'GET', body: null, headers: { accept: 'text/html,*/*', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36' }, gzip: false, url: 'http://localhost/', followRedirect: [Function], strictSSL: false } +0ms
  cypress:server:request setting request jar cookies [] +92ms
GET / 200 3.274 ms - -
  cypress:server:request sending request as stream { auth: { username: 'user', password: 'pass' }, failOnStatusCode: true, method: 'GET', body: null, headers: { accept: 'text/html,*/*', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36' }, gzip: false, url: 'http://localhost/', followRedirect: [Function], strictSSL: false } +82ms
  cypress:server:request setting request jar cookies [] +61ms
GET / 200 1.248 ms - -

Versions

Cypress 3.2.0

@LucasL94
Copy link

LucasL94 commented Nov 5, 2019

Having similar problems here, I'm trying to run Cypress yarn cypress run through Jenkins and it gives me the same errors

Cypress version: 3.5.0
node: V10.16

@jennifer-shehane
Copy link
Member

I've verified that the issue as detailed with a reproducible example by @spras that was happening in Cypress 3.2.0 has been fixed in Cypress 3.5.0 with the Electron upgrade #4720

If you're facing this issue, please you run Cypress in our latest version.

If your issue is still happening, please open a new issue with a reproducible example, since we are considering this exact use case resolved.

@jennifer-shehane jennifer-shehane removed the stage: ready for work The issue is reproducible and in scope label Dec 10, 2019
@cypress-io cypress-io locked as resolved and limited conversation to collaborators Dec 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: regression A bug that didn't appear until a specific Cy version release type: user experience Improvements needed for UX
Projects
None yet
Development

No branches or pull requests

8 participants