登陆-使用COOKIE绕过登陆
cy.setCookie函数保存cookie,并引用
文件上传方法-将以下写在support-commands.js里面
Cypress.Commands.add('uploadFile', (file,selector,type = 'image/jpeg') => {
return cy
.fixture(file, 'base64')
.then(Cypress.Blob.base64StringToBlob)
.then(blob => {
return cy.window().then(win => {
const nameSegments = file.split('/');
const name = nameSegments[nameSegments.length - 1];
const testFile = new win.File([blob], name, { type });
const event = { dataTransfer: { files: [testFile] } };
// return subject
return cy.get(selector).trigger('drop', event);
});
});
});
使用时可通过,cy.uploadFile('timg.jpg','.ivu-card-body')直接调用!
解决跨域报错问题
cypress.json 增加 "chromeWebSecurity": false
网友评论