This script is logging in to a site. This is my first jest test. The last line before the test clicks a li in a ul dropdown list. We then navigate to a new page with url https://uat2.onplanapp.com/#/
As a simple test I am trying to check that this is indeed the url of the new page. When I watch in browser, the script does log in and navigate to the correct page.
Getting error shown below.
Code
/**
* @name Onplan Login
* @desc Logs in and test for correct page title
*/
const puppeteer = require('puppeteer');
const assert = require('assert');
let browser;
let page;
beforeAll(async () => {
browser = await puppeteer.launch({
headless: false,
devtools: true
//slowMo: 50
});
const page = await browser.newPage();
await page.goto('https://uat2.onplanapp.com/#/sheet/139');
await page.waitFor(500);//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(100);//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(500);// was 1000
// click dropdown to show list of companies
await page.click('#react-select-2-option-2'); //Test company
await page.waitFor(300);//was 1000
// click list item to select company
await page.click('button[class="btn btn-block mt-3"]');
// now navigate to company page
})
test('url should be correct"', async () => {
expect.assertions(1);
const url = await page.url;
await assert(url === 'https://uat2.onplanapp.com/#/');
});
afterAll(async () => {
//await browser.close()
})
Error Message
onplan_jest@1.0.0 test F:\Projects\onplan_jest jest
FAIL ./login.test.js (6.165 s) × url should be correct" (2 ms)
● url should be correct"
Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.
at mapper (node_modules/jest-jasmine2/build/queueRunner.js:29:45)
● url should be correct"
TypeError: Cannot read property 'url' of undefined
43 |
44 | expect.assertions(1);
> 45 | const url = await page.url;
| ^
46 | await assert(url === 'https://uat2.onplanapp.com/#/');
47 | });
48 |
at Object.<anonymous> (login.test.js:45:28)
● url should be correct"
expect.assertions(1)
Expected one assertion to be called but received zero assertion calls.
42 | test('url should be correct"', async () => {
43 |
> 44 | expect.assertions(1);
| ^
45 | const url = await page.url;
46 | await assert(url === 'https://uat2.onplanapp.com/#/');
47 | });
at Object.<anonymous> (login.test.js:44:12)
Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 6.316 s, estimated 7 s Ran all test suites. 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.
End of Error Message