title: How to make the same alias accessible in all tests in Cypress
body: <p>I'm trying to make <em>the same</em> alias, that is accessible in severel different tests. And the documentation doesn't explain how to achieve this.</p>
  <p>I'm trying to do this:</p>
  <pre><code>Before
   - Generate datetime-stamp as a string: $dateTime
  
  Test 1
   - Test that no order exists where $dateTime is the first name for the buyer.
  
  Test 2
   - Make an order, setting $dateTime as the first name
  
  Test 3
   - Test that there is an order where $dateTime is the first name
  </code></pre>
  <p>How do I, in the <code>before()</code>-function make a variable that is accessible in all my tests?
  ... And please note, that since the <code>$dateTime</code> should be the same in all tests, then it should be generated once and not in <code>beforeEach()</code>.</p>
  <h2>Update1</h2>
  <p>I can see that it is actually described in the &quot;Do not do this&quot;-section <a href="https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Aliases" rel="nofollow noreferrer">here</a>. But I don't see how this is 'making my code do backflips'.</p>
  <hr />
  <h2>Update2</h2>
  <p>And are there an advantage of using fixtures, if I do this anyway:</p>
  <pre><code>context( 'Buy product' , function () {
      let dateTime = new Date();
      let dateTimeStr = dateTime.toLocaleDateString('en-GB', { year: 'numeric', day: 'numeric', month: 'short', hour: 'numeric', minute: 'numeric', second: 'numeric' });
      dateTimeStr = dateTimeStr.replaceAll( ', ', '--' );
      dateTimeStr = dateTimeStr.replaceAll( ' ', '-' );
      dateTimeStr = dateTimeStr.replaceAll( ':', '' );
  
  
      beforeEach( () =&gt; {
          cy.wrap( dateTimeStr ).as('dateTimeStr');
      });
  
  
      it( 'Order with DateTime DOES NOT exists', () =&gt; {
          cy.visit( 'https://example.org/dashboard/orders' );
  
          cy.get( &quot;@dateTimeStr&quot; )
          .then( (dateTimeStr) =&gt; {
              cy.contains( dateTimeStr ).should('not.exist');
          });
      });
  
  
      it( 'Buy product', function() {
  
          cy.visit( 'https://example.org/product/test' );
          ...
          cy.get( '#first_name' ).type( this.dateTimeStr );
          ...
          cy.get('#submit_order').click();
      });
  
  
      it( 'Order with DateTime exists', () =&gt; {
          cy.visit( 'https://example.org/dashboard/orders' );
  
          cy.get( &quot;@dateTimeStr&quot; )
          .then( (dateTimeStr) =&gt; {
              cy.contains( dateTimeStr ).should('exist');
          });
      });
  
  
  });
  </code></pre>
  <p>This code works. But is explicitly mentioned in the documention, that I shouldn't do this. However... The documention doesn't really explain why. Flakyness? Anti-pattern? I don't know. It seems pretty smart to me.</p>