joelgriffith / navalia

A bullet-proof, fast, and reliable headless browser API
https://joelgriffith.github.io/navalia/
GNU General Public License v3.0
961 stars 32 forks source link

Navalia closes chrome after page load #76

Closed vicdup closed 6 years ago

vicdup commented 6 years ago

Hi there,

I have started to implement Navalia, it works great on production but fails when trying on localhost.

Here is my test case:

const { Chrome } = require('navalia');
const pageUrl = 'http://localhost:3000';

describe('Homepage', () => {
  let chrome = {};

  // Setup a clean instance for each test
  beforeEach(() => {
    chrome = new Chrome({
      timeout: 100000,
      flags: { headless: false }
    });
  });

  // Tear down for each test
  afterEach(() => {
    return chrome.done();
  });

  it('should load', () => {
    return chrome.goto(pageUrl)
      .then(() => chrome.exists('[data-test="username"]'))
      .then((exists) => expect(exists).toEqual(true));
  });
});

When I use my production URL instead of localhost one it works fine. But with localhost I can see chrome opening, the page loads and the close before testing. Here are the logs

  navalia:chrome :then() > Executing 1 actions +0ms
  navalia:chrome :getChromeCDP() > starting chrome +2ms
  navalia:chrome :getChromeCDP() > chrome launched on port 57985 +1s
  navalia:chrome :goto() > going to http://localhost:3000 +0ms
  navalia:chrome :goto() > waiting for pageload on http://localhost:3000 +2s
  navalia:chrome :done() > finished +2s
  navalia:chrome :done() > closing chrome +0ms

Not sure how to debug that?

Thanks,

vicdup commented 6 years ago

I finally got it, it was due to jasmine.DEFAULT_TIMEOUT_INTERVAL not being large enough so I increased it adding jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; to my code.