playwright-page.js 1018 B

12345678910111213141516171819202122232425262728293031
  1. import { test as base } from "@playwright/test";
  2. import { goto as goToPage, } from "./page/utils";
  3. /**
  4. * Extends the base `page` test figure within Playwright.
  5. * @param page The page to extend.
  6. * @param testInfo The test info.
  7. * @returns The modified playwright page with extended functionality.
  8. */
  9. export async function extendPageFixture(page, testInfo) {
  10. const originalGoto = page.goto.bind(page);
  11. /**
  12. * Adds a global flag on the window that the test suite
  13. * can use to determine when it is safe to execute tests
  14. * on hydrated Stencil components.
  15. */
  16. await page.addInitScript(`
  17. (function() {
  18. window.addEventListener('appload', () => {
  19. window.testAppLoaded = true;
  20. });
  21. })();`);
  22. // Overridden Playwright methods
  23. page.goto = (url, options) => goToPage(page, url, options, testInfo, originalGoto);
  24. return page;
  25. }
  26. export const test = base.extend({
  27. page: async ({ page }, use, testInfo) => {
  28. page = await extendPageFixture(page, testInfo);
  29. await use(page);
  30. },
  31. });