<h3 dir="auto">System info</h3>
<ul dir="auto">
<li>Playwright Version: 1.32.3</li>
<li>Operating System: [macOS 13.2.1 (22D68)]</li>
<li>Browser: [Chromium]</li>
<li>Other info:</li>
</ul>
<h3 dir="auto">Source code</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I provided exact source code that allows reproducing the issue locally.</li>
</ul>




<p dir="auto"><strong>Link to the GitHub repository with the repro</strong></p>
<p dir="auto"><a href="https://github.com/hex0cter/playwright-locator-loop">playwright-locator-loop</a></p>
<p dir="auto">or</p>
<p dir="auto"><strong>Config file</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// playwright.config.ts

import { PlaywrightTestConfig } from &quot;@playwright/test&quot;;

const config: PlaywrightTestConfig = {
  timeout: 60 * 1000,
  retries: 0,
  snapshotDir: &quot;./snapshots&quot;,
  reporter: [
    [&quot;html&quot;, { outputFolder: `playwright-report` }],
    [&quot;line&quot;],
  ],
  projects: [
    {
      name: &quot;chrome&quot;,
      use: {
        browserName: &quot;chromium&quot;,
        channel: &quot;chrome&quot;,
        headless: true,
        viewport: { width: 1500, height: 730 },
        acceptDownloads: true,
        screenshot: &quot;only-on-failure&quot;,
        video: &quot;on&quot;,
        trace: &quot;on&quot;,
      },
    }
  ],
};

export default config;"><pre class="notranslate"><span class="pl-c">// playwright.config.ts</span>

<span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-v">PlaywrightTestConfig</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"@playwright/test"</span><span class="pl-kos">;</span>

