Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: unflake a few tests (#39084)

Dmitry Gozman6a928b02f4de
diff --git a/packages/playwright-core/src/server/dispatchers/pageAgentDispatcher.ts b/packages/playwright-core/src/server/dispatchers/pageAgentDispatcher.ts
index 65b57bab06..8884638250 100644
--- a/packages/playwright-core/src/server/dispatchers/pageAgentDispatcher.ts
+++ b/packages/playwright-core/src/server/dispatchers/pageAgentDispatcher.ts
@@ -76,11 +76,15 @@ export class PageAgentDispatcher extends Dispatcher<SdkObject, channels.PageAgen
const self = this;
return {
onBeforeTurn(params: { conversation: loopTypes.Conversation }) {
+ if (self._disposed)
+ return;
const userMessage = params.conversation.messages.find(m => m.role === 'user');
self._dispatchEvent('turn', { role: 'user', message: userMessage?.content ?? '' });
},
onAfterTurn(params: { assistantMessage: loopTypes.AssistantMessage, totalUsage: loopTypes.Usage }) {
+ if (self._disposed)
+ return;
const usage = { inputTokens: params.totalUsage.input, outputTokens: params.totalUsage.output };
const intent = params.assistantMessage.content.filter(c => c.type === 'text').map(c => c.text).join('\n');
self._dispatchEvent('turn', { role: 'assistant', message: intent, usage });
@@ -90,15 +94,21 @@ export class PageAgentDispatcher extends Dispatcher<SdkObject, channels.PageAgen
},
onBeforeToolCall(params: { toolCall: loopTypes.ToolCallContentPart }) {
+ if (self._disposed)
+ return;
self._dispatchEvent('turn', { role: 'assistant', message: `call tool "${params.toolCall.name}"` });
},
onAfterToolCall(params: { toolCall: loopTypes.ToolCallContentPart, result: loopTypes.ToolResult }) {
+ if (self._disposed)
+ return;
const suffix = params.toolCall.result?.isError ? 'failed' : 'succeeded';
self._dispatchEvent('turn', { role: 'user', message: `tool "${params.toolCall.name}" ${suffix}` });
},
onToolCallError(params: { toolCall: loopTypes.ToolCallContentPart, error: Error }) {
+ if (self._disposed)
+ return;
self._dispatchEvent('turn', { role: 'user', message: `tool "${params.toolCall.name}" failed: ${params.error.message}` });
}
};
diff --git a/tests/library/browsercontext-locale.spec.ts b/tests/library/browsercontext-locale.spec.ts
index 231961785e..c3d5335d95 100644
--- a/tests/library/browsercontext-locale.spec.ts
+++ b/tests/library/browsercontext-locale.spec.ts
@@ -116,6 +116,8 @@ it('should work for multiple pages sharing same process', async ({ browser, serv
});
it('should be isolated between contexts', async ({ browser, server }) => {
+ it.slow();
+
const context1 = await browser.newContext({ locale: 'en-US' });
const promises = [];
// By default firefox limits number of child web processes to 8.
diff --git a/tests/library/permissions.spec.ts b/tests/library/permissions.spec.ts
index 3f13729efc..c62e90f6ba 100644
--- a/tests/library/permissions.spec.ts
+++ b/tests/library/permissions.spec.ts
@@ -253,9 +253,10 @@ it.describe(() => {
// Secure context
it.use({ ignoreHTTPSErrors: true, });
- it('should be able to use the local-fonts API', async ({ page, context, httpsServer, browserName, channel }) => {
+ it('should be able to use the local-fonts API', async ({ page, context, httpsServer, browserName, channel, headless }) => {
it.skip(browserName !== 'chromium', 'chromium-only api');
it.fixme(!!channel && channel.startsWith('msedge'), 'always times out in edge');
+ it.fixme(!headless, 'times out in headed');
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/36113' });
await page.goto(httpsServer.EMPTY_PAGE);
diff --git a/tests/library/video.spec.ts b/tests/library/video.spec.ts
index 1a7b624fa6..89154044bf 100644
--- a/tests/library/video.spec.ts
+++ b/tests/library/video.spec.ts
@@ -37,7 +37,7 @@ export class VideoPlayer {
const ffmpeg = registry.findExecutable('ffmpeg')!.executablePathOrDie('javascript');
// Force output frame rate to 25 fps as otherwise it would produce one image per timebase unit
// which is 1 / (25 * 1000).
- this.output = spawnSync(ffmpeg, ['-i', this.fileName, '-r', '25', `${this.fileName}-%03d.png`]).stderr.toString();
+ this.output = spawnSync(ffmpeg, ['-i', this.fileName, '-r', '25', `${this.fileName}-%04d.png`]).stderr.toString();
const lines = this.output.split('\n');
let framesLine = lines.find(l => l.startsWith('frame='))!;
@@ -68,7 +68,7 @@ export class VideoPlayer {
frame(frame: number, offset = { x: 10, y: 10 }): any {
if (!this.cache.has(frame)) {
- const gap = '0'.repeat(3 - String(frame).length);
+ const gap = '0'.repeat(4 - String(frame).length);
const buffer = fs.readFileSync(`${this.fileName}-${gap}${frame}.png`);
this.cache.set(frame, PNG.sync.read(buffer));
}
@@ -153,7 +153,7 @@ function expectFrames(videoFile: string, size: { width: number, height: number }
expectAll(pixels, pixelPredicate);
}
{
- const pixels = videoPlayer.seekLastFrame({ x: size.width - 20, y: 0 }).data;
+ const pixels = videoPlayer.seekLastFrame({ x: size.width - 20, y: 10 }).data;
expectAll(pixels, pixelPredicate);
}
}
@@ -481,15 +481,15 @@ it.describe('screencast', () => {
expect(duration).toBeGreaterThan(0);
{
- const pixels = videoPlayer.seekLastFrame({ x: 0, y: 0 }).data;
+ const pixels = videoPlayer.seekLastFrame({ x: 10, y: 10 }).data;
expectAll(pixels, isAlmostRed);
}
{
- const pixels = videoPlayer.seekLastFrame({ x: 300, y: 0 }).data;
+ const pixels = videoPlayer.seekLastFrame({ x: 300, y: 10 }).data;
expectAll(pixels, isAlmostGray);
}
{
- const pixels = videoPlayer.seekLastFrame({ x: 0, y: 200 }).data;
+ const pixels = videoPlayer.seekLastFrame({ x: 10, y: 200 }).data;
expectAll(pixels, isAlmostGray);
}
{
diff --git a/tests/page/page-click.spec.ts b/tests/page/page-click.spec.ts
index 360cb42054..76b29b9269 100644
--- a/tests/page/page-click.spec.ts
+++ b/tests/page/page-click.spec.ts
@@ -296,7 +296,7 @@ it('should scroll and click the button with smooth scroll behavior', async ({ pa
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/12370' });
await page.goto(server.PREFIX + '/input/scrollable.html');
await page.addStyleTag({ content: 'html { scroll-behavior: smooth; }' });
- for (let i = 0; i < 10; i++) {
+ for (let i = 0; i < 5; i++) {
await page.click('#button-80');
expect(await page.evaluate(() => document.querySelector('#button-80').textContent)).toBe('clicked');
await page.click('#button-20');