why do i get kicked out of a logged in web session?

馋奶兔 提交于 2019-12-24 19:32:51

问题


so i still have the same problem, but this time, my code is not the problem, at least i think so

My Code:

import * as LogConst from 'C:\\Users\\Kristi\\Desktop\\BATests\\tests\\cypress\\fixtures\\Login_Data.json'

describe('all testcases hopefully', function () {

    before(function () {
        cy.clearLocalStorage();
        cy.clearCookies();

    });


    it('loading', function () {
        cy.visit('https://' + LogConst.server.name + ':' + LogConst.server.password + '@dev.capitalpioneers.de/');
        cy.request({
            method: 'POST',
            url: '/login', // baseUrl is prepended to url
            form: true, // indicates the body should be form urlencoded and sets Content-Type: application/x-www-form-urlencoded headers
            body: {
                username: 'LogConst.TestUserCostumer.usercos',
                password: 'LogConst.TestUserCostumer.usercospass'
            }
        });
        // just to prove we have a session
        cy.getCookies('cypress-session-cookie').should('exist')
        cy.contains('Login').click();
    });
 it('gets to products', function () {
        cy.request('/produkte');
        cy.getCookies('cypress-session-cookie').should('exist');
        cy.contains('Produkt').click();
        cy.url()
            .should('include', '/produkte');
    });


    it('selects Dr. Peters ', function () {
        cy.request('/produkt/hotelimmobilie-aachen/');
        cy.getCookies('cypress-session-cookie').should('exist');
        cy.contains('Dr. Peters').click();
        cy.get('#sum_slider[type=range]')
            .invoke('val', 50000)
            .trigger('change')
    });
it('downloads all files and checks the checkboxes', function () {
        cy.get('#ga-btn-invest-now-product-detail-hotelimmobilie-aachen').click();
        cy.contains('Fondsprospekt').click();
        cy.contains('Wesentlichen Anlegerinformationen').click();
        cy.get('#pre_check_inGermany').click({force: true});
        cy.get('#pre_check_readDocument1').click({force: true});
        cy.get('#pre_check_readDocument2').click({force: true});
       // cy.pause();
        cy.get('.button.button.button--full-width.button--yellow.js-outbrain-invest[type=submit]').click();
    });

after clicking on the last button i get kicked out and redirected to the log in page instead of getting to the next page which should have this url:

https://dev.capitalpioneers.de/investor/investment/dynamic changing number/investieren/

what is the prboblem? I don't get any error messages


回答1:


This is expected behavior in Cypress. I believe you have to preserve the cookies post every it()/ context(),

beforeEach('Preserve the cookies to persist the state', () => {
        Cypress.Cookies.preserveOnce('sessionid', 'csrftoken')
    })

In the above script sessionid and csrftoken are the token names which I want to preserve/ retain after each test.

An alternative is to whitelist the cookie tokens which you want to preserve,

Cypress.Cookies.defaults({whitelist: 'sessionid'});


来源:https://stackoverflow.com/questions/55052760/why-do-i-get-kicked-out-of-a-logged-in-web-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!