Transcripted Summary

By the end of this video, you will be able to record and play a script using Playwright's common line utility (CLI).

Playwright has a common line utility that is really useful in order to generate these scripts without having to actually code. Let me show you how this works.

You have to start by typing npx in the common line or in this terminal and then playwright codegen and then the URL.


npx playwright codegen https://www.saucedemo.com

We just wait a little bit and it's going to launch the Playwright inspector.



And if you notice it is actually doing what we have been doing so far.

It requires Playwright first, then is launching chromium because it's using chromium, creating a new context, and then a new page to later go to the webpage that I set off when I was typing on the common line.

What we can do is start trying to use this web page.



So let me just quickly go and log in with “standard_user”.

And as you can see, it is writing things on the left while I'm typing on here.



So let me just log in as well. You go to the login button.

Let's just add this backpack to our cart.

And then if we go to the backpack, let's checkout and I'm going to add my name, my last name, add zip code here.

You can tell it's actually even helping us with the selectors, which is something pretty useful,



Now continue and then we can do finish.

So, we're done with an end to end flow here, right?

**What I'm going to do is I'm going to stop here and I'm going to copy this code that is generated for us. **



Let's give it a try so we can actually see it working.

I'm going to create a new file, which I'm going to name cli.js.

And I'm going to paste the code that we copied from the inspector, where it was creating the code for us. I'm just copy/pasting it as it is.

Let's save these and let's run it — node cli.js — and it's launching the exact same thing that I did.



So, I think this command line utility did a pretty decent job for this script.



Resources



© 2024 Applitools. All rights reserved. Terms and Conditions Privacy Policy GDPR