jeudi 9 janvier 2020

Testcafe: .includes() is not a function when used in an if/else statement

I am trying to use an if/else statement on one of my Testcafe cases but the condition is to see if a string contains a word (substring) and if it does run if not go to else

Here is an example code:

const textData = Selector('.css-f3fafa').innerText;

        if (textData.includes("Administrator") ) {
            await t
            .hover(button1)
            .expect(button).eql('Submit')
            .click(buttonUp)
            .setNativeDialogHandler(() => true)
            .click(modalSub)
            .wait(5000)
            .expect(thank).eql('Thank you for your submission.')

        } else {
            await t
            // .hover(button1)
            // .expect(button).eql('Sign Up')
            .expect(textData).contains('Administrator')
            .click(button1)
            .expect(getStarted).ok('Get Started')
        }

I keep getting a type error: textData.includes... is not a function but if I did .expect(textData).includes... that works just fine and it passes. I also tried indexOf, adding a === true to the condition, I tried adding String() to the variable and that kinda worked but it skipped right to the else (Doesn't pass the If even when the condition is true)

Is there another way I can make this condition work with Testcafe?

Aucun commentaire:

Enregistrer un commentaire