Rayrun
← Back to Discord Forum

comparing values in playwright

Let's assume we have 3 cards, inside which we have many things displayed. One of which are prices, which are coming from backend. So the question is, is there any way to compare these prices? Whether they are equal or not?

This thread is trying to answer question "Is there any way to compare prices coming from the backend in Playwright?"

5 replies

What is exact problem you're facing? Getting price values or comparing?

Comparing, I mean, prices are being displayed in the card. Now the problem that I'm facing is to read those prices and compare them in e2e scenarios

You can use locator.evaluate to get the text. Something like this: expect(await tweets.evaluate(node => node.innerText)).toBe('10 retweets'); https://playwright.dev/docs/next/api/class-locator#locator-evaluate

I assume you need it in a variable, so I think it's const textToCompare = yourlocator.evaluate(node => node.innerText);

Once they're stored thus, you can use standard javascript comparison functions

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].