'Cypress - passing object to cy.type or cy.contains command

I'm generating name and surname, which I want to use them in several it tests. With describe block I save them into JSON file. Then I want to use them in cy.type or cy.contains.

describe("Constants", function () {
const uuid = () => Cypress._.random(0, 1e3)
const suid = () => Cypress._.random(0, 1e3)
const id = uuid()
const sid = suid()
const Firstname = `Test${id}`
const Surname = `Patient${sid}`
it("Copy constants", function () {
    cy.writeFile('cypress/fixtures/constants.json', { "Firstname" : Firstname, "Surname" : Surname})
})

})

When I use both variables in it test, they're represented as object (see picture)

it('Treatments', function() {
      cy.visit('/')
      cy.fixture("constants.json").then(ime => {   
        cy.log(ime.Firstname)
      cy.fixture("constants.json").then(priimek => {   
        cy.log(priimek.Surname)
      cy.get('a.ng-tns-c80-4').click()
      cy.get('path[d="M19 11h-6V5a1 1 0 0 0-2 0v6H5a1 1 0 0 0 0 2h6v6a1 1 0 0 0 2 0v-6h6a1 1 0 0 0 0-2z"]').click()
      cy.get('.d-flex > .appearance-filled').should('be.visible').and('contain','Create').click()
      //Patient info
      cy.get('[translate="treatmentsPage.patientInformationTitle"]').should('be.visible').and('contain','Patient information')
      cy.get('[translate="treatmentsPage.errors.firstNameIsRequired"]').should('be.visible').and('contain','First name is required!')
      cy.get('#firstName').should('be.visible').clear().type(`${ime}`)
      cy.get('[translate="treatmentsPage.errors.lastNameIsRequired"]').should('be.visible').and('contain','Last name is required!')
      cy.get('#lastName').should('be.visible').clear().type(`${priimek}`)

})

Testing

What am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source