mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	fix(reporter): fix locator stacks to hide internal detail (#9693)
This commit is contained in:
		
							parent
							
								
									299dffbdb3
								
							
						
					
					
						commit
						6a3e08d1ac
					
				@ -36,7 +36,10 @@ export class Locator implements api.Locator {
 | 
				
			|||||||
  private async _withElement<R>(task: (handle: ElementHandle<SVGElement | HTMLElement>, timeout?: number) => Promise<R>, timeout?: number): Promise<R> {
 | 
					  private async _withElement<R>(task: (handle: ElementHandle<SVGElement | HTMLElement>, timeout?: number) => Promise<R>, timeout?: number): Promise<R> {
 | 
				
			||||||
    timeout = this._frame.page()._timeoutSettings.timeout({ timeout });
 | 
					    timeout = this._frame.page()._timeoutSettings.timeout({ timeout });
 | 
				
			||||||
    const deadline = timeout ? monotonicTime() + timeout : 0;
 | 
					    const deadline = timeout ? monotonicTime() + timeout : 0;
 | 
				
			||||||
    const handle = await this.elementHandle({ timeout });
 | 
					
 | 
				
			||||||
 | 
					    return this._frame._wrapApiCall<R>(async (channel: channels.FrameChannel) => {
 | 
				
			||||||
 | 
					      const result = await channel.waitForSelector({ selector: this._selector, strict: true, state: 'attached', timeout });
 | 
				
			||||||
 | 
					      const handle = ElementHandle.fromNullable(result.element) as ElementHandle<SVGElement | HTMLElement> | null;
 | 
				
			||||||
      if (!handle)
 | 
					      if (!handle)
 | 
				
			||||||
        throw new Error(`Could not resolve ${this._selector} to DOM Element`);
 | 
					        throw new Error(`Could not resolve ${this._selector} to DOM Element`);
 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
@ -44,6 +47,7 @@ export class Locator implements api.Locator {
 | 
				
			|||||||
      } finally {
 | 
					      } finally {
 | 
				
			||||||
        await handle.dispose();
 | 
					        await handle.dispose();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async boundingBox(options?: TimeoutOptions): Promise<Rect | null> {
 | 
					  async boundingBox(options?: TimeoutOptions): Promise<Rect | null> {
 | 
				
			||||||
 | 
				
			|||||||
@ -368,6 +368,43 @@ test('should not have internal error when steps are finished after timeout', asy
 | 
				
			|||||||
  expect(result.output).not.toContain('Internal error');
 | 
					  expect(result.output).not.toContain('Internal error');
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test('should show nice stacks for locators', async ({ runInlineTest }) => {
 | 
				
			||||||
 | 
					  const result = await runInlineTest({
 | 
				
			||||||
 | 
					    'reporter.ts': stepsReporterJS,
 | 
				
			||||||
 | 
					    'playwright.config.ts': `
 | 
				
			||||||
 | 
					      module.exports = {
 | 
				
			||||||
 | 
					        reporter: './reporter',
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					    `,
 | 
				
			||||||
 | 
					    'a.test.ts': `
 | 
				
			||||||
 | 
					      const { test } = pwt;
 | 
				
			||||||
 | 
					      test('pass', async ({ page }) => {
 | 
				
			||||||
 | 
					        await page.setContent('<button></button>');
 | 
				
			||||||
 | 
					        const locator = page.locator('button');
 | 
				
			||||||
 | 
					        await locator.evaluate(e => e.innerText);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    `
 | 
				
			||||||
 | 
					  }, { reporter: '', workers: 1 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  expect(result.exitCode).toBe(0);
 | 
				
			||||||
 | 
					  expect(result.passed).toBe(0);
 | 
				
			||||||
 | 
					  expect(result.output).not.toContain('Internal error');
 | 
				
			||||||
 | 
					  expect(result.output.split('\n').filter(line => line.startsWith('%%')).map(stripEscapedAscii)).toEqual([
 | 
				
			||||||
 | 
					    `%% begin {"title":"Before Hooks","category":"hook"}`,
 | 
				
			||||||
 | 
					    `%% begin {"title":"browserContext.newPage","category":"pw:api"}`,
 | 
				
			||||||
 | 
					    `%% end {"title":"browserContext.newPage","category":"pw:api"}`,
 | 
				
			||||||
 | 
					    `%% end {"title":"Before Hooks","category":"hook","steps":[{"title":"browserContext.newPage","category":"pw:api"}]}`,
 | 
				
			||||||
 | 
					    `%% begin {"title":"page.setContent","category":"pw:api"}`,
 | 
				
			||||||
 | 
					    `%% end {"title":"page.setContent","category":"pw:api"}`,
 | 
				
			||||||
 | 
					    `%% begin {"title":"locator.evaluate(button)","category":"pw:api"}`,
 | 
				
			||||||
 | 
					    `%% end {"title":"locator.evaluate(button)","category":"pw:api"}`,
 | 
				
			||||||
 | 
					    `%% begin {"title":"After Hooks","category":"hook"}`,
 | 
				
			||||||
 | 
					    `%% begin {"title":"browserContext.close","category":"pw:api"}`,
 | 
				
			||||||
 | 
					    `%% end {"title":"browserContext.close","category":"pw:api"}`,
 | 
				
			||||||
 | 
					    `%% end {"title":"After Hooks","category":"hook","steps":[{"title":"browserContext.close","category":"pw:api"}]}`,
 | 
				
			||||||
 | 
					  ]);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function stripEscapedAscii(str: string) {
 | 
					function stripEscapedAscii(str: string) {
 | 
				
			||||||
  return str.replace(/\\u00[a-z0-9][a-z0-9]\[[^m]+m/g, '');
 | 
					  return str.replace(/\\u00[a-z0-9][a-z0-9]\[[^m]+m/g, '');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user