<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Dennis Bergevin</title>
    <description>The latest articles on Forem by Dennis Bergevin (@dennisbergevin).</description>
    <link>https://forem.com/dennisbergevin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2865013%2F0ee17689-04fa-411b-b31d-636aa96947ff.png</url>
      <title>Forem: Dennis Bergevin</title>
      <link>https://forem.com/dennisbergevin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dennisbergevin"/>
    <language>en</language>
    <item>
      <title>🎭 playwright-cli-select</title>
      <dc:creator>Dennis Bergevin</dc:creator>
      <pubDate>Sat, 15 Feb 2025 18:39:15 +0000</pubDate>
      <link>https://forem.com/dennisbergevin/playwright-cli-select-12j</link>
      <guid>https://forem.com/dennisbergevin/playwright-cli-select-12j</guid>
      <description>&lt;h2&gt;
  
  
  Problem context
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://playwright.dev/" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt; comes out of the box with a collection of ways to run test files, test titles, and test tags, including the &lt;a href="https://playwright.dev/docs/getting-started-vscode" rel="noopener noreferrer"&gt;VS Code extension&lt;/a&gt; and &lt;a href="https://playwright.dev/docs/test-ui-mode" rel="noopener noreferrer"&gt;UI Mode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However, I had conversations with colleagues at work who wanted to run Playwright end-to-end tests on their local machine and have an easier time in the terminal running specific tests or suites, maybe a couple tags, and a test file all in one run.&lt;/p&gt;

&lt;p&gt;That was where I noticed a gap in test tool enablement, and what prompted me to work on &lt;a href="https://github.com/dennisbergevin/playwright-cli-select" rel="noopener noreferrer"&gt;playwright-cli-select&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa60vy1ua911fldh4u980.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa60vy1ua911fldh4u980.png" alt="playwright-cli-select demo" width="800" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do I use this?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Interactive buddy:&lt;/strong&gt; Use with any of your desired Playwright command line parameters while using an interactive interface including test files, suite/test titles, and/or tags available in your project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Discoverability enhancement:&lt;/strong&gt; If a user wants to run tests on their local machine but... &lt;/p&gt;

&lt;p&gt;a. Doesn't know &lt;em&gt;which&lt;/em&gt; files, suites/tests or tags are available to choose from&lt;br&gt;
b. They don't know &lt;em&gt;how&lt;/em&gt; to run a specific collection of files/tests/tags&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Customize tests to run:&lt;/strong&gt; Maybe some tests just failed and you want to run Playwright's &lt;a href="https://playwright.dev/docs/running-tests#run-last-failed-tests" rel="noopener noreferrer"&gt;--last-failed&lt;/a&gt; flag to inspect but you don't want to run &lt;em&gt;all&lt;/em&gt; of the failed tests, or maybe you want to run Playwright's &lt;a href="https://playwright.dev/docs/release-notes#--only-changed-cli-option" rel="noopener noreferrer"&gt;--only-changed&lt;/a&gt; but have option to choose a specific &lt;em&gt;test&lt;/em&gt; in a changed spec and not &lt;em&gt;all&lt;/em&gt; tests in the changed spec.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvopekmep9z3y0n4dp9bk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvopekmep9z3y0n4dp9bk.png" alt="playwright-cli-select with --only-changed" width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6r4ihb2kemkytybzcd9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6r4ihb2kemkytybzcd9.png" alt="playwright-cli-select with --last-failed" width="800" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Increase independence:&lt;/strong&gt; If you are looking for a local development tool to enable your colleagues to run Playwright tests without a bunch of documentation or reference for which command to run or how to run tests, then look no further!&lt;/p&gt;
&lt;h2&gt;
  
  
  How do I use this?
&lt;/h2&gt;

&lt;p&gt;The package is available on &lt;a href="https://github.com/dennisbergevin/playwright-cli-select" rel="noopener noreferrer"&gt;Github&lt;/a&gt; and via &lt;a href="https://www.npmjs.com/package/playwright-cli-select" rel="noopener noreferrer"&gt;npm&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once installed, users can run a base command in their Playwright project and include any &lt;a href="https://playwright.dev/docs/test-cli" rel="noopener noreferrer"&gt;Playwright specific command line parameters/flags&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# base command for interactive cli prompts
npx playwright-cli-select run

# Example: user wants to choose tests given a specific project
npx playwright-cli-select run --project=chrome

# Example: user wants to run a specific changed test
npx playwright-cli-select run --only-changed --titles

