diff --git a/packages/playwright-core/src/server/injected/injectedScript.ts b/packages/playwright-core/src/server/injected/injectedScript.ts index 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.ts index 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('