Search code examples
javascriptcypress

Cannot parse an argument into a cypress expect


In the code below i cannot get arg3 to be used. I have tried $arg3 as well but to no avail. Does anyone know how it can be done?

Basically arg3 will refer to an array in the Notifications_Events.json file



function checkEvents(arg1,arg2,arg3){
    
  // arg1 = categories drop down button
  // arg2 = Number of events in category
  // arg3 = Name of category
   
   allure.step("Valid events in "+ arg1 + "", () => {
      
     // Open dropdown
     cy.get('span.material-icons').eq(arg1).click()
   
     // Count number of options within the category (24)
     cy.get('.innerCol tr td.mat-column-name').should('have.length', arg2)
   
     // Validate events in each category
     cy.fixture('Notification_Events.json').then(function(testdata) {
       this.testdata = testdata
     
       cy.get('.innerCol tr td.mat-column-name').each(($ele, i) => {
         expect($ele).to.have.text(this.testdata.arg3[i])
       })
         
     })
 
     // Close the Dropdown
     cy.get('span.material-icons').eq(arg1).click()
   
     cy.wait(1000)
   
   }) // End of Allure Step
  
  } // End of Function
 
  // Uses checkEvents function to check contents of event categories
  checkEvents("0","45","Fault")
  checkEvents("1","36","Warning") 

Solution

  • The place where arg3 is used is this.testdata.arg3.

    It is using the saying "give me the property of testData called arg3".

    But arg3 contains the name of the property, so instead of testdata.arg3 you need to apply with square bracket notation:

    this.testdata[arg3][i]