mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
chore(playwright): mode and direction are now set when using setContent (#25435)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { Page } from '@playwright/test';
|
||||
import type { Page, TestInfo } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* Overwrites the default Playwright page.setContent method.
|
||||
@@ -8,8 +8,9 @@ import type { Page } from '@playwright/test';
|
||||
*
|
||||
* @param page The Playwright page object.
|
||||
* @param html The HTML content to set on the page.
|
||||
* @param testInfo The TestInfo associated with the current test run.
|
||||
*/
|
||||
export const setContent = async (page: Page, html: string) => {
|
||||
export const setContent = async (page: Page, html: string, testInfo: TestInfo) => {
|
||||
if (page.isClosed()) {
|
||||
throw new Error('setContent unavailable: page is already closed');
|
||||
}
|
||||
@@ -18,7 +19,7 @@ export const setContent = async (page: Page, html: string) => {
|
||||
|
||||
const output = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html dir="${testInfo.project.metadata.rtl ? 'rtl' : 'ltr'}">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
|
||||
@@ -26,7 +27,13 @@ export const setContent = async (page: Page, html: string) => {
|
||||
<link href="${baseUrl}/scripts/testing/styles.css" rel="stylesheet" />
|
||||
<script src="${baseUrl}/scripts/testing/scripts.js"></script>
|
||||
<script type="module" src="${baseUrl}/dist/ionic/ionic.esm.js"></script>
|
||||
|
||||
<script>
|
||||
window.Ionic = {
|
||||
config: {
|
||||
mode: '${testInfo.project.metadata.mode}'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
${html}
|
||||
|
||||
@@ -43,7 +43,7 @@ export async function extendPageFixture(page: E2EPage, testInfo: TestInfo) {
|
||||
|
||||
// Overridden Playwright methods
|
||||
page.goto = (url: string, options) => goToPage(page, url, options, testInfo, originalGoto);
|
||||
page.setContent = (html: string) => setContent(page, html);
|
||||
page.setContent = (html: string) => setContent(page, html, testInfo);
|
||||
page.locator = (selector: string, options?: LocatorOptions) => locator(page, originalLocator, selector, options);
|
||||
|
||||
// Custom Ionic methods
|
||||
|
||||
Reference in New Issue
Block a user