Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(expect): toHaveCSS with custom CSS properties (#12709)
Max Schmittadcd32fc6e6e
diff --git a/packages/playwright-core/src/server/injected/injectedScript.ts b/packages/playwright-core/src/server/injected/injectedScript.tsindex 41fa4bdd80..f88ca5b8d2 100644--- a/packages/playwright-core/src/server/injected/injectedScript.ts+++ b/packages/playwright-core/src/server/injected/injectedScript.ts@@ -999,7 +999,7 @@ export class InjectedScript {} else if (expression === 'to.have.class') {received = element.className;} else if (expression === 'to.have.css') {- received = (window.getComputedStyle(element) as any)[options.expressionArg];+ received = window.getComputedStyle(element).getPropertyValue(options.expressionArg);} else if (expression === 'to.have.id') {received = element.id;} else if (expression === 'to.have.text') {diff --git a/tests/playwright-test/playwright.expect.text.spec.ts b/tests/playwright-test/playwright.expect.text.spec.tsindex 02c942556c..859b651cce 100644--- a/tests/playwright-test/playwright.expect.text.spec.ts+++ b/tests/playwright-test/playwright.expect.text.spec.ts@@ -308,9 +308,15 @@ test('should support toHaveCSS', async ({ runInlineTest }) => {const locator = page.locator('#node');await expect(locator).toHaveCSS('color', 'rgb(255, 0, 0)');});++ test('pass with custom css properties', async ({ page }) => {+ await page.setContent('<div id=node style="--custom-color-property:#FF00FF;">Text content</div>');+ const locator = page.locator('#node');+ await expect(locator).toHaveCSS('--custom-color-property', '#FF00FF');+ });`,}, { workers: 1 });- expect(result.passed).toBe(1);+ expect(result.passed).toBe(2);expect(result.exitCode).toBe(0);});