Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cy.selectFile within cy.origin not working correctly #25261

Open
mduft opened this issue Dec 23, 2022 · 19 comments
Open

cy.selectFile within cy.origin not working correctly #25261

mduft opened this issue Dec 23, 2022 · 19 comments
Labels
E2E Issue related to end-to-end testing existing workaround stage: needs investigating Someone from Cypress needs to look at this topic: cy.origin Problems or enhancements related to cy.origin command Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: bug v12.0.0 🐛

Comments

@mduft
Copy link

mduft commented Dec 23, 2022

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

@mduft
Copy link
Author

mduft commented Dec 23, 2022

Also, in my real world use-case I get this (additionally to the path being undefined as in the tiny test case):
image
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

@emilyrohrbough emilyrohrbough self-assigned this Dec 23, 2022
@emilyrohrbough
Copy link
Member

@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:

Image

Something is def acting wonky with .selectFile(), inside of the .origin() callback. Marking this as a bug.

@emilyrohrbough emilyrohrbough added type: bug topic: cy.origin Problems or enhancements related to cy.origin command routed-to-e2e E2E Issue related to end-to-end testing labels Dec 23, 2022
@Danc9520
Copy link

Danc9520 commented Jan 6, 2023

Are there any workarounds for this in the meantime?

@mduft
Copy link
Author

mduft commented Jan 9, 2023

Are there any workarounds for this in the meantime?

None that I know of. My 12.x update is completely blocked by this ATM.

@mduft
Copy link
Author

mduft commented Jan 18, 2023

Any news on this? I'm stuck on Cypress 11.x without any way to update to 12.x due to this issue.

@emilyrohrbough emilyrohrbough removed their assignment Jan 30, 2023
@mduft
Copy link
Author

mduft commented Feb 27, 2023

We still cannot move forward with Cypress 12 due to this BLOCKER. Any plans to fix this anytime soon?

@georgwindhaber
Copy link

This issue is also blocking one of my tests, so +1

@nagash77 nagash77 added Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed routed-to-e2e labels Apr 19, 2023
@fredbh
Copy link

fredbh commented May 4, 2023

Just wanted to chime in saying this issue is blocking the writing of our tests as well, would be great to have any updates.

@chrisbreiding
Copy link
Contributor

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');
  });

@mduft
Copy link
Author

mduft commented Jun 21, 2023

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?

@DariaBor
Copy link

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((

@SemaEfe
Copy link

SemaEfe commented Oct 19, 2023

Hi, is there any solution about that. I have a problem same

@nageshcrest
Copy link

nageshcrest commented Jan 31, 2024

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')
  });

@shastrisubramaniam
Copy link

Can a fix for this be prioritized and expedited ? We have multiple use cases for uploading image files within origin ?

I don't see any workaround for this.

@jennifer-shehane
Copy link
Member

@shastrisubramaniam Have you tried the workaround described here? #25261 (comment)

@shastrisubramaniam
Copy link

@jennifer-shehane My understanding is that the workaround above does not work for image files

@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Jun 24, 2024
@ainkollu
Copy link

the issue persists for files of type image and PDF.....below is the error that is thrown on trying to upload an image or a PDF

Screenshot 2024-10-24 at 9 51 16 PM

@Neill83
Copy link

Neill83 commented Nov 28, 2024

We also have this issue when using cy.get(...).selectFile(...) inside cy.origin. We have tried everything what was suggested.
image

@eshadboltadr
Copy link

I'm also having this problem in cypress 13.16.0 . The cy.origin is interfering with .selectFile for image files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing existing workaround stage: needs investigating Someone from Cypress needs to look at this topic: cy.origin Problems or enhancements related to cy.origin command Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: bug v12.0.0 🐛
Projects
None yet
Development

No branches or pull requests