This is my first jest test with puppeteer. I am trying to log in to a site and test that the title of the first page after log in is correct.
This is being done in headful mode.
I can see that the login is successful. However the test fails and the vsCode terminal shows the error(s) as below. Please advise.
/**
* @name Onplan Login
* @desc Logs in and test for correct page title
*/
const puppeteer = require('puppeteer');
beforeAll(async () => {
const browser = await puppeteer.launch({
headless: false,
devtools: true
});
const page = await browser.newPage();
//await page.setViewport({ width: 4096, height: 1800 })
await page.goto('https://uat2.onplanapp.com/#/sheet/139');
await page.waitFor(1000);//was 500
await page.waitFor('#inputEmail');
await page.type('#inputEmail', 'xxx@yyy');
await page.type('#inputPassword', '1111');
await page.click('button');//Login
await page.waitForNavigation();
await page.waitFor(1000);//was 500
// SELECT COMPANY ON NEXT PAGE
await page.waitFor('#logn-screenv > form > div.row.logn-screenbody.pb-4.pt-3.px-2 > div:nth-child(2) > div > div > div.css-1hwfws3.custom-scrollbar__value-container > div.css-151xaom-placeholder.custom-scrollbar__placeholder');
await page.click('#logn-screenv > form > div.row.logn-screenbody.pb-4.pt-3.px-2 > div:nth-child(2) > div > div > div.css-1hwfws3.custom-scrollbar__value-container > div.css-151xaom-placeholder.custom-scrollbar__placeholder');//Login
// SELECT COMPANY
await page.waitFor(300);// was 1000
// Select dropdown
//select company option
await page.click('#react-select-2-option-2'); //Test company
await page.waitFor(100);//was 1000
await page.click('button[class="btn btn-block mt-3"]');
})
describe('Login', () => {
test('should be titled "Onplan"', async () => {
await page.waitFor(500);//was 1000
expect.assertions(1);
await expect(page.$('title').resolves.toEqual('Onplan'));
});
}, 10000)
afterAll(async () => {
await browser.close()
})
//////////////////// Error Message //////////////////// PS F:\Projects\onplan_jest> npm test
PS F:\Projects\onplan_jest> npm test
onplan_jest@1.0.0 test F:\Projects\onplan_jest jest
FAIL ./login.test.js ● Test suite failed to run
Protocol error: Connection closed. Most likely the page has been closed.
at Object.assert (node_modules/puppeteer/lib/helper.js:28:15)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 6.811 s
Ran all test suites.
(node:501740) UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.callFunctionOn): Target closed.
at F:\Projects\onplan_jest\node_modules\puppeteer\lib\Connection.js:148:63
at new Promise ()
at CDPSession.send (F:\Projects\onplan_jest\node_modules\puppeteer\lib\Connection.js:147:16)
at ExecutionContext._evaluateInternal (F:\Projects\onplan_jest\node_modules\puppeteer\lib\ExecutionContext.js:77:50)
at ExecutionContext.evaluateHandle (F:\Projects\onplan_jest\node_modules\puppeteer\lib\ExecutionContext.js:35:21)
at ExecutionContext. (F:\Projects\onplan_jest\node_modules\puppeteer\lib\helper.js:83:27)
at ElementHandle.evaluateHandle (F:\Projects\onplan_jest\node_modules\puppeteer\lib\JSHandle.js:43:46)
at ElementHandle. (F:\Projects\onplan_jest\node_modules\puppeteer\lib\helper.js:83:27)
at ElementHandle.$ (F:\Projects\onplan_jest\node_modules\puppeteer\lib\JSHandle.js:347:35)
at ElementHandle. (F:\Projects\onplan_jest\node_modules\puppeteer\lib\helper.js:83:27)
-- ASYNC --
at ExecutionContext. (F:\Projects\onplan_jest\node_modules\puppeteer\lib\helper.js:82:19)
at ElementHandle.evaluateHandle (F:\Projects\onplan_jest\node_modules\puppeteer\lib\JSHandle.js:43:46)
at ElementHandle. (F:\Projects\onplan_jest\node_modules\puppeteer\lib\helper.js:83:27)
at ElementHandle.$ (F:\Projects\onplan_jest\node_modules\puppeteer\lib\JSHandle.js:347:35)
at ElementHandle. (F:\Projects\onplan_jest\node_modules\puppeteer\lib\helper.js:83:27)
at DOMWorld.$ (F:\Projects\onplan_jest\node_modules\puppeteer\lib\DOMWorld.js:96:38)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
-- ASYNC --
at Frame. (F:\Projects\onplan_jest\node_modules\puppeteer\lib\helper.js:82:19)
at Page.$ (F:\Projects\onplan_jest\node_modules\puppeteer\lib\Page.js:219:33)
at Page.$ (F:\Projects\onplan_jest\node_modules\puppeteer\lib\helper.js:83:27)
at Object. (F:\Projects\onplan_jest\login.test.js:48:27)
(node:501740) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing
inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:501740) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ERROR: The process "497896" not found.
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with --detectOpenHandles
to troubleshoot this issue.
at Object. (F:\Projects\onplan_jest\login.test.js:48:27)
(node:501740) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing
inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:501740) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ERROR: The process "497896" not found.
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with --detectOpenHandles
to troubleshoot this issue.
(node:501740) UnhandledPromiseRejectionWarning: TypeError: Caught error after test environment was torn down
Assignment to constant variable.
(node:501740) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing
inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)