我正在尝试编写一个脚本来登录这个网站a/en/
但在登录后,我禁用了此错误Cookie(查看图片)
这是我的密码:文章源自玩技e族-https://www.playezu.com/204533.html
import HomePage from "../../page-objects/pages/HomePage"
Cypress.on('uncaught:exception', (err, runnable) => {
return false;
describe('POM Implementation', () => {
it('should login', () => {
cy.visit('a/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);
台湾软件功能测试文章源自玩技e族-https://www.playezu.com/204533.html 文章源自玩技e族-https://www.playezu.com/204533.html
玩技站长微信
添加好友自动发送入群邀请
rainbow-shownow
玩技官方公众号
官方微信公众号
PLAYEZU
未知地区 1F
我认为最好的解决方案是使用Cypress会话来管理您的登录并进行重构。
首先,输入您的/cypress/support/index。js文件的代码:
Cypress.on(‘uncaught:exception’, (err, runnable) => {
return false;
});
在spec测试文件中不需要上述代码
其次,将测试URL放在cypress中。json或cypress.config。js文件并禁用chromeWebSecurity:
{
"baseUrl": "a/en/",
"chromeWebSecurity": false,
}
最后,使用Cypress会话进行登录,没有问题:
cy.session(_variable, () => {
cy.visit(‘a/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会话的更多信息ypress.io/api/commands/session#Syntax