# Example: user wants to run a specific last failed test
npx playwright-cli-select run --last-failed --titles
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, there is a &lt;code&gt;--help&lt;/code&gt; command available showing available package-specific parameters:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft50lardd5hfp8c65ym2t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft50lardd5hfp8c65ym2t.png" alt="playwright-cli-select help menu" width="800" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Under the hood
&lt;/h2&gt;

&lt;p&gt;When you run &lt;code&gt;npx playwright-cli-select run&lt;/code&gt; in your Playwright project, it is using &lt;code&gt;npx playwright test --list --reporter=json&lt;/code&gt; command under the hood, with allowance for any Playwright command line arguments, to gather available test files, suites, tests, and tags.&lt;/p&gt;

&lt;p&gt;The available test files, suites, tests and tags are then displayed in interactive prompts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hint 1:&lt;/strong&gt; Passing arguments to a flag such as &lt;code&gt;--project&lt;/code&gt; would be passed onto this &lt;code&gt;--list&lt;/code&gt; command, which will show all test files, suites, tests, and tags associated with that specific project. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hint 2:&lt;/strong&gt; Passing &lt;code&gt;--last-failed&lt;/code&gt; and &lt;code&gt;--only-changed&lt;/code&gt; will alter the results from the &lt;code&gt;--list&lt;/code&gt; command, allowing you to tailor the choices seen in the various prompts to dial deeper into a specific test from those commands.&lt;/p&gt;

&lt;p&gt;Rather than using Playwright's &lt;code&gt;--grep&lt;/code&gt; to pass selections to &lt;code&gt;npx playwright test&lt;/code&gt; command for starting a test run, the &lt;code&gt;file:line&lt;/code&gt; method is used (i.e. &lt;code&gt;my-spec.ts:42&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
        {
          "title": "Routing",
  ------&amp;gt; "file": "demo-todo-app.spec.ts",
  ------&amp;gt; "line": 382,
          "column": 6,
          "specs": [
            {
              "title": "should allow me to display active items",
              "ok": true,
              "tags": [],
              "tests": [
                {
                  "timeout": 30000,
                  "annotations": [],
                  "expectedStatus": "passed",
                  "projectId": "chromium",
                  "projectName": "chromium",
                  "results": [],
                  "status": "skipped"
                }
              ],
              "id": "849da1cee0c412ce5534-168ac99248367a9c5f75",
     ------&amp;gt;  "file": "demo-todo-app.spec.ts",
     ------&amp;gt;  "line": 391,
              "column": 7
            },
            {
              "title": "should respect the back button",
              "ok": true,
              "tags": [],
              "tests": [
                {
                  "timeout": 30000,
                  "annotations": [],
                  "expectedStatus": "passed",
                  "projectId": "chromium",
                  "projectName": "chromium",
                  "results": [],
                  "status": "skipped"
                }
              ],
              "id": "849da1cee0c412ce5534-f4a7bfde65c589b439d6",
      ------&amp;gt; "file": "demo-todo-app.spec.ts",
      ------&amp;gt; "line": 401,
              "column": 7
            },
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While &lt;code&gt;--grep&lt;/code&gt; has it's obvious uses and is very powerful, there are many considerations and complexities when enabling test selection using this command, notably that different shells require different escaping using &lt;code&gt;--grep&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Additionally, it can become tedious crafting a long &lt;code&gt;--grep&lt;/code&gt; of multiple OR conditions if you are looking to run various combinations of test files, suites, tests and tags.&lt;/p&gt;

&lt;p&gt;The playwright-cli-select will parse the &lt;code&gt;--list&lt;/code&gt; of available test files, suites, tests and tags and store the &lt;code&gt;file:line&lt;/code&gt; for each suite, test, and tag. Then, when a user picks a given selection, the stored &lt;code&gt;file:line&lt;/code&gt; will be sent as argument to the &lt;code&gt;npx playwright test&lt;/code&gt; command to run the selections.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where can I get more info?
&lt;/h2&gt;

&lt;p&gt;More information can be seen in the project repository &lt;a href="https://github.com/dennisbergevin/playwright-cli-select" rel="noopener noreferrer"&gt;README&lt;/a&gt;, so be sure to check it out and feel free to give the project a star!&lt;/p&gt;

</description>
      <category>playwright</category>
      <category>cli</category>
      <category>testing</category>
      <category>tooling</category>
    </item>
  </channel>
</rss>
