Enjoy free content straight from your inbox 💌
00:00
In addition to excellent tooling within Visual Studio Code playwright also comes with great support for the command line. Here we have two test files, math dot spec and Google Do Spec. We can run all our tests by executing the command NPX playwright test. This will run both our tests against the three projects that we have configured resulting in six test executions. The play test command takes a number of additional arguments. For example, if you only want to run a specific test file, we can pass in a pattern that matches that file. For example, if you pass in Google and it'll only run Google do spect ts,
00:34
we can also modify the output of the test command by using a reporter option. For example, we can pass in minus minus reporter equal to list to get a more verbose and a very clear display of the different tests that are running. Right now, the spec is still running against the three different projects, but we can change that with the minus minus project flag. For example, we can run the tests against just the chromium project and now we have just the Google spec running against just chromium. Another command line flag both knowing about is minus minus headed.
01:06
By default, the test run in headless mode, but with minus minus headed, you will be able to see the different browsers that are actually executing our test. It's great for showing all your automation work and it's useful when you have some errors in your test to make it easy to run. Pay right on the command line without having all of the arguments memorized. You can add scripts to your package. Do Jason file, which provides an easy way to share common commands with other team members. You will add a new script within our package or Jason script section called test, and this script will run playwright test Minus minus Reporter equal list.
01:40
Feel free to add additional scripts within your package Es, or modify the Command Nine Flags to your own personal preference. To run a script, we open up the CLI and execute NPM Run, followed by the script name, which in our case is called test. This will execute the script playwright test with the argument that we provided, which is report A list. A neat trick to know about NPM scripts is that we can actually pass in additional command nine flags to the underlying script by using minus minus, for example, minus minus, followed by space, followed by math, will essentially run playwright test minus minus reporter
02:14
equal list, followed by the additional argument, which is math. This means that we can build upon test to build even more complicated scripts. For example, we can add a new script called Test dash Chrome, which basically runs in pm run test, followed by additional flag minus, minus project equal chromium. So now if you open up the terminal and execute NPM Run test dash chrome math, it'll only run the spec math against chromium.