我试图写一个脚本来登录这个网站https://www.decathlon.ca/en/,但是在登录之后,我禁用了这个错误的cookie(查看图片)

这是我的密码:
import HomePage from "../../page-objects/pages/HomePage"
Cypress.on('uncaught:exception', (err, runnable) => {
return false;
});
describe('POM Implementation', () => {
it('should login', () => {
cy.visit('https://www.decathlon.ca/en/')
cy.viewport(1024, 768)
HomePage.clickUserIcon();
cy.get('.js-block-log-out > .btn').click();
HomePage.clickConnexionNextButton();
cy.getCookies()
HomePage.typeUsername('gggn@gmail.com');
cy.get('#lookup-btn').click({force: true})
HomePage.typePassword('123456);
cy.get('#signin-button').click({force: true})
cy.wait(5000);发布于 2022-08-02 20:36:13
我认为对您来说最好的解决方案是使用Cypress会话来管理您的登录并进行一些重构。
首先,将代码放入/cypress/support/index.js文件中:
Cypress.on('uncaught:exception', (err, runnable) => {
return false;
});您不需要在规范测试文件中使用上面的代码
其次,将您的测试URL放在您的cypress.json或cypress.config.js文件中,并禁用chromeWebSecurity:
{
"baseUrl": "https://www.decathlon.ca/en/",
"chromeWebSecurity": false,
}最后,使用Cypress会话进行登录,没有问题:
cy.session(_variable, () => {
cy.visit('https://www.decathlon.ca/en/')
cy.viewport(1024, 768)
HomePage.clickUserIcon();
cy.get('.js-block-log-out > .btn').click();
HomePage.clickConnexionNextButton();
HomePage.typeUsername('gggn@gmail.com');
cy.get('#lookup-btn').click({force: true})
HomePage.typePassword('123456);
cy.get('[data-test=password]').type('s3cr3t')
cy.get('#signin-button').click({force: true})
cy.wait(5000);
})您可以在这里阅读更多关于Cypress会话的信息,https://docs.cypress.io/api/commands/session#Syntax。
https://stackoverflow.com/questions/73212324
复制相似问题