为什么我会被踢出已登录的网络会话?

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

所以我仍然有同样的问题,但是这次,我的代码不是问题,至少我是这么认为的

我的代码:

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();
    });

单击最后一个按钮后,我被踢出并重定向到登录页面,而不是进入应该有此 url:

的下一页

https://dev.capitalpioneers.de/investor/investment/动态变化数/investieren/

问题是什么?我没有收到任何错误消息

这是赛普拉斯的预期行为。我相信您必须每隔 it()/context()

保留 cookie post

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

在上面的脚本中,sessionidcsrftoken 是我想在每次测试后保留/保留的令牌名称。

另一种方法是将您要保留的 cookie 标记列入白名单,

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