I'm practicing and was trying to write in a file, all names and links of 'cars' from amazon. The following code is working but will only write one line in the txt file. How can I write the complete list? Maybe as an object?
Is there a better way to do this?
it.only("amazon cars", () => {
cy.get("input#twotabsearchtextbox").type("cars{enter}");
cy.get(".s-main-slot")
.find("div>h2>a>span")
.each((element) => {
const elname = element.text();
cy.wrap(element)
.parent()
.invoke("attr", "href")
.then((href) => {
cy.writeFile("element.txt", `${elname} and its link ${href}`);
});
});
});