此脚本正在登录站点。这是我的第一个笑话测试。测试前的最后一行单击 ul 下拉列表中的 li。然后我们导航到带有 url https://uat2.onplanapp.com/#/的新页面
作为一个简单的测试,我试图检查这确实是新页面的 url。当我在浏览器中观看时,脚本会登录并导航到正确的页面。
得到如下所示的错误。
代码
/**
* @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()
})
错误信息
onplan_jest@1.0.0 测试 F:\Projects\onplan_jest jest
FAIL ./login.test.js (6.165 s) × url 应该是正确的" (2 ms)
● url 应该是正确的”
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 应该是正确的”
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 应该是正确的”
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)
测试套件:1 个失败,总共 1 个测试:1 个失败,总共 1 个快照:总共 0 个时间:6.316 秒,估计 7 秒运行所有测试套件。测试运行完成后一秒钟,Jest 没有退出。
这通常意味着在您的测试中没有停止异步操作。考虑运行 Jest--detectOpenHandles
来解决此问题。
错误信息结束