No one likes writing tests. We all need to. Simple as that.
Here. Couple of snippets I’ve had some more work on.
Config:
Settled up on this approach with ENV’s:
const { defineConfig } = require("cypress");
module.exports = defineConfig({
e2e: {
//env: "local",
baseUrl: "http://(...)",
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
env: {
blah: "ziiium",
(...)
}
})
Upload a file?
it('should POST /file blah.dcm', ()=> {
cy.fixture('dicom/blah.dcm','base64').then((dcmfile) => {
cy.request({
method:'POST',
url: '/file',
headers: {
'Content-Type': 'application/dicom',
"X-DUPA": "UDPA",
//"X-OriginUsername": "Żółć", // cypress err on this
},
body: Cypress.Blob.base64StringToBlob(dcmfile)
}).then((response) => {
cy.log(JSON.stringify(response.body))
expect(response.status).to.eq(200);
// for some reason the response.body is empty
// expect(response.body).to.have.property('Status');
// expect(response.body.Status).to.be.oneOf(['AlreadyStored','Success']);
})
})
})
Issues?
- won’t accept national characters
- response body seem to be
{}
What about multiframe from files?
Option 1) Prepare (wireshark?) a multiframe.data with pre-baked content.
Option 2) WIP… but here is an idea:
const fs = require('fs');
let fileNamesArray = [];
fs.readdirSync('cypress/fixtures').forEach((file) => {
fileNamesArray.push(file);
});
it('push files', () => {
cy.get('input[type=file]').selectFile(fileNamesArray);
});
