<p dir="auto">Great work on <code class="notranslate">connectOverCDP</code> <g-emoji class="g-emoji" alias="+1" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png">👍</g-emoji> I am loving the ability to connect to an existing instance rather than launch a new chrome every time.</p>
<p dir="auto"><strong>Context:</strong></p>
<ul dir="auto">
<li>Playwright Version: 1.9.1</li>
<li>Operating System: Mac</li>
<li>Node.js version: 12.x</li>
<li>Browser: Chromium</li>
</ul>
<p dir="auto"><strong>Code Snippet</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
const { chromium } = require(&quot;playwright&quot;);

(async () =&gt; {
	const browser = await chromium.connectOverCDP({
                // NOTE: change this with ws URL by launching chrome with CDP
		wsEndpoint: `ws://127.0.0.1: 56685/devtools/browser/a5d5af82-e168-4ebb-8b87-199c3e5dc260`,
	});
	const contexts = browser.contexts();
	const browserContext = contexts[0];
	const page = await browserContext.newPage();
	await page.goto(&quot;https://playwright.dev&quot;);
})();"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-kos">{</span> chromium <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"playwright"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-kos">(</span><span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
	<span class="pl-k">const</span> <span class="pl-s1">browser</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">chromium</span><span class="pl-kos">.</span><span class="pl-en">connectOverCDP</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
                <span class="pl-c">// NOTE: change this with ws URL by launching chrome with CDP</span>
		<span class="pl-c1">wsEndpoint</span>: <span class="pl-s">`ws://127.0.0.1: 56685/devtools/browser/a5d5af82-e168-4ebb-8b87-199c3e5dc260`</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">const</span> <span class="pl-s1">contexts</span> <span class="pl-c1">=</span> <span class="pl-s1">browser</span><span class="pl-kos">.</span><span class="pl-en">contexts</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
	<span class="pl-k">const</span> <span class="pl-s1">browserContext</span> <span class="pl-c1">=</span> <span class="pl-s1">contexts</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
	<span class="pl-k">const</span> <span class="pl-s1">page</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">browserContext</span><span class="pl-kos">.</span><span class="pl-en">newPage</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">goto</span><span class="pl-kos">(</span><span class="pl-s">"https://playwright.dev"</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></pre></div>
<p dir="auto"><strong>Describe the bug</strong><br>
Error log:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[1] app: 2021-02-28T03:57:53.593Z app:debug 1614484673593 -&gt; Chrome Endpoint: ws://127.0.0.1:56685/devtools/browser/a5d5af82-e168-4ebb-8b87-199c3e5dc260
[1] app: 2021-02-28T03:57:53.643Z app:warn 1614484673641 -&gt; Error: Duplicate target 3E6BA14AC5D3C8825FC23623D1B55050
[1] app:     at Object.assert (/Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/utils/utils.js:80:15)
[1] app:     at CRBrowser._onAttachedToTarget (/Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/server/chromium/crBrowser.js:152:17)
[1] app:     at CRSession.emit (events.js:315:20)
[1] app:     at CRSession.EventEmitter.emit (domain.js:483:12)
[1] app:     at /Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/server/chromium/crConnection.js:157:22
[1] app:     at runNextTicks (internal/process/task_queues.js:62:5)
[1] app:     at processImmediate (internal/timers.js:429:9) Promise { &lt;rejected&gt; Error: Duplicate target 3E6BA14AC5D3C8825FC23623D1B55050 at Object.assert (/Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/utils/utils.js:80:15) at CRBrowser._onAttachedToTarget (/Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/server/chromium/crBrowser.js:152:17) at CRSession.emit (events.js:315:20) at CRSession.EventEmitter.emit (domain.js:483:12) at /Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/server/chromium/crConnection.js:157:22 at runNextTicks (internal/process/task_queues.js:62:5) at processImmediate (internal/timers.js:429:9) }"><pre class="notranslate"><code class="notranslate">[1] app: 2021-02-28T03:57:53.593Z app:debug 1614484673593 -&gt; Chrome Endpoint: ws://127.0.0.1:56685/devtools/browser/a5d5af82-e168-4ebb-8b87-199c3e5dc260
[1] app: 2021-02-28T03:57:53.643Z app:warn 1614484673641 -&gt; Error: Duplicate target 3E6BA14AC5D3C8825FC23623D1B55050
[1] app:     at Object.assert (/Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/utils/utils.js:80:15)
[1] app:     at CRBrowser._onAttachedToTarget (/Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/server/chromium/crBrowser.js:152:17)
[1] app:     at CRSession.emit (events.js:315:20)
[1] app:     at CRSession.EventEmitter.emit (domain.js:483:12)
[1] app:     at /Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/server/chromium/crConnection.js:157:22
[1] app:     at runNextTicks (internal/process/task_queues.js:62:5)
[1] app:     at processImmediate (internal/timers.js:429:9) Promise { &lt;rejected&gt; Error: Duplicate target 3E6BA14AC5D3C8825FC23623D1B55050 at Object.assert (/Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/utils/utils.js:80:15) at CRBrowser._onAttachedToTarget (/Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/server/chromium/crBrowser.js:152:17) at CRSession.emit (events.js:315:20) at CRSession.EventEmitter.emit (domain.js:483:12) at /Users/vikramtiwari/Documents/code/app/packages/node_modules/playwright/lib/server/chromium/crConnection.js:157:22 at runNextTicks (internal/process/task_queues.js:62:5) at processImmediate (internal/timers.js:429:9) }
</code></pre></div>
<p dir="auto">First time connection works properly but next time I try to connect to same WS URL, I see this error.</p>
<p dir="auto"><strong>Context:</strong></p>
<ul dir="auto">
<li>Playwright Version: <code class="notranslate">"@playwright/test": "^1.28.1",</code></li>
<li>Operating System: Mac</li>
<li>Node.js version: 16</li>
<li>Visual Studio Code version: Version: 1.74.1</li>
<li>Playwright for VSCode extension version: v1.0.1</li>
<li>Browser: N/A</li>
<li>Extra: N/A</li>
</ul>
<p dir="auto"><strong>Code Snippet</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function getTestData() {
  return [1, 2];
}

// THIS IS THE ONLY ONE PROPERLY DETECTED BY TEST RUNNER AS A TEST THAT CAN BE EXECUTED
test.describe('Quote - Existing Account - Test Quote Prices', () =&gt; {
  const testCases = [1, 2];
  for (const x of testCases) {
    test('my test', async () =&gt; {
      // fake
    });
  }
});

const testCases = [1, 2];

test.describe('Quote - Existing Account - Test Quote Prices', () =&gt; {
  for (const x of quoteTestCases) {
    test('my test', async () =&gt; {
      // fake
    });
  }
});

test.describe('Quote - Existing Account - Test Quote Prices', () =&gt; {
  for (const x of testCases) {
    test('my test', async () =&gt; {
      // fake
    });
  }
});

test.describe('Quote - Existing Account - Test Quote Prices', () =&gt; {
  for (const x of [1, 2]) {
    test('my test', async () =&gt; {
      // fake
    });
  }
});"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">getTestData</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-c">// THIS IS THE ONLY ONE PROPERLY DETECTED BY TEST RUNNER AS A TEST THAT CAN BE EXECUTED</span>
<span class="pl-s1">test</span><span class="pl-kos">.</span><span class="pl-en">describe</span><span class="pl-kos">(</span><span class="pl-s">'Quote - Existing Account - Test Quote Prices'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-k">const</span> <span class="pl-s1">testCases</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</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">x</span> <span class="pl-k">of</span> <span class="pl-s1">testCases</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">'my test'</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-c">// fake</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">const</span> <span class="pl-s1">testCases</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">;</span>

<span class="pl-s1">test</span><span class="pl-kos">.</span><span class="pl-en">describe</span><span class="pl-kos">(</span><span class="pl-s">'Quote - Existing Account - Test Quote Prices'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</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">x</span> <span class="pl-k">of</span> <span class="pl-s1">quoteTestCases</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">'my test'</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-c">// fake</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-s1">test</span><span class="pl-kos">.</span><span class="pl-en">describe</span><span class="pl-kos">(</span><span class="pl-s">'Quote - Existing Account - Test Quote Prices'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</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">x</span> <span class="pl-k">of</span> <span class="pl-s1">testCases</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">'my test'</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-c">// fake</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-s1">test</span><span class="pl-kos">.</span><span class="pl-en">describe</span><span class="pl-kos">(</span><span class="pl-s">'Quote - Existing Account - Test Quote Prices'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</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">x</span> <span class="pl-k">of</span> <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">'my test'</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-c">// fake</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></pre></div>
<p dir="auto"><strong>Describe the bug</strong></p>
<p dir="auto">If test case data for parameterized tests are obtained from any variable declared outside the scope of the current scope or are declared inline in the for loop, the tests do not provide the option to be run.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/5461649/208159644-52d6eee1-f73e-4bd4-814e-675f9ebb1568.png"><img src="https://user-images.githubusercontent.com/5461649/208159644-52d6eee1-f73e-4bd4-814e-675f9ebb1568.png" alt="image" style="max-width: 100%;"></a></p>