samedi 4 septembre 2021

Cypress, If statement not working no matter what i try

I'm trying to do a simple test in Cypress to see if a field is read only but no matter what i try i cant get the if statement to work, ive checked the cypress documentation and been through a load of different types of examples, i normally dont have an issue grabbing hold of elements and working with them but i'm a bit stumped with this, what am i missing?:

(Ive tried this with .hasClass and .find but still no luck, ive also tried using the other attributes of the element but nothing works)

Heres the html code for the field i want to interact with:

textarea _ngcontent-nud-c545="" rows="1" cdktextareaautosize="" aria-label="Product name" matinput="" type="text" placeholder="'Enter a product name...'" required="" formcontrolname="productName" class="cdk-textarea-autosize mat-input-element mat-form-field-autofill-control ng-tns-c98-55 ng-pristine ng-valid cdk-text-field-autofill-monitored ng-touched" ng-reflect-enabled="" ng-reflect-type="text" ng-reflect-placeholder="'Enter a product name...'" ng-reflect-required="" ng-reflect-name="productName" id="mat-input-3" data-placeholder="'Enter a product name...'" aria-invalid="false" aria-required="true" style="height: 21px;"> textarea

Heres my code to grab it and test to see if it includes text 'productName':

cy.get('[formcontrolname="productName"]').then (($productName) => {

  if ($productName.text().includes('productName')) {
    cy.log('its found it');

  } else {
    cy.log('it hasnt found it');
  }

});

No matter what i try the if statement goes to 'it hasnt found it'

Aucun commentaire:

Enregistrer un commentaire