为什么我被踢出登录的Web会话? [英] why do i get kicked out of a logged in web session?
问题描述
所以我仍然有同样的问题,但是这次,我的代码不是问题,至少我认为是
so i still have the same problem, but this time, my code is not the problem, at least i think so
我的代码:
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的页面:
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/ 动态更改数量/investieren/
https://dev.capitalpioneers.de/investor/investment/dynamic changing number/investieren/
什么是问题?我没有收到任何错误消息
what is the prboblem? I don't get any error messages
推荐答案
这是赛普拉斯的预期行为.我相信您必须在每个it()
/context()
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')
})
在上面的脚本中,sessionid
和csrftoken
是我希望在每次测试后保留/保留的令牌名称.
In the above script sessionid
and csrftoken
are the token names which I want to preserve/ retain after each test.
另一种方法是将要保留的cookie令牌列入白名单,
An alternative is to whitelist the cookie tokens which you want to preserve,
Cypress.Cookies.defaults({whitelist: 'sessionid'});
这篇关于为什么我被踢出登录的Web会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!