cypress
cypress copied to clipboard
cy.selectFile within cy.origin not working correctly
Current behavior
cy.selectFile behaves wrong as soon as wrapped in a cy.origin call. I had multiple different kinds of errors while playing with it, but did not get it to work properly somehow. I tried with the filename shortcut and the fixture syntax, both to no avail. The fixture syntax does look like it works, but somehow the file content is not properly attached to the input, e.g. an image is not shown correctly when uploading an image.
Desired behavior
File should be attached to selectFile properly.
Test code to reproduce
https://github.com/mduft/cypress-test-tiny/tree/master
Cypress Version
12.2.0
Node version
16.17.2
Operating System
Windows 11
Debug Logs
No response
Other
No response
Also, in my real world use-case I get this (additionally to the path being undefined as in the tiny test case): Which I did not manage to reproduce with the tiny test case, and I have NO idea why...?
xml.js:30 Uncaught TypeError: Cannot destructure property 'subject' of 'data' as it is null.
at SpecBridgeCommunicator.handleSubjectAndErr (xml.js:30:2)
at SpecBridgeCommunicator.toPrimary (xml.js:30:2)
at SpecBridgeCommunicator.<anonymous> (xml.js:30:2)
at SpecBridgeCommunicator.emit (xml.js:30:2)
at SpecBridgeCommunicator.onMessage (xml.js:30:2)
at xml.js:30:2
@mduft Interesting! Thank you for the reproduction! I am able to reproduce the issue you are seeing with the example you provided and verifying it works without the use of cy.origin()
. I also tried reading from the fixture like our documentation suggests and am seeing:
cy.origin('https://www.w3schools.com', () => {
cy.visit('/howto/howto_html_file_upload_button.asp');
cy.fixture('example.json', { encoding: null }).as('myFixture')
cy.get('input[type=file]').selectFile('@myFixture', { force: true });
});
and am seeing:
Something is def acting wonky with .selectFile()
, inside of the .origin()
callback. Marking this as a bug.
Are there any workarounds for this in the meantime?
Are there any workarounds for this in the meantime?
None that I know of. My 12.x update is completely blocked by this ATM.
Any news on this? I'm stuck on Cypress 11.x without any way to update to 12.x due to this issue.
We still cannot move forward with Cypress 12 due to this BLOCKER. Any plans to fix this anytime soon?
This issue is also blocking one of my tests, so +1
Just wanted to chime in saying this issue is blocking the writing of our tests as well, would be great to have any updates.
I was able to find a workaround for this issue by reading a fixture and stringifying it into an alias:
cy.origin('https://www.w3schools.com', () => {
cy.visit('/howto/howto_html_file_upload_button.asp');
cy.fixture('example.json').then(JSON.stringify).as('myFixture'); // <= read the fixture with default encoding, then stringify it before saving it as an alias
cy.get('input[type=file]').selectFile('@myFixture');
});
Unfortunately that does not help with binaries (ZIP files, pictures, etc.), right? We're still blocked on this issue, and still are forced to stay on 11, even though it has been quite many 12 releases now - any chance to get this properly fixed?
Please, any news on it?=(( it is a blocker indeed And can anyone tell which cypress version doesn't have this bug? I switched to 11.2.0 and it's not working as well((
Hi, is there any solution about that. I have a problem same
Thanks to @chrisbreiding, By referring your code sample I tweaked a bit and tried below and it worked for me, thank you so much.
cy.origin('https://example.com', () => {
cy.visit('/upload');
cy.fixture('user.csv').as('myFixture');
cy.get('[data-testid="file-input"]').selectFile('@myFixture')
});