Skip to main content
Mejorar visualización de código
Origen Enlace
Marcos
  • 35.7k
  • 7
  • 36
  • 70
for (let i = 0; i < win.sessionStorage.lenght; i++) {
            const key = win.sessionStorage.key(i);
            const value = win.sessionStorage.getItem(key);
            cy.log(key)
            cy.log(value)      
        }```

me devuelve esto:

{
me devuelve esto  "prueba": "eyJ123",
    "persist:userSession": "{\"_persist\":\"{\\\"version\\\":-1,\\\"rehydrated\\\":true}\"}",
    "ob": "true",
    "cargarPinpoint": "false",
    "csid": "1",
    "user": "true",
    "obState": "",
    "isServertime": "true",
    "tt_appInfo": "{\"platform\":\"pc\"}",
    "nombre": "Juan Perez",
    "chat": "true",
    "jwt": "eyJ123",
    "referer": "",
    "cdTabData": "{\"id\":\"1\",\"openTabTS\":172}"
}

{ "prueba": "eyJ123", "persist:userSession": "{"_persist":"{\"version\":-1,\"rehydrated\":true}"}", "ob": "true", "cargarPinpoint": "false", "csid": "1", "user": "true", "obState": "", "isServertime": "true", "tt_appInfo": "{"platform":"pc"}", "nombre": "Juan Perez", "chat": "true", "jwt": "eyJ123", "referer": "", "cdTabData": "{"id":"1","openTabTS":172}" }```


sessionStorage: Storage
{
    "prueba": "eyJ123",
    "persist:userSession": "{\"_persist\":\"{\\\"version\\\":-1,\\\"rehydrated\\\":true}\"}",
    "ob": "true",
    "cargarPinpoint": "false",
    "csid": "1",
    "user": "true",
    "obState": "",
    "isServertime": "true",
    "tt_appInfo": "{\"platform\":\"pc\"}",
    "nombre": "Juan Perez",
    "chat": "true",
    "jwt": "eyJ123",
    "referer": "",
    "cdTabData": "{\"id\":\"1\",\"openTabTS\":172}"
}```
for (let i = 0; i < win.sessionStorage.lenght; i++) {
            const key = win.sessionStorage.key(i);
            const value = win.sessionStorage.getItem(key);
            cy.log(key)
            cy.log(value)      
        }```

me devuelve esto:

