From d950f5b6ee3fee4b825831983d5af5b197bda769 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Thu, 19 Jan 2023 15:04:09 -0800 Subject: [PATCH] chore: remove toIntersectViewport for the next release (#20232) Mostly reverts #19901. --- docs/src/api/class-locatorassertions.md | 16 --------- docs/src/test-assertions-js.md | 1 - packages/playwright-core/src/server/frames.ts | 4 +-- .../src/server/injected/injectedScript.ts | 16 ++------- packages/playwright-test/src/expect.ts | 2 -- .../playwright-test/src/matchers/matchers.ts | 10 ------ packages/playwright-test/types/test.d.ts | 20 ----------- tests/page/expect-misc.spec.ts | 35 ------------------- 8 files changed, 5 insertions(+), 99 deletions(-) diff --git a/docs/src/api/class-locatorassertions.md b/docs/src/api/class-locatorassertions.md index 1ed17a916a9a0..f7c5e7a2faf75 100644 --- a/docs/src/api/class-locatorassertions.md +++ b/docs/src/api/class-locatorassertions.md @@ -1719,19 +1719,3 @@ Expected options currently selected. ### option: LocatorAssertions.toHaveValues.timeout = %%-csharp-java-python-assertions-timeout-%% * since: v1.23 - -## async method: LocatorAssertions.toIntersectViewport -* since: v1.30 -* langs: js - -Ensures the [Locator] points to an element that intersects viewport, according to the [intersection observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API). - -**Usage** - -```js -const locator = page.locator('button.submit'); -await expect(locator).toIntersectViewport(); -``` - -### option: LocatorAssertions.toIntersectViewport.timeout = %%-js-assertions-timeout-%% -* since: v1.30 diff --git a/docs/src/test-assertions-js.md b/docs/src/test-assertions-js.md index 2c5ce5a51cfe2..318ce106df623 100644 --- a/docs/src/test-assertions-js.md +++ b/docs/src/test-assertions-js.md @@ -43,7 +43,6 @@ By default, the timeout for assertions is set to 5 seconds. Learn more about [va | [`method: LocatorAssertions.toHaveText`] | Element matches text | | [`method: LocatorAssertions.toHaveValue`] | Input has a value | | [`method: LocatorAssertions.toHaveValues`] | Select has options selected | -| [`method: LocatorAssertions.toIntersectViewport`] | Element intersects viewport | | [`method: PageAssertions.toHaveScreenshot#1`] | Page has a screenshot | | [`method: PageAssertions.toHaveTitle`] | Page has a title | | [`method: PageAssertions.toHaveURL`] | Page has a URL | diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.ts index 90261a8151171..fd1bd6ea1a80e 100644 --- a/packages/playwright-core/src/server/frames.ts +++ b/packages/playwright-core/src/server/frames.ts @@ -1426,7 +1426,7 @@ export class Frame extends SdkObject { const injected = await context.injectedScript(); progress.throwIfAborted(); - const { log, matches, received } = await injected.evaluate(async (injected, { info, options, snapshotName }) => { + const { log, matches, received } = await injected.evaluate((injected, { info, options, snapshotName }) => { const elements = info ? injected.querySelectorAll(info.parsed, document) : []; const isArray = options.expression === 'to.have.count' || options.expression.endsWith('.array'); let log = ''; @@ -1438,7 +1438,7 @@ export class Frame extends SdkObject { log = ` locator resolved to ${injected.previewNode(elements[0])}`; if (snapshotName) injected.markTargetElements(new Set(elements), snapshotName); - return { log, ...(await injected.expect(elements[0], options, elements)) }; + return { log, ...injected.expect(elements[0], options, elements) }; }, { info, options, snapshotName: progress.metadata.afterSnapshot }); if (log) diff --git a/packages/playwright-core/src/server/injected/injectedScript.ts b/packages/playwright-core/src/server/injected/injectedScript.ts index 00cb2fb01c88e..7fa2344dc598a 100644 --- a/packages/playwright-core/src/server/injected/injectedScript.ts +++ b/packages/playwright-core/src/server/injected/injectedScript.ts @@ -1119,7 +1119,7 @@ export class InjectedScript { this.onGlobalListenersRemoved.add(addHitTargetInterceptorListeners); } - async expect(element: Element | undefined, options: FrameExpectParams, elements: Element[]) { + expect(element: Element | undefined, options: FrameExpectParams, elements: Element[]) { const isArray = options.expression === 'to.have.count' || options.expression.endsWith('.array'); if (isArray) return this.expectArray(elements, options); @@ -1130,16 +1130,13 @@ export class InjectedScript { // expect(locator).not.toBeVisible() passes when there is no element. if (options.isNot && options.expression === 'to.be.visible') return { matches: false }; - // expect(locator).not.toIntersectViewport() passes when there is no element. - if (options.isNot && options.expression === 'to.intersect.viewport') - return { matches: false }; // When none of the above applies, expect does not match. return { matches: options.isNot }; } - return await this.expectSingleElement(element, options); + return this.expectSingleElement(element, options); } - private async expectSingleElement(element: Element, options: FrameExpectParams): Promise<{ matches: boolean, received?: any }> { + private expectSingleElement(element: Element, options: FrameExpectParams): { matches: boolean, received?: any } { const expression = options.expression; { @@ -1187,13 +1184,6 @@ export class InjectedScript { return { received, matches }; } } - { - // Viewport intersection - if (expression === 'to.intersect.viewport') { - const ratio = await this.viewportRatio(element); - return { received: `viewport ratio ${ratio}`, matches: ratio > 0 }; - } - } // Multi-Select/Combobox { diff --git a/packages/playwright-test/src/expect.ts b/packages/playwright-test/src/expect.ts index cd0a6405a1666..efa2e291d5161 100644 --- a/packages/playwright-test/src/expect.ts +++ b/packages/playwright-test/src/expect.ts @@ -38,7 +38,6 @@ import { toHaveURL, toHaveValue, toHaveValues, - toIntersectViewport, toPass } from './matchers/matchers'; import { toMatchSnapshot, toHaveScreenshot } from './matchers/toMatchSnapshot'; @@ -144,7 +143,6 @@ const customMatchers = { toHaveURL, toHaveValue, toHaveValues, - toIntersectViewport, toMatchSnapshot, toHaveScreenshot, toPass, diff --git a/packages/playwright-test/src/matchers/matchers.ts b/packages/playwright-test/src/matchers/matchers.ts index c61802caffb5b..f73702892198d 100644 --- a/packages/playwright-test/src/matchers/matchers.ts +++ b/packages/playwright-test/src/matchers/matchers.ts @@ -117,16 +117,6 @@ export function toBeVisible( }, options); } -export function toIntersectViewport( - this: ReturnType, - locator: LocatorEx, - options?: { timeout?: number }, -) { - return toBeTruthy.call(this, 'toIntersectViewport', locator, 'Locator', async (isNot, timeout, customStackTrace) => { - return await locator._expect(customStackTrace, 'to.intersect.viewport', { isNot, timeout }); - }, options); -} - export function toContainText( this: ReturnType, locator: LocatorEx, diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts index df2b1232565da..77ce9df68da2e 100644 --- a/packages/playwright-test/types/test.d.ts +++ b/packages/playwright-test/types/test.d.ts @@ -4539,26 +4539,6 @@ interface LocatorAssertions { */ timeout?: number; }): Promise; - - /** - * Ensures the [Locator] points to an element that intersects viewport, according to the - * [intersection observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API). - * - * **Usage** - * - * ```js - * const locator = page.locator('button.submit'); - * await expect(locator).toIntersectViewport(); - * ``` - * - * @param options - */ - toIntersectViewport(options?: { - /** - * Time to retry the assertion for. Defaults to `timeout` in `TestConfig.expect`. - */ - timeout?: number; - }): Promise; } /** diff --git a/tests/page/expect-misc.spec.ts b/tests/page/expect-misc.spec.ts index 1f10bc1ac9975..37d3916d450d5 100644 --- a/tests/page/expect-misc.spec.ts +++ b/tests/page/expect-misc.spec.ts @@ -285,38 +285,3 @@ test.describe('toHaveId', () => { await expect(locator).toHaveId('node'); }); }); - -test.describe('toIntersectViewport', () => { - test('should work', async ({ page }) => { - await page.setContent(` -
-
foo
- `); - await expect(page.locator('#big')).toIntersectViewport(); - await expect(page.locator('#small')).not.toIntersectViewport(); - await page.locator('#small').scrollIntoViewIfNeeded(); - await expect(page.locator('#small')).toIntersectViewport(); - }); - - test('should have good stack', async ({ page }) => { - let error; - try { - await expect(page.locator('body')).not.toIntersectViewport({ timeout: 100 }); - } catch (e) { - error = e; - } - expect(error).toBeTruthy(); - expect(/unexpected value "viewport ratio \d+/.test(error.stack)).toBe(true); - const stackFrames = error.stack.split('\n').filter(line => line.trim().startsWith('at ')); - expect(stackFrames.length).toBe(1); - expect(stackFrames[0]).toContain(__filename); - }); - - test('should report intersection even if fully covered by other element', async ({ page }) => { - await page.setContent(` -

hello

-