-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chore: adds dynamic locator and element getters in the modal validator #4223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
11 Skipped Deployments
|
async getLocator(selector: string, timeout = 5000, interval = 500): Promise<Locator> { | ||
const start = Date.now() | ||
while (Date.now() - start < timeout) { | ||
const element = this.page.locator(selector) | ||
if (element) { | ||
return element | ||
} | ||
// eslint-disable-next-line no-await-in-loop | ||
await this.page.waitForTimeout(interval) // Wait before rechecking | ||
} | ||
throw new Error(`Element ${selector} did not become visible within ${timeout}ms`) | ||
} | ||
|
||
async getByTestId(testId: string | RegExp, timeout = 5000, interval = 500): Promise<Locator> { | ||
const start = Date.now() | ||
while (Date.now() - start < timeout) { | ||
const element = this.page.getByTestId(testId) | ||
if (element) { | ||
return element | ||
} | ||
// eslint-disable-next-line no-await-in-loop | ||
await this.page.waitForTimeout(interval) // Wait before rechecking | ||
} | ||
throw new Error( | ||
`Element with data-testid="${testId}" did not become visible within ${timeout}ms` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make a utils like getElement
or something that has the timing part of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdym? to move these into the shared/utils?
Coverage Report
File Coverage
|
Description
Added
locator
&element
getters that try to get an element from the page every n ms until a timeout is hit rather than onceType of change
Associated Issues
For Linear issues: Closes APKT-xxx
For GH issues: closes #...
Showcase (Optional)
If there is a UI change include the screenshots with before and after state.
If new feature is being introduced, include the link to demo recording.
Checklist