Rayrun
← Back to Discord Forum

Checking an array of strings.

I am checking my console errors like this: page.on("console", (message) => { if (message.type() === "error") { errorLogs.push(message.text()) } }) where i push the error message and the page.title() to the errorlogs, but after i want to check the errorlogs array if it contains the title. But this doesn't work: await expect(errorLogs).toContain(title); Is there a way with playwright i can check the array for just a specific string, and not the entire errormessage i'm adding?

This thread is trying to answer question "How can I check an array for a specific string, and not the entire error message I'm adding, using Playwright?"

1 reply
peritektikum
peritektikum
let arrFiltered = errorLogs.filter((errMsg) => {
  return errMsg.includes(specificString);
});

you can just filter your array by a specific string

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].