Skip to content

Dynamic file upload #267

Answered by c32hedge
ghost asked this question in Q&A
Jan 27, 2021 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

I don't think this is quite what you were looking for, but I had a similar goal of not having to create tons of fixtures and found that if I could replicate the format of the file contents that cy.fixture yields, I didn't need a real file at all. Obviously, this is probably easier for my use case of simple csv and txt files, but I used console.log to see what value was being passed to my cy.fixture callback and came up with something like this:

cy.get('<my-file-input-selector>').attachFile({
  fileContent: 'Header1,Header2\nvalue A,value B\nvalue C,value D',
  fileName: 'LookMaNoRealFile.csv',
  mimeType: 'text/csv',
  encoding: 'utf-8'
});

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
1 reply
@c32hedge
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants