<h3 dir="auto">System info</h3>
<ul dir="auto">
<li>Playwright Version: [1.31.2]</li>
<li>Operating System: [Windows 11.]</li>
<li>Browser: [NA]</li>
<li>Other info: API testing Using Playwright</li>
</ul>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="test(&quot;GET: Fetch Document Type Groups&quot;, async({request, baseURL})=&gt;{

    const response = await request.get(`${baseURL}/document-capture/document-type-groups`);
    expect(response.status()).toBe(200);
    const responsebody = await response.json();
    const employeeDocuments = responsebody.data[1].id;
    console.log(employeeDocuments);
    **request.storageState.employeeDocuments = employeeDocuments;**
})
test(&quot;GET: Fetch Document Types for a DocumentTypeGroup&quot;, async({request,baseURL})=&gt;{
    
    
    const response = await request.get(`${baseURL}/document-capture/document-types`,{
        params:{
            **'documentTypeGroupId': request.storageState.employeeDocuments** 
        }
    });
    expect(response.status()).toBe(200);
    const responsebody = await response.json();
   const offerLetterDocTypeID = responsebody.data[2].id;
   request.storageState.offerLetterDocTypeID =offerLetterDocTypeID;
   const newHireCheckListDocTypeID = responsebody.data[1].id;
   request.storageState.newHireCheckListDocTypeID  = newHireCheckListDocTypeID;
})
"><pre class="notranslate"><span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">"GET: Fetch Document Type Groups"</span><span class="pl-kos">,</span> <span class="pl-k">async</span><span class="pl-kos">(</span><span class="pl-kos">{</span>request<span class="pl-kos">,</span> baseURL<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">response</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">request</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">`<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">baseURL</span><span class="pl-kos">}</span></span>/document-capture/document-type-groups`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">expect</span><span class="pl-kos">(</span><span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-en">status</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">toBe</span><span class="pl-kos">(</span><span class="pl-c1">200</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">const</span> <span class="pl-s1">responsebody</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-en">json</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">employeeDocuments</span> <span class="pl-c1">=</span> <span class="pl-s1">responsebody</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-c1">id</span><span class="pl-kos">;</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">employeeDocuments</span><span class="pl-kos">)</span><span class="pl-kos">;</span><span class="pl-s1"></span>
    <span class="pl-c1">**</span><span class="pl-s1">request</span><span class="pl-kos">.</span><span class="pl-c1">storageState</span><span class="pl-kos">.</span><span class="pl-c1">employeeDocuments</span> <span class="pl-c1">=</span> <span class="pl-s1">employeeDocuments</span><span class="pl-kos">;</span><span class="pl-s1"></span><span class="pl-c1">**</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">"GET: Fetch Document Types for a DocumentTypeGroup"</span><span class="pl-kos">,</span> <span class="pl-k">async</span><span class="pl-kos">(</span><span class="pl-kos">{</span>request<span class="pl-kos">,</span>baseURL<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">response</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">request</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">`<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">baseURL</span><span class="pl-kos">}</span></span>/document-capture/document-types`</span><span class="pl-kos">,</span><span class="pl-kos">{</span>
        <span class="pl-c1">params</span>:<span class="pl-kos">{</span>
            <span class="pl-c1">*</span><span class="pl-c1">*</span><span class="pl-s">'documentTypeGroupId'</span>: <span class="pl-c1">request</span><span class="pl-kos">.</span><span class="pl-c1">storageState</span><span class="pl-kos">.</span><span class="pl-c1">employeeDocuments</span><span class="pl-c1">*</span><span class="pl-c1">*</span> 
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">expect</span><span class="pl-kos">(</span><span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-en">status</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">toBe</span><span class="pl-kos">(</span><span class="pl-c1">200</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">const</span> <span class="pl-s1">responsebody</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-en">json</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">offerLetterDocTypeID</span> <span class="pl-c1">=</span> <span class="pl-s1">responsebody</span><span class="pl-kos">.</span><span class="pl-c1">data</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-c1">id</span><span class="pl-kos">;</span>
   <span class="pl-s1">request</span><span class="pl-kos">.</span><span class="pl-c1">storageState</span><span class="pl-kos">.</span><span class="pl-c1">offerLetterDocTypeID</span> <span class="pl-c1">=</span><span class="pl-s1">offerLetterDocTypeID</span><span class="pl-kos">;</span>
   <span class="pl-k">const</span> <span class="pl-s1">newHireCheckListDocTypeID</span> <span class="pl-c1">=</span> <span class="pl-s1">responsebody</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-c1">id</span><span class="pl-kos">;</span>
   <span class="pl-s1">request</span><span class="pl-kos">.</span><span class="pl-c1">storageState</span><span class="pl-kos">.</span><span class="pl-c1">newHireCheckListDocTypeID</span>  <span class="pl-c1">=</span> <span class="pl-s1">newHireCheckListDocTypeID</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto"><strong>Expected</strong><br>
IT should fetch the value from the previous request that is getting stored in the first call</p>
<p dir="auto"><strong>Actual</strong><br>
I was trying to chain this two request by fetching a data from the response and storing in the storagestate (request.storageState.employeeDocuments = employeeDocuments;) , but when i am passing this in the query params of the second request, it is gettng passed as undefined</p>
<h3 dir="auto">Feature request</h3>
<p dir="auto">The purpose is testing of complete applications that have concepts like branch offices or clinics.  More explained below.</p>
<p dir="auto">The solution would be instead of from a directory listing to get tests from a JavaScript generator function <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators</a> .  One possible way to configure could be if <code class="notranslate">project.config.testDir</code> is a <code class="notranslate">function</code> instead of a <code class="notranslate">string</code>, but it could have its own name too.  The entry point to start implementing apparently would be <code class="notranslate">test/runner.ts</code> but it would affect <code class="notranslate">test/loader.ts</code>.  The functionality should be optional, only if such a function is provided.  If used, it would imply less parallelism, limiting to one worker per project.</p>
<p dir="auto">There are three items of functionalitiy.  Currently we use very hacky workarounds.  To understand the need:</p>
<p dir="auto">A branch office or clinic needs to be set up.  With proper authentication and verification, involving email, OAuth, etc., a staff memeber filling out information about themselves, etc. that process as <strong>a test case can take a minute per user</strong> (also for the clinic itself).  Outside IT systems are involved for the authentication and verification, which take any number of seconds to process, sometimes half a minute.  Not a problem, but it takes a while.</p>
<p dir="auto">Those staff members need to exist and be used in further tests.  Not just one, but different roles, for example a doctor versus a technician, but also with different access rights, admin versus regular user.  Maybe a handful or a dozen users are needed, so that <strong>further tests then can determine</strong> that they cannot violate role specific limitations.  E.g. a non-admin user must not be able to change anyone else's records, or a tech may not be allowed to sign a diagnosis like a doctor.</p>
<p dir="auto">Therefore, <strong>executing tests in order is essential</strong>:  A clinic must be created, professional users must be created, only then patients can be seen.</p>
<p dir="auto">The creation of a clinic and of professional users itself are distinct test cases.  They are part of the system and as such deserved to be implemented as test cases.  It makes little sense to duplicate that ability some other way.  That reinforces the idea that executing tests in order is essential.</p>
<p dir="auto">As a side note, it would be nice after creating a set of users, then to run some code that isn't test code proper, but that sets up "from now on use the users that have been created".  This does matter for the idea of execution in time:  If <strong>the test running mechanism comes back to the generator function after each test</strong>, that allows the generator function to have additional code in it, that "knows" after all users have been generated, to set something up for the following tests.  That step of setting up wouldn't work if the test running mechanism ahead of time asks for all tests to run.  (Workaround for this one requirement: Make and insert in order a fake test that does those intermediate setup steps.)</p>
<p dir="auto">The next topic:  If you need ten users, maybe that would be ten times the same test case "register-a-new-user.test.ts".  The generator function could ten times give the same script to run.  That works better if the test running mechanism comes back with <strong>next()</strong> after each test and <strong>the generator function gives it the same test file name to run again</strong> next.  Each test run would be somewhat different with random or seed data.</p>
<p dir="auto">There is more about randomization, but to keep it short, we can describe:  Running the same test case any number, three times, twenty time, a hundred times, is very valuable to what we have been doing.  Specifically there is a lengthy form, that takes half a minute or a minute to fill out, in part because of API calls to the server, not useless waiting, not lack of skill in test writing, just a lengthy form.  Imagine patient intake, health history, or imagine a complete tax form (which are longer for people with family or a business).  The point is:  A hundred or even ten or three of those, do not reasonably fit into a single test.  And, because of the many possible combinations of data (age, history, symptoms, etc.) randomization is a significant feature to actually achieve quality.</p>
<p dir="auto">Therefore, the abilitiy to run the same test file multiple times, any number of repetions as seen fit that time (for example quick acceptance versus a broader sweep) is important.  (Difficult workaround:  Symlinks.  Not how it should be.  Parallelism, cleanup, naming, etc..)</p>
<p dir="auto">It is important to do this within a test run, in order to have reporting.  We have so far done some of this with scripting outside loops, invoking Playwright for each repetition, but that means there isn't a singular final report.</p>
<p dir="auto">Notably, a generator function can be invoked multiple times, also in parallel, e.g. if testing Chromium, Firefox, WebKit.</p>
<p dir="auto">Related could be <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="917597725" data-permission-text="Title is private" data-url="https://github.com/microsoft/playwright/issues/7028" data-hovercard-type="issue" data-hovercard-url="/microsoft/playwright/issues/7028/hovercard" href="https://github.com/microsoft/playwright/issues/7028">#7028</a> and maybe <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="918006563" data-permission-text="Title is private" data-url="https://github.com/microsoft/playwright/issues/7050" data-hovercard-type="issue" data-hovercard-url="/microsoft/playwright/issues/7050/hovercard" href="https://github.com/microsoft/playwright/issues/7050">#7050</a> .</p>