I am trying to fill out an HTML form using a CSV file. For them I first convert the CSV file to JSON and then try to fill the form using the JSON file. However, the only thing I get is the error: cy.type() can only accept a string or number. You passed in: undefined
I have checked the answers that have been given for this same problem but I can't find one that helps me. What am I doing wrong?
Here I leave the code with which I first pass the file from CSV to JSON, then it is logged in the console and finally I pass it through the form:
<!-- language: js -->
import {parse} from "papaparse"
describe('Convert CSV file in JSON file', function(){
let allData
before(()=>{
cy.readFile('C:/data/cypress/downloads/generatedBy_react-csv.csv')
.then(str =>{
cy.writeFile('C:/data/cypress/fixtures/testDataFromCSV.json', parse(str, {header:true}))
})
cy.fixture('testDataFromCSV.json')
.as('dataJson')
.then(dataJson => {
allData = dataJson
})
})
it('Log the data from the CSV to the JSON file', function(){
allData.data.forEach(data =>{
cy.log(data.firstName)
cy.log(data.lastName)
cy.log(data.email)
cy.log(data.age)
cy.log(data.address)
cy.log(data.vehicle)
cy.log(data.phoneNo)
})
})
it('Use JSON Data in hte HTML form', function(){
allData.data.forEach(data =>{
cy.visit('http://localhost/2iTesting/form.html')
cy.fixture("testDataFromCSV.json")
.then((dataJson)=>{
allData = JSON.stringify(dataJson)
cy.get('[cy-data="firstname"]')
.type(data.firstName)
cy.get('[cy-data="lastname"]')
.type(data.lastName)
cy.get('[cy-data="email"]')
.type(data.email);
cy.get('[cy-data="address"]')
.type(data.address);
cy.get('[cy-data="vehicle"]')
.type(data.vehicle);
cy.get('[cy-data="submit"]')
.click()
cy.wait(1500)
})
})
})
})