DEV Community

Cover image for #005 | Tool Talk: Hello, Command Line
Nitya Narasimhan, Ph.D for Microsoft Azure

Posted on • Originally published at nitya.github.io on

#005 | Tool Talk: Hello, Command Line

This post was originally published on the Learn Playwright blog. Reference the original post to get the most updated version of this content.

Don't forget to follow the #playwright tag on dev.to for more community-authored articles on Playwright!

#playwright

Playwright is an open-source framework for Web Testing and Automation. It enables reliable end-to-end testing for modern web apps across browsers and platforms, using one API! Playwright supports resilient testing (with features like auto-wait, web-first assertions and tracing) with powerful tooling for authoring, debugging and profiling your end-to-end tests!

🔖 | Today's Resources


🗺 | Article Roadmap

I'm back after a week away - let's continue the #30DaysOfPlaywright journey with more Tool Talk!! Here's what today's post covers:

  • 1️⃣ | Follow #playwright on dev.to
  • 2️⃣ | Today's Objectives
  • 3️⃣ | A Visual Cheatsheet
  • 4️⃣ | Playwright CLI: Usage
  • 5️⃣ | Playwright CLI: Basic Commands
  • 6️⃣ | Playwright CLI: Try Examples
  • 7️⃣ | Playwright CLI: Command Options
  • 8️⃣ | Next Steps

1️⃣   Follow #playwright on dev.to

I've been publishing the #30DaysofPlaywright series on the dev.to platform. And I'm excited to say that I am now also moderating the #playwright tag there. Follow it for new posts from me and the community!

And I have an ask for you!!

Are you a beginner learning Playwright? Or an experienced tester with insights into Playwright usage with existing web frameworks or application scenarios? If so, do consider writing a dev.to post and tagging it with playwright! I'm monitoring that tag and want to read / amplify your posts!


2️⃣   Today's Objectives

In my last post I continued my learning journey by exploring Trace Viewer - a Playwright tool for post-mortem analysis of tracing-enabled test runs.

Today, I want to step back and look at the full spectrum of Command Line tools and options available to us for authoring, debugging, and analyzing, our testing runs. Some of these capabilities can also be configured and used from the Playwright API - something we'll explore in future posts.

For today, I'll focus on three things:

  • CLI commands - what tools can we launch from command line?
  • CLI options - how can we customize tool behaviors for our needs?
  • CLI examples - let's see how these work with practical use cases

3️⃣   A Visual Cheatsheet

You can browse the Command Line Tools documentation in depth - but if you're a visual-spatial learner like me, you might benefit from seeing a big picture before diving into the details. So here's my visual cheatsheet to the various tools and options provided by Playwright CLI.

I created this from the --help screens for Playwright v1.17.1. Start exploration at the yellow rectangle, then follow arrows pointing to deep-dives into individual commands. Run highlighted commands (per area) in your terminal for usage updates related to your installed Playwright version.

Consider downloading the hi-res image and using it - as a printout or as desktop wallpaper - to give yourself a handy reference to guide our CLI exploration!

Visual Guide to Playwright Command Line


4️⃣   Playwright CLI: Usage

The Command Line Tools documentation page has a great reference with examples, but the best way explore the CLI is interactively. Try this:

// Check your installed version of Playwright
$  npx playwright -V
Version 1.17.1

// Get help on Playwright CLI commands available
$npx playwright --help
Usage: npx playwright [options] [command]
...
<truncated for clarity>

// Get help on usage + options for specific CLI command
// Ex: for `open` command
$ npx playwright open --help
Usage: npx playwright open [options] [url]

open page in browser specified via -b, --browser
Options:
...
<truncated for clarity>
Enter fullscreen mode Exit fullscreen mode

Check out the visual cheatsheet to see the --help outputs for all commands to get a sense of the extent of supported options for each.


5️⃣   Playwright CLI: Basic Commands

For convenience, here is a simplified table of the main Playwright CLI commands available now (v1.17.1) with links to relevant documentation pages.

Commands Description
install installs browsers needed for this Playwright version
install-deps installs system dependencies for supported browsers
open opens the specified page in the default browser (cr = chromium)
cr = open in chromium
fr = open in firefox
wk = open in webkit
opens the specified page in the specified browser
(same open options)
screenshot opens specified page, then
captures page screenshot
pdf opens specified page, then
saves page as pdf
codegen opens specified page, then
launches Test Generator, creating test code (script) from user actions.
test launches Playwright Test runner using default configuration file (CLI options take priority, if specified)
show-trace launches Trace Viewer (PWA) for interactive analysis of trace zipfiles.
show-report launches HTML Reporter webpage on local server, for test run analysis.

The final four commands in this list are likely to find the most use - so I'll explore each in a separate post. Ex: check out the Trace Viewer post to learn about show-trace and it's usage for post-mortem analysis of test runs.


6️⃣   Playwright CLI: Try Examples

Let's do a quick run through of a subset of the command-line examples and use these to understand the Playwright CLI options with a real world context. In the video below, I walk through the examples using this script - try it out yourself in your local environment.


7️⃣   Playwright CLI: Command Options

For convenience, here's a recap of key options defined for use in the Playwright CLI. Use --help with a specific command (or refer to the visual cheatsheet), to learn which options are applicable to each command.

Option Description
--browser <browserType> use a specific browser (options are cr=chromium, ff=firefox, wk=webkit) with default=cr
--channel <distribution> for chromium-based browsers - see channel options for chrome, msedge
--device <name>
--user-agent <ua-string>
--viewport-size <size>
emulate mobile browser contexts using supported parameters -- see device descriptors for valid values.
--timezone <time-zone>
--lang <lang>
--geolocation <lat,long>
emulate browser context for these parameters - see Locale/Timezone, Language tags, Geolocation values.
--color-scheme <dark,light> emulate context with dark or light mode
--timeout <timeout> set timeout for Playwright test actions to complete, in ms (default "10000")
--save-storage <filename>
--load-storage <filename>
preserve state (e.g., cookies, localStorage) for reuse across sessions e.g., for authentication
--ignore-https-errors ignore HTTPS errors on network requests
--proxy-server <proxy> specify URL of proxy server to use
--wait-for-selector <selector> (use with screenshot and pdf) - wait for selector to take action
--wait-for-timeout <timeout> (use with screenshot and pdf) - wait for timeout (in ms) to take action
--full-page (use with screenshot) - capture full page (entire scrollable area)
--output <filename> (use with codegen) save the generated script to this filename
--debug (use with test) runs Playwright Test with Inspector for debugging

The playwright test command has a much richer set of options that we will revisit in a separate post about Playwright Test runner.


8️⃣   Next Steps

We explored Command Line Tools at a high level, and tried out examples for a subset of CLI commands. But there are four commands that will get a lot more usage so we'll explore these in separate posts coming up next.

Top comments (0)