@@ -1724,3 +1724,75 @@ test('action settling after its attempt ended is not recorded', async () => {
17241724 }
17251725 ` )
17261726} )
1727+
1728+ test ( 'locator without a match is traced without reading its selector' , async ( ) => {
1729+ const { stderr, errorTree, results } = await runInlineBrowserTests (
1730+ {
1731+ 'basic.test.ts' : /* ts */ `
1732+ import { expect, test } from 'vitest'
1733+ import { page } from 'vitest/browser'
1734+
1735+ test('absent', async () => {
1736+ const locator = page.getByRole('button')
1737+ // mimic providers whose selector resolves elements and throws when nothing matches
1738+ Object.defineProperties(locator, {
1739+ _pwSelector: { value: locator.selector },
1740+ selector: { get() { throw new Error('selector should not be read') } },
1741+ })
1742+ // the only matcher that passes when nothing matches
1743+ await expect.element(locator).not.toBeInTheDocument()
1744+ await locator.mark('absent mark')
1745+ })
1746+ ` ,
1747+ } ,
1748+ {
1749+ browser : {
1750+ instances : instances . slice ( 0 , 1 ) ,
1751+ traceView : 'on' ,
1752+ } ,
1753+ } ,
1754+ )
1755+ expect ( stderr ) . toBe ( '' )
1756+ expect ( errorTree ( ) ) . toMatchInlineSnapshot ( `
1757+ {
1758+ "basic.test.ts": {
1759+ "absent": "passed",
1760+ },
1761+ }
1762+ ` )
1763+ const entries = results
1764+ . flatMap ( ( testModule ) => [ ...testModule . children . allTests ( ) ] )
1765+ . flatMap ( ( testCase ) => testCase . artifacts ( ) )
1766+ . flatMap ( ( artifact ) =>
1767+ artifact . type === 'internal:browserTrace' ? ( artifact . data as BrowserTraceData ) . entries : [ ] ,
1768+ )
1769+ . map ( ( entry ) => ( {
1770+ name : entry . name ,
1771+ locator : entry . element ?. locator ,
1772+ selectorResolution : entry . snapshot ?. selectorResolution ,
1773+ } ) )
1774+ expect ( entries ) . toMatchInlineSnapshot ( `
1775+ [
1776+ {
1777+ "locator": "getByRole('button')",
1778+ "name": "not.toBeInTheDocument",
1779+ "selectorResolution": "missing",
1780+ },
1781+ {
1782+ "locator": "getByRole('button')",
1783+ "name": "not.toBeInTheDocument",
1784+ "selectorResolution": "missing",
1785+ },
1786+ {
1787+ "locator": "getByRole('button')",
1788+ "name": "absent mark",
1789+ "selectorResolution": "missing",
1790+ },
1791+ {
1792+ "locator": undefined,
1793+ "name": "vitest:onAfterRetryTask",
1794+ "selectorResolution": undefined,
1795+ },
1796+ ]
1797+ ` )
1798+ } )
0 commit comments