Jest, puppeteer usage timeout

Timeout-Async callback was not invoked within the 5000ms timeout specified

recently working on UI tests, using jest and puppeteer. Mainly to test the login page.

I have been messing around with the online tutorials for a long time, and there is a mistake that I don"t know how to solve.

errors are as follows:

 Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

      63 | });
      64 |
    > 65 | test("login failure", async () => {
         | ^
      66 |   await page.waitForSelector("-sharpusername", {
      67 |         timeout: 5000,
      68 |       });

      at Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:85:20)
      at Object.test (src/tests/login.test.js:65:1)

the code for the test is as follows:

const puppeteer = require("puppeteer");

let browser;
let page;

beforeAll(async () => {
  browser = await puppeteer.launch({
    headless: false,
    slowMo: 200,
  });
  page = await browser.newPage();
});

afterAll(() => {
  browser.close();
});

test("open page", async () => {
  await page.goto("localhost:8000/web/login");
});

test("login failure", async () => {
  await page.waitForSelector("-sharpusername", {
        timeout: 5000,
      });
  await page.type("-sharpusername", "test");
  await page.type("-sharppassword", "1111");
  await page.click("-sharpsubmit");
  await page.waitForSelector(".ant-message-notice",{ timeout: 5000});
});

up to now, I have done a good job in the agreement

. For

protocol errors, I changed page.goto ("http://localhost:8000/web/login") to page.goto) (" localhost:8000/web/login" for Ok) ~

. There has been no progress on the issue of timeout. Currently, I think it is a test of jest that the default is no more than 5s. Because I have now simplified the steps, making it easy to verify the user name and password that will be entered when logging in, thus reducing the test to less than 5s.

 PASS  src/tests/login.test.js (9.914s)
   open page (2080ms)
   login failure (4981ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        10.871s
Ran all test suites.

so, does anyone understand that QAQ, is modifying the configuration of jest? It still needs to be solved, and the configuration of jest does not know where to solve OTZ

.
Jun.11,2021

timeout problem solved ~ after reading this passage, I suddenly became clear ~
four main lifecycle functions:

afterAll (fn,timeout): execute fn, after all tests in the current file are completed. If fn is promise,jest, it waits for timeout milliseconds. Default is 5000
afterEach (fn,timeout): execute fn,timeout after each test execution means the same as above
beforeAll (fn,timeout): it differs from afterAll, in that it executes
beforeEach (fn,timeout) before all tests start: it differs from afterEach, in that it executes

before each test starts.

so I wonder if timeout can be set after every test

then pass ~


first distinguish the concept of timeout. The timeout of a test framework such as
jest refers to the timeout between each case (for example, the timeout of the before operation). The timeout of an at framework such as puppeteer refers to the timeout of a certain dom node in select (for example, if a button cannot be found, timeout)
there is another concept in at that you may have confused, that is, wait time, means that the page waits for a while without doing anything, and you can think of it as sleep,. There should be an api similar to sleep in puppeteer for you to call, and each api of puppeteer may also have a parameter of timeout for you to set separately. I am not familiar with puppeteer. Check the document yourself, at least this function is available in selenium

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2b196-2a7b0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2b196-2a7b0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?