title: TestCafe how to share variables from a RequestHook
body: <p>We want to automate testing for our analytics calls. I am currently evaluation front end test tools, that could be used for this. I found TestCafe Studio to be what we would need to create the tests, but first I need some proof of concept. Thus I try to code a simple test case first. But I struggle with what seems to be the most basic. I want to assert that some parameters in a request have a certain value. So what I did is to create a <code>RequestHook</code> according to the documentation: https://devexpress.github.io/testcafe/documentation/test-api/intercepting-http-requests/creating-a-custom-http-request-hook.html (what they omit is that you need to export your class if you place it in a separate file...)
  I have two problems now:</p>
  
  <ol>
  <li>How can I wait for this request to be executed? The <code>await t</code> is only for the page I am requesting, but the analytics call is then executed later.</li>
  <li>How do I provide the test with some data collected in the hook?</li>
  </ol>
  
  <p>Here is how far I have gotten (I got the URL in the console):</p>
  
  <pre><code>import { RequestHook} from 'testcafe';
  
  export class AnalyticsRequestHook extends RequestHook {
      constructor (requestFilterRules, responseEventConfigureOpts) {
          super(requestFilterRules, responseEventConfigureOpts);
      }
      async onRequest (event) {
          console.log(event.requestOptions.url);
      }
      async onResponse (event) {
      }
  }
  </code></pre>
  
  <p>I then instantiate this class with:</p>
  
  <pre><code>const analyticsRequestHook = new AnalyticsRequestHook(/https:\/\/trackinghost.com\//);
  </code></pre>
  
  <p>In some other examples, they just import <code>t</code> as well and you should have access to it in the methods. But this seems not to work for RequestHooks, as I get the following error as soon as I try to access <code>t</code>:</p>
  
  <blockquote>
    <p>Cannot implicitly resolve the test run in the context of which the
          test controller action should be executed. Use test function's 't'
          argument instead.</p>
  </blockquote>
  
  <p>But in <code>onRequest</code> I can't pass other arguments.</p>
  
  <p>So are my two questions even possible, if yes, please provide an example, as I am really a complete newbie with testcafe.</p>