首页 > 解决方案 > 赛普拉斯:如何上传压缩的 tar 文件

问题描述

我正在自动化我的REST API。我有一个 POST 请求,例如: POST /upload文件(应用程序/x-compressed-tar)类型和 "Content-Type": "multipart/form-data".

cypressTestFile.ts

cy.fixture(filePath, 'binary').then((binary) => {
  const blob = Cypress.Blob.binaryStringToBlob(binary);
  const formData = new FormData();
  formData.set('file', blob, filePath);  <-- formData is empty {}
  cy.request({
    method: 'POST',
    url: `/upload`,
    form: true,
    headers: {
      "Content-Type": "multipart/form-data"
    },
    body: {
      file: blob,
      type: "application/x-compressed-tar"
    }
  }).as('response').then(res => {
    expect(res.status).to.equal(201);
  });
})

这没有按预期工作。

任何帮助表示赞赏!

谢谢

标签: automationautomated-testscypresscypress-component-test-runner

解决方案


推荐阅读