title: Cypress - set global variable from function
body: <p>I have the following flow:</p>
  
  <p>1) On one page I get the value of a field:</p>
  
  <pre><code> var myID;
   cy.get('#MYID').
          then(($txt) =&gt; {
              myID=  $txt.text();
          })
         .should('not.equal', null); 
  </code></pre>
  
  <p>2) I then navigate to a new page and try to check if this new page contains this id:</p>
  
  <pre><code>cy.get('#myTable').find('td').contains(myID);
  </code></pre>
  
  <p>It says that myID is not defined. I know the first function is async and reading the documentation it says I can use an alias. The problem with the alias is it needs to be in the beforeEach() function which not to go into a long story I cannto use in this test case. I tried using async/await but it did not seem to work for me as it was still undefined. </p>