0

Writing some e2e tests using Jest and Puppeteer. These tests pass locally but they fail on Heroku CI (the beforeAll hook times out after 15 seconds).

I added some console.log statements and figured out that the beforeAll hook is timing out in the waitForSelector line. I'm wondering if there's an issue with navigating to localhost on Heroku?

const port = process.env.PORT || 3001;


beforeAll(async () => {
  // Set a definite size for the page viewport so view is consistent across browsers
  await page.setViewport({
    width: 1366,
    height: 768,
    deviceScaleFactor: 1,
  });
  await page.goto("http://localhost:" + port);
  await page.waitForSelector("div > div > button");
  await page.click("div > div > button");
  await page.waitForSelector("input#username");
  await page.type("input#username", process.env.TEST_USERNAME);
  await page.type("input#password", process.env.TEST_PASSWORD);
  await page.keyboard.press("Enter");
});

describe("Basic authentication e2e tests", () => {
  it("should load the business table and display total number of accounts", async () => {
    await page.waitForSelector(".business-table");
    await page.waitForSelector(".paginator-counter");
    let element = await page.$(".paginator-counter");
    let value = await page.evaluate((el) => el.textContent, element);
    let firstWord = value.split(" ")[0];
    expect(firstWord).toBe("1-25");
  }, 10000);

});
  • 1
    Is CI also using localhost? Not much info here to reproduce. I guess if it's making it to `waitForSelector` that's good--can you print `console.log(await page.content())` to verify that the selector is indeed there and it's the page you expect? – ggorlen Oct 06 '22 at 00:03

0 Answers0