1
votes

When I login from normal browser the login is successful with the URL : http://neelesh.zapto.org:8084/EnrolMe/indHome.html

But when I run the script from Cypress the directory location is not appended and the new URL after login is formed as : http://neelesh.zapto.org:8084/__/indHome.html

I have tried setting cypress.json with

{
    "chromeWebSecurity": false,
    "modifyObstructiveCode" : false
}

I have tried on chrome/electron(head and headless).

Below is my code snippet:

describe('My First Test Suite', function() {
    it('My First test case', function() {

      cy.visit("http://neelesh.zapto.org:8084/EnrolMe")
      cy.get("#login").click()
      cy.get("input[value='Individual']").click()
      cy.get("#username").type('1234567890')
      cy.get("#pwd").type('0646')
      Cypress.Cookies.debug(true)
      cy.clearCookies()
      cy.get("#login").click()
      cy.wait(6000)
   })
})

When I run the script from Cypress the directory location is not appended and the new URL after login is formed as : http://neelesh.zapto.org:8084/__/indHome.html

It should be redirected as : http://neelesh.zapto.org:8084/EnrolMe/indHome.html

Can anyone help me on this?

1

1 Answers

0
votes

This sounds like an issue with "Frame Busting". There's a related discussion for Cypress GitHub Issue #992 which may lend some help.

Your application code may contain problematic frame busting code like the following:

if (window.top !== window.self) {
  window.top.location.href = window.self.location.href;
}

You can get around this by changing your application code's reference to window.self from the Application Window to the Cypress Test Runner window (window.top).

Cypress emits a series of events as it runs in your browser. You can use the emitted window:before:load application event to ensure it's done before you attempt to login.

// cypress/support/index.js
Cypress.on('window:before:load', (win) => {
  Object.defineProperty(win, 'self', {
    get: () => {
      return window.top
    }
  })
})