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

Tests run in Chrome with baseUrl set navigate directly to baseUrl instead of Test Runner URL #1777

Closed
StormPooper opened this issue May 25, 2018 · 30 comments · Fixed by #3049

Comments

@StormPooper
Copy link

Current behavior:

When I set a baseUrl and attempt to run the tests in Chrome, instead of the test runner it attempts to directly go to that URL.
image
Removing the baseUrl property will load Cypress as normal, as does having a value set but running the tests using Electron.

Desired behavior:

When I run the tests with Chrome, it should navigate to Cypress running on localhost and show me the Cypress Test Runner. This is how it behaves when using Electron as the browser.

Steps to reproduce:

  1. Add "baseUrl": "https://doesntmatteranyurl" to Cypress.json
  2. Open Cypress
  3. Set browser to Chrome
  4. Run any tests

Versions

Cypress: 2.1.0 (happened on previous versions too)
OS: Windows 10 1803

@jennifer-shehane
Copy link
Member

This is the intended behavior of baseUrl as outlined here

How are you seeing the main url in the Electron browser? - the main url bar does not display for me in Electron.

Are you having an issue running the tests in Chrome versus Electron? Are the tests not running / displaying an error?

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label May 25, 2018
@StormPooper
Copy link
Author

Ah, I've misunderstood it then. I assumed it was always going to be Cypress' URL in the address bar. and the site in question in the secondary bar.

In that case, the issue is that when I attempt to write a test for https://e2e-webapp-dev-brighthr-canadev.azurewebsites.net I don't see the Test Runner UI in Chrome and the tests do nothing (it also breaks the page, removing the background and causing JS errors).

When I run the tests in Electron through the UI, it's working correctly, and I'm pretty sure we're not doing any frame-busting, so I'm not sure why they are behaving differently.

@jennifer-shehane
Copy link
Member

I'm unable to recreate this in my environment using Cypress 2.1.0 on Mac. Tried Chrome 66, Chromium 65, Canary 68 and Electron 59. The only other obvious difference I see is Windows, which I would have to test.

Do you have any other configuration set up? Anything in your cypress.json or env vars?

@StormPooper
Copy link
Author

StormPooper commented May 25, 2018

It could be, my colleages also had it but they were all running Windows 7 or 10 too.

Here's the full cypress.json, no environment variables set.

{
    "baseUrl": "https://e2e-webapp-dev-brighthr.azurewebsites.net",
    "viewportWidth": 1440,
    "viewportHeight": 900,
    "env": {
        "apiUrl": "https://e2e-brighthr-api-dev.azurewebsites.net",
        "region": "uk"
    },
    "reporter": "mochawesome",
    "reporterOptions": {
        "inline": true,
        "reportDir": "cypress/report",
        "reportFilename": "e2e",
        "configFile": "cypress.json"
    },
    "reporterEnabled": "mochawesome,@cypress/mocha-teamcity-reporter",
    "mochawesomeReporterOptions": {
        "quiet": true,
        "configFile": "cypress.json"
    }
}

@jennifer-shehane jennifer-shehane added OS: windows stage: needs investigating Someone from Cypress needs to look at this and removed stage: needs information Not enough info to reproduce the issue labels May 25, 2018
@StormPooper
Copy link
Author

@jennifer-shehane: Just asked a colleague on a Mac to run it and it's fine for them, so it appears to be a Windows issue. Here's what I see:
image

And here's what my colleague sees (note the Test Runner UI in the background):
image

@StormPooper
Copy link
Author

Still an issue on 3.0.1.

@astehlik
Copy link

astehlik commented Aug 5, 2018

I'm experiencing the same issue on Fedora 28:

With Chrome 68: the baseUrl is opened instead of the test runner and I get a 404 error.

When I use Chromium 67 or Electron 59 everything is working as expected.

@astehlik
Copy link

astehlik commented Aug 5, 2018

Another hint: the error occurs in Cypress version 2.1.0 (where it already worked before) and in version 3.0.3.

This seems to indicate that something changed in a newer Chrome version which causes the problem.

@jennifer-shehane
Copy link
Member

Oftentimes Windows has a different major Chrome release version than Linux/Mac machines, so while it is only happening on Windows - it may be a specific Chrome version issue - would need full versions of Chrome it is happening on.

I'm still unable to replicate on:

  • Chrome Version 70.0.3518.0
  • Chrome Version 68.0.3440.106
  • Chrome Version 67.0.3396.0

These just happen to be the chrome versions on my machine at the moment though.

@TPiddy
Copy link

TPiddy commented Aug 27, 2018

I have the same issue...

Chrome 68, Cypress 3.1.0, Mac OS.

@StormPooper
Copy link
Author

Still an issue for us. Interestingly, @TPiddy above is on a Mac, implying it's something other than the OS, but I haven't been able to reproduce it on the Macs in our office.

  • Cypress 3.1.0
  • Windows 10 1809
  • Chrome 70.0.3538.77 (Official Build) (64-bit)

@renefs
Copy link

renefs commented Nov 27, 2018

Same problem here with a create-react-app application:

  • Cypres 3.1.2
  • Mac OS 10.14 (Mojave)
  • Canary 72 (Version 72.0.3622.0 (Official Build) canary (64-bit))

cypress.json:

{
  "baseUrl": "http://localhost:3000"
}

Test run:

context('Redirections', () => {
  it('goes to github', () => {
    cy.visit('https://github.com/')
    cy.url().should('contains', '/');
  })
})

URL I see on the browser: http://localhost:3000/__/#/tests/integration/actions.spec.js

The problem happened using cypress run --browser canary and cypress open

@jarrodldavis
Copy link

jarrodldavis commented Dec 9, 2018

