title: How to return result from Cypress function after set
body: <p>I have the following code:</p>
  <pre><code>function getValues(date)
  {
    let totalValue=-10;
    cy.visit('http://localhost/page1');  
    cy.get(&quot;.total&quot;).then((span)=&gt; 
    {
      console.log(&quot;Values: &quot;+span.text())
      totalValue=span.text()        
    }
    )
    //.then(()=&gt; totalValue);
    return totalValue;
  }
  </code></pre>
  <p>I would like to get the value of the element so I use this:</p>
  <pre><code>it('Testing values',()=&gt;
  {
    var totalValues=getValues(startDate)
    console.log(&quot;Total values: &quot;+ totalValues)
  }
  </code></pre>
  <p>Unfortunately, it never waits for the variable to be set.</p>
  <p>Either I get this <code>-10</code> (when I use the <code>return</code>) or <code>undefined</code> (when I use <code>then</code>) as results and the order is incorrect:</p>
  <blockquote>
  <p>Total values: -10</p>
  <p>Values: 2.5</p>
  </blockquote>
  <p>How could I force the execution to wait until the correct value is set?</p>