Cypress: Issue with domains in 'baseUrl' having several dots

Created on 4 May 2018  路  7Comments  路  Source: cypress-io/cypress

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.

needs information bug

Most helpful comment

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!

All 7 comments

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

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!

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

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!

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.

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.

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zbigniewkalinowski picture zbigniewkalinowski  路  3Comments

verheyenkoen picture verheyenkoen  路  3Comments

egucciar picture egucciar  路  3Comments

brian-mann picture brian-mann  路  3Comments

igorpavlov picture igorpavlov  路  3Comments