{ "prueba": "eyJ123", "persist:userSession": "{"_persist":"{\"version\":-1,\"rehydrated\":true}"}", "ob": "true", "cargarPinpoint": "false", "csid": "1", "user": "true", "obState": "", "isServertime": "true", "tt_appInfo": "{"platform":"pc"}", "nombre": "Juan Perez", "chat": "true", "jwt": "eyJ123", "referer": "", "cdTabData": "{"id":"1","openTabTS":172}" }```


sessionStorage: Storage
{
    "prueba": "eyJ123",
    "persist:userSession": "{\"_persist\":\"{\\\"version\\\":-1,\\\"rehydrated\\\":true}\"}",
    "ob": "true",
    "cargarPinpoint": "false",
    "csid": "1",
    "user": "true",
    "obState": "",
    "isServertime": "true",
    "tt_appInfo": "{\"platform\":\"pc\"}",
    "nombre": "Juan Perez",
    "chat": "true",
    "jwt": "eyJ123",
    "referer": "",
    "cdTabData": "{\"id\":\"1\",\"openTabTS\":172}"
}```
for (let i = 0; i < win.sessionStorage.lenght; i++) {
            const key = win.sessionStorage.key(i);
            const value = win.sessionStorage.getItem(key);
            cy.log(key)
            cy.log(value)      
        }

me devuelve esto:

{
    "prueba": "eyJ123",
    "persist:userSession": "{\"_persist\":\"{\\\"version\\\":-1,\\\"rehydrated\\\":true}\"}",
    "ob": "true",
    "cargarPinpoint": "false",
    "csid": "1",
    "user": "true",
    "obState": "",
    "isServertime": "true",
    "tt_appInfo": "{\"platform\":\"pc\"}",
    "nombre": "Juan Perez",
    "chat": "true",
    "jwt": "eyJ123",
    "referer": "",
    "cdTabData": "{\"id\":\"1\",\"openTabTS\":172}"
}

sessionStorage: Storage
{
    "prueba": "eyJ123",
    "persist:userSession": "{\"_persist\":\"{\\\"version\\\":-1,\\\"rehydrated\\\":true}\"}",
    "ob": "true",
    "cargarPinpoint": "false",
    "csid": "1",
    "user": "true",
    "obState": "",
    "isServertime": "true",
    "tt_appInfo": "{\"platform\":\"pc\"}",
    "nombre": "Juan Perez",
    "chat": "true",
    "jwt": "eyJ123",
    "referer": "",
    "cdTabData": "{\"id\":\"1\",\"openTabTS\":172}"
}
se añadieron 1264 caracteres en el cuerpo
Origen Enlace
Poden
  • 11
  • 4
   beforeEach("Precondicon", () => {
        cy.visit("urldeprueba")
        Cypress.on('uncaught:exception', (err, runnable) => {
            // returning false here prevents Cypress
            // inside the cy.origin() method from failing the test
            return false
        })
    
        cy.get("[name='usuario']").type("138")
        cy.get("[name='clave']").type("2233")
        cy.get("[type='submit']").click()
    
        cy.window().then((win) => {
            cy.wait(8000);
            cy.log(win.sessionStorage)
            cy.log(win.sessionStorage.jwt)
            cy.log(win.sessionStorage.getItem("jwt"))
            
            for (let i = 0; i < win.sessionStorage.lenght; i++) {
                const key = win.sessionStorage.key(i);
                const value = win.sessionStorage.getItem(key);
                cy.log(key)
                cy.log(value)
    
            }
        })
    })

Edit: En el

for (let i = 0; i < win.sessionStorage.lenght; i++) {
            const key = win.sessionStorage.key(i);
            const value = win.sessionStorage.getItem(key);
            cy.log(key)
            cy.log(value)      
        }```

me devuelve esto:

{ "prueba": "eyJ123", "persist:userSession": "{"_persist":"{\"version\":-1,\"rehydrated\":true}"}", "ob": "true", "cargarPinpoint": "false", "csid": "1", "user": "true", "obState": "", "isServertime": "true", "tt_appInfo": "{"platform":"pc"}", "nombre": "Juan Perez", "chat": "true", "jwt": "eyJ123", "referer": "", "cdTabData": "{"id":"1","openTabTS":172}" }```

En el cy.log(win):


sessionStorage: Storage
{
    "prueba": "eyJ123",
    "persist:userSession": "{\"_persist\":\"{\\\"version\\\":-1,\\\"rehydrated\\\":true}\"}",
    "ob": "true",
    "cargarPinpoint": "false",
    "csid": "1",
    "user": "true",
    "obState": "",
    "isServertime": "true",
    "tt_appInfo": "{\"platform\":\"pc\"}",
    "nombre": "Juan Perez",
    "chat": "true",
    "jwt": "eyJ123",
    "referer": "",
    "cdTabData": "{\"id\":\"1\",\"openTabTS\":172}"
}```
beforeEach("Precondicon", () => {
    cy.visit("urldeprueba")
    Cypress.on('uncaught:exception', (err, runnable) => {
        // returning false here prevents Cypress
        // inside the cy.origin() method from failing the test
        return false
    })

    cy.get("[name='usuario']").type("138")
    cy.get("[name='clave']").type("2233")
    cy.get("[type='submit']").click()

    cy.window().then((win) => {
        cy.wait(8000);
        cy.log(win.sessionStorage)
        cy.log(win.sessionStorage.jwt)
        cy.log(win.sessionStorage.getItem("jwt"))
        
        for (let i = 0; i < win.sessionStorage.lenght; i++) {
            const key = win.sessionStorage.key(i);
            const value = win.sessionStorage.getItem(key);
            cy.log(key)
            cy.log(value)

        }
    })
})
   beforeEach("Precondicon", () => {
        cy.visit("urldeprueba")
        Cypress.on('uncaught:exception', (err, runnable) => {
            // returning false here prevents Cypress
            // inside the cy.origin() method from failing the test
            return false
        })
    
        cy.get("[name='usuario']").type("138")
        cy.get("[name='clave']").type("2233")
        cy.get("[type='submit']").click()
    
        cy.window().then((win) => {
            cy.wait(8000);
            cy.log(win.sessionStorage)
            cy.log(win.sessionStorage.jwt)
            cy.log(win.sessionStorage.getItem("jwt"))
            
            for (let i = 0; i < win.sessionStorage.lenght; i++) {
                const key = win.sessionStorage.key(i);
                const value = win.sessionStorage.getItem(key);
                cy.log(key)
                cy.log(value)
    
            }
        })
    })

Edit: En el

for (let i = 0; i < win.sessionStorage.lenght; i++) {
            const key = win.sessionStorage.key(i);
            const value = win.sessionStorage.getItem(key);
            cy.log(key)
            cy.log(value)      
        }```

me devuelve esto:

{ "prueba": "eyJ123", "persist:userSession": "{"_persist":"{\"version\":-1,\"rehydrated\":true}"}", "ob": "true", "cargarPinpoint": "false", "csid": "1", "user": "true", "obState": "", "isServertime": "true", "tt_appInfo": "{"platform":"pc"}", "nombre": "Juan Perez", "chat": "true", "jwt": "eyJ123", "referer": "", "cdTabData": "{"id":"1","openTabTS":172}" }```

En el cy.log(win):


sessionStorage: Storage
{
    "prueba": "eyJ123",
    "persist:userSession": "{\"_persist\":\"{\\\"version\\\":-1,\\\"rehydrated\\\":true}\"}",
    "ob": "true",
    "cargarPinpoint": "false",
    "csid": "1",
    "user": "true",
    "obState": "",
    "isServertime": "true",
    "tt_appInfo": "{\"platform\":\"pc\"}",
    "nombre": "Juan Perez",
    "chat": "true",
    "jwt": "eyJ123",
    "referer": "",
    "cdTabData": "{\"id\":\"1\",\"openTabTS\":172}"
}```
Origen Enlace
Poden
  • 11
  • 4

Como hago para tomar el valor del jwt en el sessionStorage usando cypress?

Estoy intentando automatizar el login de una url de prueba, donde necesito tomar el valor del jwt para luego poder reutilizarlo para hacer validaciones varias

El codigo que estoy usando es:

beforeEach("Precondicon", () => {
    cy.visit("urldeprueba")
    Cypress.on('uncaught:exception', (err, runnable) => {
        // returning false here prevents Cypress
        // inside the cy.origin() method from failing the test
        return false
    })

    cy.get("[name='usuario']").type("138")
    cy.get("[name='clave']").type("2233")
    cy.get("[type='submit']").click()

    cy.window().then((win) => {
        cy.wait(8000);
        cy.log(win.sessionStorage)
        cy.log(win.sessionStorage.jwt)
        cy.log(win.sessionStorage.getItem("jwt"))
        
        for (let i = 0; i < win.sessionStorage.lenght; i++) {
            const key = win.sessionStorage.key(i);
            const value = win.sessionStorage.getItem(key);
            cy.log(key)
            cy.log(value)

        }
    })
})

Tanto en el cy.log del for como en el de win.sessionStorage directo, veo que aparece el jwt, pero no tengo forma de poder tomar el contenido. Intente de formas varias con sessionStorage.getItem("jwt") pero no hay manera