How to Select Random Option with Playwright

Situation My task was to create random test data for an application, which didn’t have an API for data creation. I simply chose to write e2e tests with Playwright and I only had to figure out how to select random values. Solution After googling, looking on Stackoverflow and asking ChatGPT - I managed to write the following code. import { test } from '@playwright/test' test('select random option', async ({ page }) => { // you can also use any other locator const select = page....

May 4, 2024 · 1 min · 131 words · Phuc Tran