From ed0dcdabc9ffa447e0577ce620445140fd5d8653 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 18 Apr 2022 17:06:01 -0700 Subject: [PATCH] docs: clarify toBeDisabled behavior (#13616) --- docs/src/api/class-locatorassertions.md | 6 +++- packages/playwright-test/types/test.d.ts | 5 ++- tests/config/experimental.d.ts | 5 ++- .../playwright.expect.true.spec.ts | 33 +++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/docs/src/api/class-locatorassertions.md b/docs/src/api/class-locatorassertions.md index afb259b9b6..9282c34a1b 100644 --- a/docs/src/api/class-locatorassertions.md +++ b/docs/src/api/class-locatorassertions.md @@ -337,7 +337,11 @@ await Expect(locator).ToBeCheckedAsync(); * langs: - alias-java: isDisabled -Ensures the [Locator] points to a disabled element. +Ensures the [Locator] points to a disabled element. Element is disabled if it has "disabled" attribute +or is disabled via ['aria-disabled'](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled). +Note that only native control elements such as HTML `button`, `input`, `select`, `textarea`, `option`, `optgroup` +can be disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored +by the browser. ```js const locator = page.locator('button.submit'); diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts index 14e8812b13..98261cff1c 100644 --- a/packages/playwright-test/types/test.d.ts +++ b/packages/playwright-test/types/test.d.ts @@ -3163,7 +3163,10 @@ interface LocatorAssertions { }): Promise; /** - * Ensures the [Locator] points to a disabled element. + * Ensures the [Locator] points to a disabled element. Element is disabled if it has "disabled" attribute or is disabled + * via ['aria-disabled'](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled). Note + * that only native control elements such as HTML `button`, `input`, `select`, `textarea`, `option`, `optgroup` can be + * disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser. * * ```js * const locator = page.locator('button.submit'); diff --git a/tests/config/experimental.d.ts b/tests/config/experimental.d.ts index 32976f9d6a..1525ad4f11 100644 --- a/tests/config/experimental.d.ts +++ b/tests/config/experimental.d.ts @@ -19368,7 +19368,10 @@ interface LocatorAssertions { }): Promise; /** - * Ensures the [Locator] points to a disabled element. + * Ensures the [Locator] points to a disabled element. Element is disabled if it has "disabled" attribute or is disabled + * via ['aria-disabled'](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled). Note + * that only native control elements such as HTML `button`, `input`, `select`, `textarea`, `option`, `optgroup` can be + * disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser. * * ```js * const locator = page.locator('button.submit'); diff --git a/tests/playwright-test/playwright.expect.true.spec.ts b/tests/playwright-test/playwright.expect.true.spec.ts index 0328e4bf34..c74c2386ca 100644 --- a/tests/playwright-test/playwright.expect.true.spec.ts +++ b/tests/playwright-test/playwright.expect.true.spec.ts @@ -176,6 +176,39 @@ test('should support toBeEditable, toBeEnabled, toBeDisabled, toBeEmpty', async expect(output).toContain('expect(locator).toBeEnabled({ timeout: 500 }'); }); +test('should support toBeDisabled,toBeChecked,toBeHidden w/ value', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.ts': ` + const { test } = pwt; + + test('disabled', async ({ page }) => { + await page.setContent(''); + const locator = page.locator('button'); + await expect(locator).toBeDisabled(); + }); + test('checked', async ({ page }) => { + await page.setContent(''); + const locator = page.locator('input'); + await expect(locator).toBeChecked(); + }); + test('hidden', async ({ page }) => { + await page.setContent(''); + const locator = page.locator('input'); + await expect(locator).toBeHidden(); + }); + test('div disabled', async ({ page }) => { + await page.setContent('
'); + const locator = page.locator('div'); + await expect(locator).not.toBeDisabled(); + }); + `, + }, { workers: 1 }); + expect(result.passed).toBe(4); + expect(result.failed).toBe(0); + expect(result.exitCode).toBe(0); +}); + + test('should support toBeVisible, toBeHidden', async ({ runInlineTest }) => { const result = await runInlineTest({ 'a.test.ts': `