handsome-cartoon-58565
01/25/2023, 4:58 PMts
cy.fixture('test-image-1.png')
.then((_) => (console.log('image 1?', _), _))
.as('productTestImage1');
cy.fixture('test-image-2.png').as('productTestImage2');
cy.wait(['@productTestImage1', '@productTestImage2']).then((imageFiles) => {
console.log('[[ fixture loaded? ]] /imageFiles:', imageFiles);
forAPI.images = imageFiles;
});
The file structure - which looks fine to me - is as on attached screenshot and yet Cypress throws an error that it's not able to locate the image file and logs don't show up.
What could be the reason?modern-dawn-86006
01/25/2023, 6:33 PMhandsome-cartoon-58565
01/25/2023, 6:44 PMtest.png doesn't work. I have a suspicion that it has to do something with my Cypress being launched from inside the Dockerhandsome-cartoon-58565
01/25/2023, 6:45 PMfixtureFolder path in cypress.json, so it's defaulthandsome-cartoon-58565
01/25/2023, 7:27 PMcy.fixture() yields - even my console.log inside cy.fixture( .. ).then() is not called, because the promise-alike yielded by Cypress apparently doesn't get resolve due to the not found filesome-cartoon-73108
01/26/2023, 6:52 AMpowerful-orange-86819
01/26/2023, 7:39 AMjs
cy.fixture(gameImage).then((image) => {
const formData = new FormData();
const fileName = gameNames[index] + ".jpg";
const blob = Cypress.Blob.base64StringToBlob(
image,
"image/jpg"
);
formData.append("file", blob, fileName);
imageUploadReq(formData).then((response) => {
const bodyString = Cypress.Blob.arrayBufferToBinaryString(
response.body
);
Here is part of my code implementation of uploading images with cy.fixture, imageUploadReq is just a function that sends the request after image uploadgray-kilobyte-89541
01/26/2023, 11:33 AMcy.request and forms in my (paid) course https://cypress.tips/courses/network-testinghandsome-cartoon-58565
01/26/2023, 1:24 PMcy.fixture() function not being able to find images (it doesn't even call .then() where my test logs are), despite the fact i am sure they are in the correct location. Moreover, i am able to workaround it with custom plugin function, where i use Node's fs.readFileSync() to manually read these image files. So it's something about cy.fixture() having problem with locating the images paths.
So it's not that i can't share loaded images between tests (like the issue with this context) or i can't upload them via HTTP - the issue is with loading a fixture by Cypress built-in command 🙂handsome-cartoon-58565
01/26/2023, 1:25 PMcy.fixture('../../test/e2e/cypress/fixtures/test-image-1.png', null) as well as this cy.readFile('test/e2e/cypress/fixtures/test-image-1.png', null). Apparently Cypress doesn't properly resolves a root path when it's inside the Docker 🤔handsome-cartoon-58565
01/26/2023, 1:27 PMcy.readFile() has root pointed to where cypress.json is located, which in my case is test/e2e, but i still have to provide a full path, like Cypress considered the path's root to be app's root (and not where cypress.json is located)