(options: APIOptions = {})
| 446 | * @internal |
| 447 | */ |
| 448 | export async function testInBrowser(options: APIOptions = {}): Promise<void> { |
| 449 | const config = options.config ?? defaultConfig; |
| 450 | if (config.verbose) { |
| 451 | info.lowLevel(`Xvfb: ${config.useXVFB}`); |
| 452 | } |
| 453 | |
| 454 | const testPlanner = options.testPlanner ?? defaultTestPlanner; |
| 455 | let interactionManager: Nullable<E2EInteractionManager> = null; |
| 456 | let xvfb: Nullable<XvfbType> = null; |
| 457 | let browser: Nullable<Browser> = null; |
| 458 | let page: Nullable<Page> = null; |
| 459 | let maybeError: Nullable<Error> = null; |
| 460 | try { |
| 461 | xvfb = Xvfb.startIfEnabled(); |
| 462 | browser = await APIUtils.getBrowser(); |
| 463 | const pages = await browser.pages(); |
| 464 | page = pages.length > 0 ? pages[0] : await browser.newPage(); |
| 465 | // create and configure web page interaction manager |
| 466 | interactionManager = new E2EInteractionManager(page, browser); |
| 467 | if (options.evalInBrowserAfterInitLoad) { |
| 468 | interactionManager.setEvalFuncAfterInitLoad( |
| 469 | options.evalInBrowserAfterInitLoad, |
| 470 | ); |
| 471 | } |
| 472 | const visitPlan = testPlanner.getVisitPlan(); |
| 473 | // setup page configuration |
| 474 | config.setDevice(visitPlan.device); |
| 475 | await initBrowserInfoInConfig(browser); |
| 476 | browserInfo.monitorWebConsole(page); |
| 477 | await setupPage(page, options); |
| 478 | // interact with the web page and take heap snapshots |
| 479 | await interactionManager.visitAndGetSnapshots(options); |
| 480 | } catch (ex) { |
| 481 | maybeError = utils.getError(ex); |
| 482 | utils.checkUninstalledLibrary(maybeError); |
| 483 | } finally { |
| 484 | if (browser && page) { |
| 485 | await utils.closePuppeteer(browser, [page]); |
| 486 | } |
| 487 | if (interactionManager) { |
| 488 | interactionManager.clearCDPSession(); |
| 489 | } |
| 490 | if (xvfb) { |
| 491 | xvfb.stop((err: Optional<Error>) => { |
| 492 | if (err) { |
| 493 | utils.haltOrThrow(err); |
| 494 | } |
| 495 | }); |
| 496 | } |
| 497 | if (maybeError != null) { |
| 498 | utils.haltOrThrow(maybeError); |
| 499 | } |
| 500 | } |
| 501 | } |
no test coverage detected
searching dependent graphs…