title: Cypress.io how to get length of a array in a before hook, and reuse it later?
body: <ol>
  <li>My task is to enter the page, get the array length (of the <strong>&quot;a&quot;</strong> tags)
  and store it so I can use in in the next step. I need it once, so I do this firstly in before hook.</li>
  <li>Forward, I need to get the <strong>&quot;a&quot;</strong> tags and check if they have a <strong>&quot;title&quot;</strong> attribute. This
  case will be looped so many times, as many <strong>&quot;a&quot;</strong> tags are places on the
  web-page. <strong>Thast why I need the array length.</strong></li>
  </ol>
  <p>This is my code, according to the <a href="https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Aliases" rel="nofollow noreferrer">docs</a> this isnt a good practice, docs call this &quot;code doing backflips&quot; but it should work:</p>
  <pre><code>    let sizeVar;
  
  before(() =&gt; {
      cy.visit(&quot;https://web-page&quot;);
      cy.get(&quot;a&quot;).not(&quot;[href='']&quot;).not(&quot;[href='#']&quot;).its(&quot;length&quot;).then((size) =&gt; {
          sizeVar = Cypress.$(size);
          return sizeVar;
      });
  })
  
  for (let i = 0; i &lt; sizeVar; i++) {
      it(`tag &lt;a&gt; index ${i}`, () =&gt; {
          cy.get(&quot;a&quot;).not(&quot;[href='']&quot;).not(&quot;[href='#']&quot;).eq(i).should(&quot;have.attr&quot;, &quot;title&quot;);
      })
  }
  </code></pre>
  <p>Unfortunately, it doesnt :( after runing above test in Cypress I have <strong>&quot;No tests found in your file. We could not detect any tests in the above file. Write some tests and re-run.&quot;</strong> What the hell?! The funny fact is that when I will change in the loop the sizeVar for some static number, for example 100, it will work and move smoothly.</p>
  <pre><code>for (let i = 0; i &lt; 100; i++)
  </code></pre>
  <p>But I dont need the static number, I need it done in the right way... According to the <a href="https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Aliases" rel="nofollow noreferrer">docs</a> the best way is to use <strong>aliases</strong>. So I did, this is the code:</p>
  <pre><code>before(() =&gt; {
      cy.visit(&quot;https://web-page&quot;);
      cy.get(&quot;a&quot;).not(&quot;[href='']&quot;).not(&quot;[href='#']&quot;).its(&quot;length&quot;).as(&quot;size&quot;);
  })
  
  for (let i = 0; i &lt; this.size; i++) {
      it(`tag &lt;a&gt; index ${i}`, () =&gt; {
          cy.get(&quot;a&quot;).not(&quot;[href='']&quot;).not(&quot;[href='#']&quot;).eq(i).should(&quot;have.attr&quot;, &quot;title&quot;);
      })
  }
  </code></pre>
  <p>And again I doesnt work, this time I get <strong>&quot;Cannot read property 'size' of undefined&quot;</strong>. Where am I doing mistake? Please help.</p>
  <p>=======================UPDATE===============================</p>
  <p>I was thinking about to use pure JS but this not work either... I dont see any wrong logic in my code... But Cypress dont want to pass this variable :(</p>
  <pre><code>describe(&quot;test&quot;, () =&gt; {
  
  let links = document.querySelectorAll(&quot;a&quot;);
  let linksLength = links.length;
  
  before(() =&gt; {
      cy.visit(&quot;https://web-page&quot;);
  })
  
  for (let i = 0; i &lt; linksLength; i++) {
      it(`tag &lt;a&gt; index ${i}`, () =&gt; {
          cy.get(&quot;a&quot;).not(&quot;[href='']&quot;).not(&quot;[href='#']&quot;).eq(i).should(&quot;have.attr&quot;, &quot;title&quot;);
      })
  }
  })
  </code></pre>