Gradio uses [playwright](https://playwright.dev/docs/intro) to interact with gradio applications programmatically to ensure that both the frontend and backend function as expected.
Playwright is very powerful but it can be a little intimidating if you haven't used it before.
No one on the team is a testing expert so don't be afraid to ask if you're unsure how to do something.
Sometimes there may not be a retrying assertion for what you need to check.
In that case, you can retry any custom async function until it passes using `toPass` ([docs](https://playwright.dev/docs/test-assertions#expecttopass)).
Internal network calls are not visible to the user, so they can be refactored whenever.
If we have tests that rely on a request to a given route finishing before moving on, for example, they will fail if we ever change the route name or some other implementation detail.
It's much better to use a retrying assertion that targets a visible DOM element with a larger timeout to check if some work is done.
You can write the basic skeleton of the test automatically by just interacting with the UI!
First, start a gradio demo from the command line. Then use the following command and point it to the URL of the running demo:
```bash
npx playwright codegen <url>
```
This will open up a Chromium session where each interaction with the page will be converted into a playwright accessor.
NOTE: Only copy the `test("test-name", ....)` not the imports. For playwright to work when running in the gradio CI, `test` and `expect` need to be imported from `@gradio/tootils`.