title: Cypress.io: Reading and storing value of form input into a JS variable (or constant)
body: <p>I have an HTML form (really simple one, no tricky parts like Ajax, ...) on a simple page. I try to read default value of any input (type="text", again no tricks) and store it in constant for later use (assert).</p>
  
  <p>HTML looks like:</p>
  
  <pre><code>&lt;form method="post" ...&gt;
    &lt;input type="text" id="xyz" name="xyz" value="123"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Cypress test, that DOESN'T work, looks like:</p>
  
  <pre><code>describe('General tests', function(){
  
    context('General', function() {
  
      it('can read the input and store in const', function () {
  
          cy.visit('http://localhost/settings')
          const xyz = Cypress.$('#xyz').val()
          cy.log(xyz)
  
      })
  
    })
  })
  </code></pre>
  
  <p>This doesn't work. BUT after several hours of playing (by accident this worked for me in more complex test suite = file). What I realized is, that this construct works as expected in case previous test ( = it() ) visits the same URL as the last visited URL. Than it works like a miracle.</p>
  
  <p>Cypress test, that WORKS, looks like:</p>
  
  <pre><code>describe('General tests', function(){
  
    context('General', function() {
  
      it('makes magic and allows the next test to work', function () {
  
          cy.visit('http://localhost/settings')
  
      })
  
      it('can read the input and store in const', function () {
  
          cy.visit('http://localhost/settings')
          const xyz = Cypress.$('#xyz').val()
          cy.log(xyz)
  
      })
  
    })
  })
  </code></pre>
  
  <p>I thought that tests should be independent, but it looks like they are not.</p>
  
  <p>I tried other ways how to get the value of input info variable and the closest what I needed was using closure ".then()", but it can be used for just a single input, not for more complex forms.</p>
  
  <p>Simple asserting like "cy.get('#id_of_input').should('eq', ...)" works fine, but it doesn't allow me to work with default (and by test overridden) value of inputs.</p>
  
  <p>So my questions:</p>
  
  <p>1) Is it OK to use included jQuery in this way to get and store value of input into constant? If now what is the other way for cases when I need to do this for like 5 various input fields in the form (for a signel input closure will be just fine)
  2) Is it OK that tests influence each other?</p>
  
  <p>Thanks everyone for any help.</p>