I'm running into a similar issue – a locally hosted web server and Cypress' test runner not displaying when baseUrl is set to that local URL (e.g. http://localhost:8080). There appears to be some issue with some versions of Chrome/Chromium (currently I get this issue on Chromium Version 73 and Chrome Version 72) regarding localhost/127.0.0.1 URLs bypassing the configured proxy, which is what Cypress uses to inspect network traffic and provide the test runner under the /__/ path.

I have some more details about that here: #1872 (comment)

@StormPooper
Copy link
Author

Still an issue with Cypress 3.1.4 and Chrome 71.0.3578.98 (Official Build) (64-bit) on Windows 10 1803.

@Ycaglayan
Copy link

I have this issue as well on Windows 7, Cypress 3.1.4 and 71.0.3578.98 (Official Build) (32-bit).

@jennifer-shehane
Copy link
Member

Can any of you experiencing this issue, try to add the code below and respond whether it fixes the issue or not?

Add the code below to your cypress/plugins/index.js file:

module.exports = (on) => {
  on('before:browser:launch', (browser = {}, args) => {
    if (browser.name === 'chrome') { 
      // ^ make sure this is your browser name, you may 
      // be using 'canary' or 'chromium' for example, so change it to match!
      args.push('--proxy-bypass-list=<-loopback>')
      return args
    }
  })
}

@jennifer-shehane jennifer-shehane added stage: awaiting response Potential fix was proposed; awaiting response and removed stage: needs investigating Someone from Cypress needs to look at this labels Jan 30, 2019
@renefs
Copy link

renefs commented Jan 30, 2019

Hi @jennifer-shehane, I confirm that adding these lines fixes the issue :D

@StormPooper
Copy link
Author

@jennifer-shehane yes, that seems to fix it for me.

@jennifer-shehane jennifer-shehane added stage: pending release stage: needs review The PR code is done & tested, needs review and removed stage: awaiting response Potential fix was proposed; awaiting response stage: pending release labels Jan 30, 2019
@jennifer-shehane
Copy link
Member

This PR will automatically pass these flags through to Chrome and should resolve this issue when released: #3049

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 30, 2019

Released in 3.1.5.

@jennifer-shehane jennifer-shehane added type: bug browser: chrome and removed stage: needs review The PR code is done & tested, needs review labels Jan 31, 2019
@StormPooper
Copy link
Author

@jennifer-shehane interestingly, this doesn't work for every machine I have. It worked on my home machine yesterday, but when I try it on my work machine I'm still getting this. I've tried with and without your code snippet and tried 3.1.5 too, but no luck. I've also upgraded to Chrome 72.0.3626.81 (Official Build) (64-bit), reinstalled it from scratch and completely wiped Chrome's settings, but no change.

@jennifer-shehane
Copy link
Member

Hey @StormPooper, can you try setting "modifyObstructiveCode": false in your cypress.json? Does that fix the issue?

@StormPooper
Copy link
Author

@jennifer-shehane just tried it, no difference.

@MarinoPoletine
Copy link

This issue happens to me also. The only way to get around is restarting my machine. I am using a MacBook

@Betree
Copy link

Betree commented Apr 3, 2019

Had the same issue with the following browser:

{ 
  isChosen: true,
  majorVersion: '73',
  name: 'chromium',
  path: 'chromium-browser',
  version: '73.0.3683.75',
  isHeaded: true,
  isHeadless: false 
}

#1777 (comment) doesn't solve it for me.

It also happens when I select Electron 59 instead of Chromium in the cypress client.

The line that causes the issue is:

cy.visit('http://localhost:1080');

Config

  • My baseUrl is set to http://localhost:3000
  • Tested on Cypress 3.1.5 and 3.2.0
  • Ubuntu 18.04

Preview

Peek 03-04-2019 16-18

@Betree
Copy link

Betree commented Apr 3, 2019

For those who really need to move forward, here is my to cents hack to bypass this issue:

/**
 * Open a link not covered by `baseUrl`.
 * See https://github.com/cypress-io/cypress/issues/1777
 */
Cypress.Commands.add('openExternalLink', url => {
  cy.visit('/').then(window => {
    const linkIdentifier = `__TMP_CY_EXTERNAL_LINK__`;
    const link = window.document.createElement('a');
    link.innerHTML = linkIdentifier;
    link.setAttribute('href', url);
    link.setAttribute('id', linkIdentifier);
    window.document.body.appendChild(link);
    cy.get(`#${linkIdentifier}`).click();
  });
});

@jennifer-shehane
Copy link
Member

I'm not able to replicate this issue by simply visiting 2 localhosts, with 1 of the localhosts being set as my baseUrl.

In Chrome Version 73.0.3683.86

test code

it('visits 3030 port', () => {
  cy.visit('http://localhost:3030')
})

it('visits 2222 port', () => {
  cy.visit('http://localhost:2222')
})

cypress.json

{
  "baseUrl": "http://localhost:3030"
}

Can you verify that visiting the second localhost directly - with no baseUrl set - loads the page properly? I want to make sure there is not some misdirection - that the page loads usually within Cypress.

Anyways, we will need a reproducible example in order to reopen the issue unfortunately.

@alastair-todd
Copy link

I have similar issue - I can visit my baseUrl, but not with a relative path

cypress

      cy.visit("http://localhost:4200/index.html"); //OK
      cy.visit("index.html"); // fails

cypress.json:

{
  "baseUrl": "http://localhost:4200"
}

@alastair-todd
Copy link

so it appears I have missed a subtle difference between cy.request and cy.visit

beginner's error!

@CodeSwimBikeRunner
Copy link

I'm having the issue where my baseUrl is http://localhost:4200/myapp
But cypress with chrome is opening http://localhost:4200/ which nothing exists there.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.