cypress: Incorrect redirect to malformed url within AUT - adding `_/` in url

Current behavior:

When I instruct cypress to login to an Oracle APEX application, the authentication re-directs cypress to a ‘404 not found’ page because the authenticated URL is malformed. The malformed URL is the only issue and can simply corrected programmatically (with a find and replace command). Screen Shot 2019-04-15 at 10 14 48 PM

However - it is very important to note that the cypress login correctly returns:

  1. a valid cookie
  2. a valid session

which is everything you need for authentication.

Desired behavior:

Cypress, ideally, should be able to follow the same authentication redirect that a user would in a regular browser.

Steps to reproduce: (app code and test code)

I created a dummy application with dummy credentials hosted by apex.oracle.com to demonstrate:

it('Login demo', function() {
    cy.visit('https://apex.oracle.com/pls/apex/f?p=54707:LOGIN_DESKTOP')
    cy.get('#P9999_USERNAME').type('ApexUser')
    cy.get('#P9999_PASSWORD').type('Oradoc_db1')
    cy.get('.t-Button').click()
  })

The above code (which should work until the application expires in many months) will redirect to a 404 not found page with a url in the format: https://apex.oracle.com/__/f?p=54707:1:[session_id]::::: Outside of cypress the url will have the format: https://apex.oracle.com/pls/apex/f?p=54707:1:[session_id]:::::

Versions

I have tested this across 4 instances of Oracle APEX (APEX 5.0, 5.1, 18.1 and 19) and this behavior is consistent.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 53 (25 by maintainers)

Commits related to this issue

Most upvoted comments

I am also facing this issue with all browsers including Electron :

  • Electron
  • Edge 85 (85.0.564.41)
  • Chrome 85 (85.0.4183.83)
  • Firefox 80 (beta)

Cypress 4.7.0 Node v8.11.3

Same after upgrading to latest versions: Cypress 5.1.0 Node v12.18.3

it('Login page', () => {

        // visit main home page
        cy.visit('https://tstapex.myhost.ch/ords/f?p=119')

        // make sure we are redirected to login
        cy.url().should('include', 'LOGIN_DESKTOP')

        // log in
        cy.get('#P9999_USERNAME').type('username')
        cy.get('#P9999_PASSWORD').type('password')

        // click login button
        cy.get('#login-button').click();

    })

I’m redirected to https://tstapex.myhost.ch/__/f?p=119:1:28275213605974:::::

Then of course get:

Not Found The requested URL /__/f was not found on this server.

Setting experimentalSourceRewriting to true does not help.

There is an open PR meant to fix this here: https://github.com/cypress-io/cypress/pull/5273 It’s complicated and is still a work in progress.

This fix is available starting in 4.6.0 as an experiment which you can access by setting this config option in your cypress.json or elsewhere:

{
	"experimentalSourceRewriting": true
}

Please use a new issue if you are still running into issues that are not solved by this change.

Another example from https://github.com/cypress-io/cypress/issues/5878

it('should reroute', function () {
  cy.visit('https://rahulshettyacademy.com/seleniumPractise/#/')
  cy.get('.cart-icon > img').click()
  cy.contains('PROCEED TO').click()
})

The url reroutes to the incorrect __/ url, visiting the Test Runner within the Test Runner as shown below. This behavior changed slightly over the versions, but never worked.

3.4.1 w/ Chrome 78

This one reroutes to https://rahulshettyacademy.com/seleniumPractise/__/#/cart

3.4.1 w/ Electron 61

This one reroutes to https://rahulshettyacademy.com/seleniumPractise/#/cart

3.5.0 w/ Chrome 78 or Electron 73

This one reroutes to https://rahulshettyacademy.com/seleniumPractise/__/#/cart

3.7.0 w/ Chrome 78 or Electron 73

This one reroutes to https://rahulshettyacademy.com/seleniumPractise/__/#/cart

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

I use the following code as workaround. Replace ‘xxx’ as needed.

cy.window().then((win) => {
   const location = win.location.href;
   cy.visit(location.replace('__', 'xxx'));
});

Does anyone know about a workaround for this problem?

I just used edit the url and redirect like so

cy.url()
      .should("contain", ":1:")
      .then(($url) => {
        loggedInPage = $url.replace("/__/", "/pls/apex/");
        cy.visit(loggedInPage); //necessary due to #redirectmalfunction
      });

An example context : https://github.com/hhudson/bypass_login_w_cypress/blob/master/cypress/integration/method1.login.js

I searched for both. Could see window.location.href being referenced, but not set.

Re-opening since others are still running in to this: https://github.com/cypress-io/cypress/issues/5442

Please re-open this issue. It is apparent in Electron 73 that ships with Cypress 3.5.0.

Since this issue only exhibits itself within Chrome - we figure it is a change in Chrome that caused this issue to happen in Cypress. I also assume it is not a bug, as the issue still persists in version 77. It may be an intended change in behavior.

Narrowing down the version of Chrome that it was introduced, it was introduce in version 71.0.3572.0, specifically between commits 7e3da6dc3d7cd7eb8a55ef301026fe1ab737f814 and 56dd83c9005f68d55ddbf85c551759526b4e37cd:

  • Chrome 61.0.3163.100 - PASSES
  • Chrome 69.0.3452.0 - PASSES
  • Chrome 71.0.3572.0 - PASSES = Base = 597039 7e3da6dc3d7cd7eb8a55ef301026fe1ab737f814
  • Chrome 71.0.3572.0 - FAILS = Base = 597057 56dd83c9005f68d55ddbf85c551759526b4e37cd
  • Chrome 72.0.3583.0 - FAILS
  • Chrome 73.0.3683.0 - FAILS
  • Chrome 74.0.3729.0 - FAILS
  • Chrome 77.0.3833.0 - FAILS

⭐️ Changelog where issue was introduced

@flotwig good luck 😅

I face the same problem. But only when using chromium. If I use elektron, it works.