How do you store an array or a collection strings into a variable. Then take that information and save it into a new fixture. The intention is to then re-use that fixture in a different scenario or test.
Example: I have a dropdown where if you click on it, it displays the following options; Apple, Banana, Pear.
I want to save all three fruits into a list somewhere outside of my test.
cy.writeFilecan be used to write data to a file. You can then usecy.readFileorcy.fixtureto read that data from the file.Alternatively, if you are running all of the tests in the same spec file, you could use a Cypress environment variable.
A few things to note: the getter/setter paradigm of Cypress.env can get a little clunky. There are probably cleaner ways to iterate through the options and store the data, but this was just an example. Also, Cypress.env is synchronous, so if you want to use it in a Cypress command chain, you'll need to either use
cy.wrapto work around that, or another strategy.