文件上传操作(使用)
<h1>1. cypress中使用</h1>
<h2>1.1 上传普通文本文件</h2>
<pre><code class="language-javascript"> //choose local chart file
cy.get('#chart-upload_chartFile').attachFile('<path>/<under>/<fixture>/file.json');</code></pre>
<h2>1.2 上传二进制文件</h2>
<p>指定文件为binary,</p>
<pre><code class="language-javascript"> const fileName = '<path>/<under>/<fixture>/file.tar.gz'
cy.fixture(fileName, 'binary')
.then(Cypress.Blob.binaryStringToBlob)
.then(fileContent => {
cy.get('#chart-upload_chartFile').attachFile({
fileContent,
fileName,
mimeType: 'application/x-gzip',
encoding:'utf8'
})
})</code></pre>
<h1>2. Reference</h1>
<p>[1]. <a href="https://npm.devtool.tech/cypress-file-upload">cypress file upload npm</a>
[2]. <a href="https://github.com/abramenal/cypress-file-upload/tree/edb15cb25bae83319ee646f2d0e32bf8e8e3d4da#working-with-raw-file-contents">cypress file upload github link</a></p>