title: Puppeteer gives different results for same test
body: <p>I have a test using jest and puppeteer that checks if a conditional item in a React / material-ui drop down exists or not.</p>
  <p>When I run it {headless:true}, it fails every time.
  When I run it with {headless:false}, and I initiate the command from the command prompt via <code>jest --watch</code> the test fails.
  When I then just 'save' the test file (ie: the test watcher notices and runs it) ... the test passes.</p>
  <p>The behavior in an actual browser is correct and works fine.</p>
  <p>Ideas?</p>
  <p>Test code is:</p>
  <pre><code>const puppeteer = require(&quot;puppeteer&quot;);
  const CONSTANTS = require('../../../constants/Config')
  const MOCKS = require('../../../test/mocks')
  const TEST_CONSTANTS = require('../../../test/testingConstants');
  
  var browser
  var page
  const apiCall = CONSTANTS.NODE_ENDPOINT + &quot;/api&quot; + '/1234'
  
  
  describe('Check that reevaluate review section', () =&gt; {
      beforeAll(async () =&gt; {
          browser = await puppeteer.launch({
              headless: false   
          })
      })
      beforeEach(async () =&gt; {
          page = await browser.newPage()
  
          // Intercept API response and pass mock data for Puppeteer
          await page.setRequestInterception(true);
          page.on('request', request =&gt; {
              if (request.url() === apiCall) {
                  request.respond({
                      content: 'application/json',
                      headers: { &quot;Access-Control-Allow-Origin&quot;: &quot;*&quot; },
                      body: JSON.stringify({
                          &quot;success&quot;: true,
                          &quot;data&quot;: MOCKS.requestDataObj_old,
                          &quot;message&quot;: &quot;Request 60f78b836a34316bd3ef12ea found&quot;
                      })
                  });
              } else {
                  request.continue();
              }
          });
          await page.goto(TEST_CONSTANTS.REQUEST_REVIEW_URL + '1234')
      });
  
      test(&quot;reevaluate options include 'Sunset'&quot;, async () =&gt; {
          await page.waitForSelector('#Request_Section_Reevaluate', { visible: true })
          await page.click('#Request_Section_Reevaluate_ReviewStatus')
          let sunsetElement = await page.waitForSelector('#Request_Section_Reevaluate_ReviewStatus_Optons_MenuItem_Sunset', { visible: true, timeout: 1500 })
          expect(sunsetElement).toBeTruthy()
          page.close()
      })
  });
  </code></pre>
  <p>Component is a rather large react component down in a rather large react tree... seeing it on the screen would require scrolling down to it and certain aspects only appear after the api call (mocked, above) is called.  The API call is short (and local, so it should be roughly the same time every time) an the timeouts are long  - so I don't think that is the issue.</p>
  <p>The error looks like this:</p>
  <pre><code> FAIL  src/components/common/RequestSectionReevaluate/RequestSectionReevaluate.ui.test.js (6.668 s)
    Check that reevaluate review section
      × reevaluate options include 'Sunset' (4779 ms)
  
    ● Check that reevaluate review section › reevaluate options include 'Sunset'
  
      TimeoutError: waiting for selector `#Request_Section_Reevaluate_ReviewStatus_Optons_MenuItem_Sunset` failed: timeout 1500ms exceeded
  
        41 |              await page.waitForSelector('#Request_Section_Reevaluate', { visible: true })
        42 |              await page.click('#Request_Section_Reevaluate_ReviewStatus')
      &gt; 43 |              let sunsetElement = await page.waitForSelector('#Request_Section_Reevaluate_ReviewStatus_Optons_MenuItem_Sunset', { visible: true, timeout: 1500 })
           |                                             ^
        44 |              expect(sunsetElement).toBeTruthy()
        45 |              page.close()
        46 |      })
  
        at new WaitTask (node_modules/puppeteer/src/common/DOMWorld.ts:813:28)
        at DOMWorld.waitForSelectorInPage (node_modules/puppeteer/src/common/DOMWorld.ts:656:22)
        at Object.internalHandler.waitFor (node_modules/puppeteer/src/common/QueryHandler.ts:78:19)
        at DOMWorld.waitForSelector (node_modules/puppeteer/src/common/DOMWorld.ts:511:25)
        at Frame.waitForSelector (node_modules/puppeteer/src/common/FrameManager.ts:1290:47)
        at Page.waitForSelector (node_modules/puppeteer/src/common/Page.ts:3222:29)
        at _callee3$ (src/components/common/RequestSectionReevaluate/RequestSectionReevaluate.ui.test.js:43:34)
        at tryCatch (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:86:17)
        at Generator._invoke (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:66:24)
        at Generator.next (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:117:21)
        at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
        at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
  
  A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks.
  Test Suites: 1 failed, 1 total
  Tests:       1 failed, 1 total
  Snapshots:   0 total
  Time:        8.474 s
  </code></pre>