| import { Locator } from '@playwright/test'; |
|
|
| |
| |
| |
| export async function isElementScrollable(locator: Locator): Promise<boolean> { |
| const scrollInfo = await locator.evaluate((el) => { |
| return { |
| scrollHeight: el.scrollHeight, |
| clientHeight: el.clientHeight, |
| isScrollable: el.scrollHeight > el.clientHeight, |
| }; |
| }); |
| return scrollInfo.isScrollable; |
| } |
|
|
| |
| |
| |
| export async function scrollToBottom(locator: Locator): Promise<void> { |
| await locator.evaluate((el) => { |
| el.scrollTop = el.scrollHeight; |
| }); |
| } |
|
|
| |
| |
| |
| export async function getScrollPosition( |
| locator: Locator |
| ): Promise<{ scrollTop: number; scrollHeight: number; clientHeight: number }> { |
| return await locator.evaluate((el) => ({ |
| scrollTop: el.scrollTop, |
| scrollHeight: el.scrollHeight, |
| clientHeight: el.clientHeight, |
| })); |
| } |
|
|
| |
| |
| |
| export async function isElementVisibleInScrollContainer( |
| element: Locator, |
| container: Locator |
| ): Promise<boolean> { |
| const elementBox = await element.boundingBox(); |
| const containerBox = await container.boundingBox(); |
|
|
| if (!elementBox || !containerBox) { |
| return false; |
| } |
|
|
| |
| return ( |
| elementBox.y >= containerBox.y && |
| elementBox.y + elementBox.height <= containerBox.y + containerBox.height |
| ); |
| } |
|
|