diff --git a/src/common/interact.ts b/src/common/interact.ts index 9f0f802..27decaf 100644 --- a/src/common/interact.ts +++ b/src/common/interact.ts @@ -49,21 +49,20 @@ export const _interact = async (page: Page, interaction: Interaction) => { /* Element Interactions */ const { annotation } = interaction; - const element = await page.locator( - `[x-pretzelduck-annotation="(PD:${annotation})"]`, - ); + const selector = `[x-pretzelduck-annotation="(PD:${annotation})"]`; + + const element = await page.locator(selector); if (type === 'click') { await element.dispatchEvent('click'); - - return element; } if (type === 'input') { const { value } = interaction; + await element.focus(); await element.fill(value); - - return element; } + + return selector; }; diff --git a/src/common/progress.ts b/src/common/progress.ts index 2638568..8a3d8d6 100644 --- a/src/common/progress.ts +++ b/src/common/progress.ts @@ -1,62 +1,58 @@ -import type { Locator } from '@playwright/test'; +import type { Page } from '@playwright/test'; import type { ModifiedField } from '../types/ModifiableField'; -import type { TestOptions } from '../types/TestOptions'; import { replaceLast } from './utils/replaceLast'; -export const progress = async ( - element: Locator, - { timeout }: TestOptions['decisions']['progressions'], -) => - element.evaluate( - (element) => { - const annotation = element.getAttribute('x-pretzelduck-annotation'); +export const progress = async (page: Page, selector: string) => + page.evaluate((selector) => { + const element = document.querySelector(selector); - if (annotation == null) { - return; - } - - element.removeAttribute('x-pretzelduck-annotation'); + if (element == null) { + return; + } - const modifiedField = element.getAttribute( - 'x-pretzelduck-modified-field', - ) as ModifiedField; + const annotation = element.getAttribute('x-pretzelduck-annotation'); - switch (modifiedField) { - case 'text-content': { - const { textContent } = element; + if (annotation == null) { + return; + } - if (textContent == null) { - return; - } + element.removeAttribute('x-pretzelduck-annotation'); - const newTextContent = replaceLast(textContent, annotation, ''); + const modifiedField = element.getAttribute( + 'x-pretzelduck-modified-field', + ) as ModifiedField; - element.textContent = newTextContent; + switch (modifiedField) { + case 'text-content': { + const { textContent } = element; - break; + if (textContent == null) { + return; } - case 'placeholder': - case 'value': { - const attribute = modifiedField; - const attributeValue = element.getAttribute(attribute); + const newTextContent = replaceLast(textContent, annotation, ''); - if (attributeValue == null) { - return; - } + element.textContent = newTextContent; - const lastAnnotationIndex = attributeValue.lastIndexOf(annotation); - const newValue = attributeValue.slice(0, lastAnnotationIndex); + break; + } + case 'placeholder': + case 'value': { + const attribute = modifiedField; - element.setAttribute(attribute, newValue); + const attributeValue = element.getAttribute(attribute); - break; + if (attributeValue == null) { + return; } + + const lastAnnotationIndex = attributeValue.lastIndexOf(annotation); + const newValue = attributeValue.slice(0, lastAnnotationIndex); + + element.setAttribute(attribute, newValue); + + break; } - }, - undefined, - { - timeout, - }, - ); + } + }, selector); diff --git a/src/common/test.ts b/src/common/test.ts index 3b97274..8589c5d 100644 --- a/src/common/test.ts +++ b/src/common/test.ts @@ -61,7 +61,7 @@ export const _test = ( const previousPage = page.url(); - const element = await _interact(page, interaction); + const selector = await _interact(page, interaction); interactionCount++; await page.waitForLoadState('domcontentloaded'); @@ -82,8 +82,8 @@ export const _test = ( const currentPage = page.url(); - if (enabled && previousPage === currentPage && element !== undefined) { - await Promise.allSettled([progress(element, progressions)]); + if (enabled && previousPage === currentPage && selector !== undefined) { + await progress(page, selector); } } while (interactionCount < maxInteractions); diff --git a/src/types/TestOptions.ts b/src/types/TestOptions.ts index 6b9f77f..1cfbb65 100644 --- a/src/types/TestOptions.ts +++ b/src/types/TestOptions.ts @@ -21,7 +21,6 @@ export type TestOptions = { progressions: { enabled: boolean; type: 'forced'; - timeout: number; }; temperature: number; maxEntropy: number; @@ -50,7 +49,6 @@ export const DEFAULT_TEST_OPTIONS: TestOptions = { progressions: { enabled: true, type: 'forced', - timeout: 5000, }, temperature: 0.3, maxEntropy: 0.05,