The sendTabUntilFocused
function is an asynchronous function in TypeScript that simulates the pressing of the 'Tab' key until a specific element on the webpage is focused. This function is useful in automated testing scenarios where you need to simulate user interactions with a webpage.
async function sendTabUntilFocused(page: Page, selector: ReturnType<typeof page.locator>): Promise<void>
page
: An instance of thePage
class from the Playwright library, representing a single tab in a browser.selector
: A Locator object, which is used to interact with the element on the webpage.
This function does not return any value. It throws an error if the timeout is reached before the element is focused.
const avatarButtonLocator = page.getByTestId('MainToolbarAvatarMenu');
const menuLocator = page.locator(
'[data-componentid^="ext-avatarmenu-"]:visible',
{has: avatarButtonLocator}
);
// Use the sendTabUntilFocused function to tab until the menu is focused
await sendTabUntilFocused(page, menuLocator);