Search code examples
javascriptchaiplaywright

Playwright - Chai - Validate if String is Enabled


I'm working with Javascript, Playwright and Chai assertions. When I try to validate if a button is enabled (Chai assertions) executions fails.

async wasEmail100CharactersFilled() {
    //expect(verifyEmailButton).to.not.be.disabled() //Not working
    should.exist(verifyEmailButton.toBeEnabled()) //Not working
  }

Verify email button is an String.

Can anybody help me with this?

EDITED

This is the element when is disabled:

<button type="button" class="btn btn-primary min-h-0 h-10 w-full rounded-full flex-shrink-0 capitalize  rounded-full normal-case disabled:cursor-not-allowed text-sm" xpath="1" disabled=""><i class="hidden h-6 w-0 "></i>Verify Email<i class="hidden h-6 w-0 "></i></button>

The same when it's enabled:

<button type="button" class="btn btn-primary min-h-0 h-10 w-full rounded-full flex-shrink-0 capitalize  rounded-full normal-case disabled:cursor-not-allowed text-sm" xpath="1"><i class="hidden h-6 w-0 "></i>Verify Email<i class="hidden h-6 w-0 "></i></button>

I still trying with this assertion for the String, but it's not working:

await page.$eval(verifyEmailButton, el => el.classList.contains("disabled"));

Solution

  • This was the only thing that worked for me:

    if(await page.$eval(verifyEmailButton, el => el.disabled = true)){
                console.log("Button is Disabled")
            } else {throw Error("Button is Enabled");}
        }
    

    Thanks for your help.