Let AI Explore Your Site & Write Tests with Playwright MCP!

Playwright www.youtube.com

Brief Summary

This video demonstrates how to use Playwright's agent mode with the MCP server to automatically generate tests by exploring a website. The agent navigates the site, identifies key functionalities, and writes tests based on its actions. The demonstration reveals a bug in the search functionality and showcases the agent's ability to create a test for the movie search feature, which passes successfully. The video also shows how to use the trace viewer to examine the agent's actions and iterate on the generated tests.

  • Agent mode automates test creation by exploring a website.
  • The MCP server helps identify edge cases and bugs.
  • Trace viewer allows detailed examination of the agent's actions.

Introduction

The presenter introduces a setup with the MCP Playwright server running locally within a VS Code project. The goal is to use a "generate test" prompt, leveraging Playwright in agent mode, to automatically create tests by exploring a website. The presenter emphasizes that there is no manual access to test files, and the intention is for the co-pilot and agent to navigate the website, browse as a user would, identify key functionalities, and then write tests based on the actions performed.

Agent Exploration and Bug Discovery

The agent begins by using the search function and entering "Star Wars." A discrepancy is immediately detected: while the search term and results say "Star Wars," the movie displayed is "kill." This reveals a bug in the search functionality that the presenter had not previously encountered during testing with other terms like "Garfield," "Deadpool," and "Avengers." The agent then uses the theme toggle feature, switching from dark to light mode. Although the presenter requested only one test, the agent identifies five potential functionalities to test: the homepage, search functionality, movie details page, theme toggle, and navigation.

Test Implementation and Execution

The agent chooses to implement a test for the movie search functionality, which it deems the most important. After fixing a lint error, the agent runs the test to verify its functionality. The test passes successfully. The presenter expresses satisfaction with the generated code and the test's outcome.

Review and Summary

The agent provides a summary of its actions, which can be used for creating a pull request. The presenter then uses the trace viewer in VS Code to examine the agent's actions in detail. The trace shows the agent searching for "Star Wars" and then clicking on "Deadpool." The presenter notes that the movie updates might not be immediate due to page loading behavior. The trace viewer allows for a thorough review of the agent's steps, enabling improvements and further test creation.

Conclusion

The presenter concludes by highlighting the power of Playwright MCP in automatically generating tests through website exploration. By simply providing a URL and a test prompt, the agent can identify bugs and suggest improvements. The presenter encourages viewers to test it out and explore their sites to discover potential issues and enhancements.

Summarize any YouTube video in seconds

Get summaries like this one for any video, in your language, with the free Summ app.

Download on the Apple Store
Get it on Google Play

Transcript

Full transcript of “Let AI Explore Your Site & Write Tests with Playwright MCP!”. Click a timestamp to open the video at that moment. Need another video? Use the YouTube transcript generator.

0:00 Hey everyone. I've got the MCP Playright server running here locally in my VSS code folder just in this project. And I've got a generate test prompt um that is basically using playwright and agent mode to create some tests based on exploring a website. So I've got no access to the actual uh test files here. I want a co-pilot and I want the agent to just go along and um use the MCP server to navigate to the website, search through the website as a user would navigate u browse it and come up with a couple of key functionalities and then write some tests based on the actual actions that it has performed. So uh we can see here it's trying to use the search function and it's going to type in Star Wars. Now look at this. Straight away the search term we call

0:45 Star Wars. The search results say Star Wars, but the movie says kill. So, there's something going on there. Now, I need to actually go and fix that because that doesn't look like great, but that's a really good scenario that came up just now because when I've been testing this website, I've been putting in Garfield and Deadpool and Avengers and the results have been perfect every time. So, as far as I'm concerned, my search works. And I've just seen using the MCP server, my search doesn't work as expected. It's touched it's found an edge case that I didn't find. So, that's kind of really cool. Um, it's uh now going to use the theme toggle feature. So, it's clicking the toggle switch to change the theme. We're already in dark mode. It's now gone to light mode. So, uh that's great. It's searching that that works. Um, now I did ask it for

1:30 only one test. So, um, it's just closed the browser there. I did ask it to do that. That's great. And it's going to summarize its findings. So, it'll be interesting to see what test it decides to write. Um so the exploration right it's on the homepage uh the search functionality the movie details page um giving a list of all that movie details and the theme toggle and the navigation. So there's five things it's found and it's going to implement a test for the movie search functionality. That's the one it's chosen as its favorite or the most uh important one. But because I have these other ones here, I can basically then say go ahead and write tests for all those other um functionalities. But I only wanted one just for this demo just to keep it quick

2:16 and easy. Um so fixed a lint error there. That's that's great. Thank you, Agent Mood. And um now it's going to run the test to see if it works. So, it's opening up the terminal and it's going to run the test and running one test. And the test seems to have worked. The test passed. So, that is fantastic. There's our test. The test has passed. Now, we didn't see anything. We don't know if that works as it is meant to. It looks good to me. Uh code looks great. Um I mean, are we happy with that? I'm pretty happy with that. But we can always uh check it out and work it ourselves. So, uh, once agent mode is finished doing what it's doing, it's giving us a summary of all the things it's done. That's great because I can use that summary then to, um, you know,

3:03 create a pull request and, um, make sure it's done what it's done. So, we'll go ahead and keep that file. Now, I'm just going to go in here to my test explorer and I'm going to choose, um, show trace viewer and I'm just going to press play here in VS Code. So, it's going to open up the trace viewer for me. And then I can go along and I can actually see um it's a little bit small there. So, let's just zoom in. Um and you can see, let's do it full size. You can see there. Search for movie. And there I typed in Star Wars and we got Star Wars back. So, it did actually search for that. Now, the movies might not update. That's just how the page um loading happens. But then it went along and clicked on Deadpool. And again, that's something that I could definitely go ahead and fix in the application itself. It's found Deadpool movie. And

3:51 then it's gone ahead and clicked true um through the titles and checked to see if it has specific titles. Um and then it's gone ahead and we've got Star Wars and it's got checked for this. So again, this is pretty cool because you can go ahead and check uh what's just happened, what it's actually done, and uh then you can go back and basically improve that and iterate over it um and then create more tests. But that was pretty good for just literally navigate, explore this URL and uh use this uh test prompt file to to basically just come up with and I just said one, right? If I had had five, it would have given me five tests. So very very powerful. um things you can do

4:37 with the Playright MCP. So, go ahead and test it out. Go and get it to explore a site and see what it comes up with. You'll be surprised how many bugs you might find uh and how many improvements you can make to your site. Hobby testing with Playride.

Share

More video summaries