<h3 dir="auto">System info</h3>
<ul dir="auto">
<li>Playwright Version: [v1.32.1]</li>
<li>Operating System: [Windows 10]</li>
<li>Browser: [ Chromium]</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"> 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"><strong>Config file</strong></p>
<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="sync getText(): Promise&lt;string&gt; {
const context = await chromium.launchPersistentContext('C:\\temp\\playwright-cache', {headless: false, channel: 'chrome' });
const page = context.pages()[0];
await page.goto(&quot;url behind SSO&quot;);
//here user login to the SSO manually for the first time
const text= await page.locator('cssSelector').innerHTML({timeout: 60*1000});
await page.close();
return text
}"><pre class="notranslate"><span class="pl-s1">sync</span> <span class="pl-en">getText</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-v">Promise</span><span class="pl-c1">&lt;</span><span class="pl-s1">string</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
<span class="pl-s1">const</span> context <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">launchPersistentContext</span><span class="pl-kos">(</span><span class="pl-s">'C:\\temp\\playwright-cache'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span><span class="pl-c1">headless</span>: <span class="pl-c1">false</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-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-s1">context</span><span class="pl-kos">.</span><span class="pl-en">pages</span><span class="pl-kos">(</span><span class="pl-kos">)</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">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">"url behind SSO"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">//here user login to the SSO manually for the first time</span>
<span class="pl-k">const</span> <span class="pl-s1">text</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">'cssSelector'</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">innerHTML</span><span class="pl-kos">(</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-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">close</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-s1">text</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Steps</strong></p>
<ol dir="auto">
<li>Playwright opens a browser with persistent context</li>
<li>Playwright navigates to a URL with behind SSO</li>
<li>User enters credentials and logins</li>
<li>Playwright grabs the text and we return it</li>
<li>Function is run for second time</li>
</ol>
<p dir="auto"><strong>Expected</strong><br>
SSO not to be shown as user has already logged in once.</p>
<p dir="auto"><strong>Actual</strong><br>
SSO page is shown every time as session is not saved.</p>
<p dir="auto"><strong>Workaround</strong><br>
If <code class="notranslate">await page.close();</code> is removed, session is correctly saved at the end of the test run and SSO page is no longer shown. However, the browser that was used to get the text required for other tests (that run in an non-persistent browser) remains open through out the test suite running and that is not ideal.</p>
<p dir="auto">It was mentioned in <a href="https://github.com/microsoft/playwright/issues/24007" data-hovercard-type="issue" data-hovercard-url="/microsoft/playwright/issues/24007/hovercard">this issue</a> that page is being closed too early and it is causing the session not to be persisted.<br>
However, adding some explicit timeout to try this theory did not proof useful:<br>
<code class="notranslate">await page.waitForTimeout(30000); </code><br>
it seem like that as long as the page closed via <code class="notranslate">page.close()</code>, it is not saving the session.</p>
<p dir="auto">Note:</p>
<ul dir="auto">
<li>Due to compliance and other technical decisions, this is the only way that I am able to save session instead of using storageState.</li>
<li>I already raised this issue  <a href="https://github.com/microsoft/playwright/issues/24007" data-hovercard-type="issue" data-hovercard-url="/microsoft/playwright/issues/24007/hovercard">this issue</a>, however, it was closed without an answer that works. So I am not sure if I should leave a comment there or create a new issue. Please advice.</li>
</ul>
<p dir="auto">It would be great if Playwright had something similar to CodeceptJS methods:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/9056958/77189043-dbb37580-6ace-11ea-9fe0-7216a9569b00.png"><img src="https://user-images.githubusercontent.com/9056958/77189043-dbb37580-6ace-11ea-9fe0-7216a9569b00.png" alt="image" style="max-width: 100%;"></a><br>
or</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/9056958/77189066-e1a95680-6ace-11ea-9617-6c3a438cc0a3.png"><img src="https://user-images.githubusercontent.com/9056958/77189066-e1a95680-6ace-11ea-9617-6c3a438cc0a3.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">I guess this could be in a form similar to <code class="notranslate">waitForProperty</code>? which waits for an element to exist and waits for a property of key and value</p>
<p dir="auto">e.g. <code class="notranslate">waitForProperty(selector, "innerText", "Foo",{timeout})</code> <code class="notranslate">waitForProperty(selector, "value", "bar",{timeout})</code></p>