Cypress使用总结

登陆-使用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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容