我正在使用 JEST + Puppeteer 在托管的 Web 应用程序上运行功能测试。这是测试代码:const puppeteer = require('puppeteer');const url = 'https://somewebsite.com';const login = (async(page, login, password) =>{ await page.goto(url) await page.waitForSelector('#mat-input-0') await page.type('#mat-input-0', login) await page.type('#mat-input-1', password) await page.click('button')})beforeEach(async () => { browser = await puppeteer.launch({ headless: false }); page = await browser.newPage();});afterEach(async () => { await browser.close();});describe('login to website test', () => { test('non existent user try', async() => { jest.setTimeout(300000); await login(page, 'user@email.com', 'upsiforgoTTThepassword') await page.waitFor(1000) var element = await page.$eval('.mat-simple-snackbar', (element) => { return element.textContent.trim() }) expect(element).toBe('User not Found') })})我遇到的问题是,如果我await browser.close();在测试结束后使用 puppeteer 功能退出浏览器,它会自动失败,并且在终端中出现错误: ● Test suite failed to run Protocol error: Connection closed. Most likely the page has been closed.如果我在测试结束后不关闭浏览器,它会按原样通过。
添加回答
举报
0/150
提交
取消