<span class="pl-k">const</span> <span class="pl-s1">config</span>: <span class="pl-v">PlaywrightTestConfig</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">timeout</span>: <span class="pl-c1">60</span> <span class="pl-c1">*</span> <span class="pl-c1">1000</span><span class="pl-kos">,</span>
  <span class="pl-c1">retries</span>: <span class="pl-c1">0</span><span class="pl-kos">,</span>
  <span class="pl-c1">snapshotDir</span>: <span class="pl-s">"./snapshots"</span><span class="pl-kos">,</span>
  <span class="pl-c1">reporter</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">"html"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">outputFolder</span>: <span class="pl-s">`playwright-report`</span> <span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
    <span class="pl-kos">[</span><span class="pl-s">"line"</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-c1">projects</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">{</span>
      <span class="pl-c1">name</span>: <span class="pl-s">"chrome"</span><span class="pl-kos">,</span>
      <span class="pl-c1">use</span>: <span class="pl-kos">{</span>
        <span class="pl-c1">browserName</span>: <span class="pl-s">"chromium"</span><span class="pl-kos">,</span>
        <span class="pl-c1">channel</span>: <span class="pl-s">"chrome"</span><span class="pl-kos">,</span>
        <span class="pl-c1">headless</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
        <span class="pl-c1">viewport</span>: <span class="pl-kos">{</span> <span class="pl-c1">width</span>: <span class="pl-c1">1500</span><span class="pl-kos">,</span> <span class="pl-c1">height</span>: <span class="pl-c1">730</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
        <span class="pl-c1">acceptDownloads</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
        <span class="pl-c1">screenshot</span>: <span class="pl-s">"only-on-failure"</span><span class="pl-kos">,</span>
        <span class="pl-c1">video</span>: <span class="pl-s">"on"</span><span class="pl-kos">,</span>
        <span class="pl-c1">trace</span>: <span class="pl-s">"on"</span><span class="pl-kos">,</span>
      <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">]</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-s1">config</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Test file (self-contained)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  test(&quot;should select all checkboxes by a loop&quot;, async ({ page }) =&gt; {
    page.goto(
      &quot;https://staging.scrive.com/s/9221714692413010618/9221932570717574475/d0661b5e62380af4&quot;
    );
    await page.waitForLoadState();
    await page.waitForLoadState(&quot;networkidle&quot;);

    const checkboxes = await page.locator(&quot;rect[data-test='checkbox']&quot;).all();
    for (const checkbox of checkboxes) {
      await checkbox.click();
    }

    await expect(page.locator(&quot;[data-test='signview_sign_btn']&quot;)).toBeEnabled();
  });
"><pre class="notranslate">  <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">"should select all checkboxes by a loop"</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">{</span> page <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-s1">page</span><span class="pl-kos">.</span><span class="pl-en">goto</span><span class="pl-kos">(</span>
      <span class="pl-s">"https://staging.scrive.com/s/9221714692413010618/9221932570717574475/d0661b5e62380af4"</span>
    <span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">await</span> <span class="pl-s1">page</span><span class="pl-kos">.</span><span class="pl-en">waitForLoadState</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">await</span> <span class="pl-s1">page</span><span class="pl-kos">.</span><span class="pl-en">waitForLoadState</span><span class="pl-kos">(</span><span class="pl-s">"networkidle"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-k">const</span> <span class="pl-s1">checkboxes</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">page</span><span class="pl-kos">.</span><span class="pl-en">locator</span><span class="pl-kos">(</span><span class="pl-s">"rect[data-test='checkbox']"</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">all</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">const</span> <span class="pl-s1">checkbox</span> <span class="pl-k">of</span> <span class="pl-s1">checkboxes</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-k">await</span> <span class="pl-s1">checkbox</span><span class="pl-kos">.</span><span class="pl-en">click</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-k">await</span> <span class="pl-en">expect</span><span class="pl-kos">(</span><span class="pl-s1">page</span><span class="pl-kos">.</span><span class="pl-en">locator</span><span class="pl-kos">(</span><span class="pl-s">"[data-test='signview_sign_btn']"</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">toBeEnabled</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Steps</strong></p>
<ul dir="auto">
<li>npm install</li>
<li>npm test</li>
</ul>
<p dir="auto"><strong>Expected</strong></p>
<p dir="auto">All checkboxes should be checked by the end of the tests. And the Next button on the bottom should be enabled</p>
<p dir="auto"><strong>Actual</strong></p>
<p dir="auto">Some of the checkboxes are clicked multiple times and others are never clicked. When I looked at the trace, it seems when playwright loops through all the matching elements, it calls <code class="notranslate">locator.click(rect[data-test='checkbox'] &gt;&gt; nth=&lt;n&gt;</code> every time, and the order of that matched list may be non deterministic.</p>
<h3 dir="auto">System info</h3>
<ul dir="auto">
<li>Playwright Version: [1.32.2]</li>
<li>Operating System: [Windows 11]</li>
<li>Browser: [Chrome]</li>
<li>Other info: I haven't tested on other browsers and I can see this issue with versions above 1.30.0</li>
</ul>
<p dir="auto"><strong>Title:</strong> Browser closes unexpectedly when a test fails during Playwright Test execution</p>
<p dir="auto"><strong>Description:</strong> When running Playwright Test using the VSCode extension and executing a test suite with two spec.ts files in the same folder, the browser unexpectedly closes and relaunches when the first test fails. This behavior is not expected, as the browser should continue to remain open even if a test fails within the suite.</p>
<p dir="auto"><strong>Steps to Reproduce:</strong></p>
<ol dir="auto">
<li>Open VSCode and install the Playwright Test extension.</li>
<li>Create a test suite with two spec.ts files in the same folder.</li>
<li>Add at least one test to each spec file.</li>
<li>Execute the test suite using the "Run Test" option on the folder.</li>
<li>Observe the behavior of the browser during the execution of the tests.</li>
</ol>
<p dir="auto"><strong>Expected Results:</strong><br>
The browser should remain open throughout the entire execution of the test suite, regardless of whether any individual test fails.</p>
<p dir="auto"><strong>Actual Results:</strong><br>
When the first test fails during the execution of the test suite, the browser unexpectedly closes and then relaunches before the next test is executed.</p>