Search code examples
typescriptplaywrightplaywright-typescript

How to validate string values in a list of string using playwright


I have a list of string values in a array.

I have to validate above array strings with the present titles are present in the application.

I have tried to validate multiple_Columns with headerTitlesPresent but my test case is failing.

can someone please suggest which assertion I should use.

const multiple_Columns = ["apple","banana","pine"]
const headerTitlesPresent = await homePage.header_Titles
expect(await headerTitlesPresent.allTextContents()).toContain(multiple_Columns)
await expect(headerTitlesPresent).toHaveText(multiple_Columns)

Solution

  • You can try my code:

    const multiple_Columns = ['apple', 'banana', 'pine']
            const headerTitlesPresent: string =
                await homePage.header_Titles.innerText()
            let matches = 0
            multiple_Columns.forEach(function (value) {
                if (headerTitlesPresent.includes(value)) {
                    matches++
                }
            })
            if (matches == multiple_Columns.length) {
                // full match
            } else {
                // not a full match
            }