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

Issue with domains in 'baseUrl' having several dots #1680

Closed
adriantoine opened this issue May 4, 2018 · 10 comments
Closed

Issue with domains in 'baseUrl' having several dots #1680

adriantoine opened this issue May 4, 2018 · 10 comments
Labels
stage: needs information Not enough info to reproduce the issue stale no activity on this issue for a long period type: bug

Comments

@adriantoine
Copy link

Current behavior:

I'm trying to tests a website on an Azure domain which looks like:

http://my-test-app.westeurope.cloudapp.azure.com

When I try to run cypress, I'm getting the following error:

Uncaught DOMException: Failed to set the 'domain' property on 'Document': 'azure.com' is not a suffix of 'localhost'.

If I try to run cypress run, my terminal just hangs after (Tests Starting) without stopping or showing any error.

Desired behavior:

The site is testable.

Steps to reproduce:

See above.

Versions

2.1.0

Also, it seems to be a recent regression, I was able to test this website a few months ago.

@jennifer-shehane
Copy link
Member

Can you install an earlier version of Cypress and confirm that this is a regression in 2.1.0? That would help narrow down the issue. Earlier versions

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

Sorry my bad, it wasn't working on previous versions, the difference is that in previous versions there wasn't a baseUrl setting.

Instead I was using cy.visit using the full URL:

cy.visit('http://my-test-app.westeurope.cloudapp.azure.com');

and that still works.

At the moment I have:

cy.visit('/');

and I have a config like that for prod testing:

{
  "baseUrl": "http://my-test-app.westeurope.cloudapp.azure.com"
}

and one like that for local testing:

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

so that I can switch between environments easily.

It works well for localhost but I can't run my tests against the Azure website, is that a bug?

Thanks!

@jennifer-shehane jennifer-shehane changed the title Issue with domains having several dots Issue with domains in 'baseUrl' having several dots May 4, 2018
@jennifer-shehane jennifer-shehane added 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 4, 2018
@jennifer-shehane
Copy link
Member

We're unaware of an issue with this currently, but it helps narrowing this down to baseUrl.

We had issues with this/something similar a while back that were fixed in 1.4.2

@adriantoine
Copy link
Author

adriantoine commented Jun 28, 2018

Hi @jennifer-shehane,

Sorry to bring this up again, I've been reading this error message again:

Uncaught DOMException: Failed to set the 'domain' property on 'Document': 'azure.com' is not a suffix of 'localhost'.

and reading "'azure.com' is not a suffix of 'localhost'" made me wonder, is Cypress meant to be run on localhost only? I'm currently trying to run unit tests on several different domains and keep finding issues, so before I open bugs, maybe I misunderstood something and Cypress is meant to be run on localhost only? Otherwise I'm not sure I understand this error message.

Thanks!

@jennifer-shehane
Copy link
Member

No, it's not intended to only be run on localhost, there are valid use cases for testing on a deployed testing or staging domain, for example, that we do ourselves.

@jennifer-shehane
Copy link
Member

Unfortunately we have to close this issue due to inactivity. Please comment if there is new information to provide concerning the original issue and we can reopen.

@jennifer-shehane jennifer-shehane removed the stage: needs investigating Someone from Cypress needs to look at this label Jul 23, 2019
@antezecevic
Copy link

Hi @jennifer-shehane ,

This still doesn't work in Cypress 4.0.1. I checked it in 3.8.3 and 4.0.1, and base url is completely ignored if you have more than one dot anywhere in the url.

For example, we have urls like this: https://sub.domain.com/MyApp-v1.2.3/appArea/ (notice the multiple dots in the app name)

If I call cy.visit("https://sub.domain.com/MyApp-v1.2.3/appArea/") everything is fine, but if I use the recommended approach with baseUrl set in cypress.json like this cy.visit("MyApp-v1.2.3/appArea/"), the cypress will ignore the base URL and will navigate to: "http://MyApp-v1.2.3/appArea/"

The original question had dots in the baseUrl, and we have the dots in the app name, so this could affect a lot of apps potentially.

Quick fix for this is to URL encode the dots, which means that regular expression that concatenates the baseUrl with app name has a bug. The problem with URL encode is that the asserts and logs in cypress contain the URL encoded text then, so it looks ugly.

I think this should still be treated as a bug.

Thanks!

@jennifer-shehane jennifer-shehane added stage: needs information Not enough info to reproduce the issue type: bug labels May 5, 2020
@HallOfSame
Copy link

Running in to this issue in v10.7 and 10.11 as well.

From what I can tell it requires both:

  • Manually setting port in the configuration
  • Setting the baseUrl inside of setupNodeEvents

Example configuration file:

const { defineConfig } = require("cypress");

const exampleBaseUrl = "https://localhost.someDomain.com:3001/";

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      config.baseUrl = exampleBaseUrl;

      return config;
    },
    // Uncomment the line below and the test loads properly
    // baseUrl: exampleBaseUrl
  },
  // Removing the port setting also fixes the issue
  port: 3000
});

Full minimal reproduction in this repo here: https://github.com/HallOfSame/CypressBaseUrlBug

The error is thrown from the configure method in packages/driver/src/cypress.ts.

    if (domainName && config.testingType === 'e2e') {
      document.domain = domainName
    }

When baseUrl is set inside of setupNodeEvents the existing document.domain here is localhost. Moving the baseUrl definition out of the setup method causes document.domain to be localhost.someDomain.com instead, fixing the error.

@cypress-app-bot
Copy link
Collaborator

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.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 18, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs information Not enough info to reproduce the issue stale no activity on this issue for a long period type: bug
Projects
None yet
Development

No branches or pull requests

5 participants