Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

711
Views
¿Puede ejecutar varias pruebas en un contexto de navegador Playwright Javascript?

¿Es posible ejecutar varias pruebas en una ventana del navegador para dramaturgo/prueba?

actualmente llegará a browser.close(); después de cada prueba a pesar de que están probando en la misma página, lo que les da mucho tiempo extra a las pruebas.

 test.beforeAll(async ({ browser }) => { const context = await browser.newContext(); const page = await context.newPage(); await page.goto('https://example.com'); }); test('nav test', async ({ page }) => { const name = await page.innerText('.navbar__title'); expect(name).toBe('Playwright'); }); test('header test', async ({ page }) => { const name = await page.innerText('.navbar__header'); expect(name).toBe('Playwright'); });
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Cuando crea una prueba como esta test('header test', async ({page}) => { está especificando una page y diciéndole que cree un nuevo contexto de página.

Elimina la page de la prueba y comparte la que creas desde tu .beforeAll

Prueba esto:

 test.describe('1 page multiple tests', () => { let page; test.beforeAll(async ({ browser }) => { const context = await browser.newContext(); page = await context.newPage(); await page.goto('https://example.com'); }); test.afterAll(async ({ browser }) => { browser.close; }); test('nav test', async () => { const name = await page.innerText('h1'); expect(name).toContain('Example'); }); test('header test', async () => { const name = await page.innerText('h1'); expect(name).toContain('Domain'); }); });

Ejecútalo así:

 npx playwright test .\StackTests_SinglePage.spec.ts --headed

(puedes ver el nombre de mi archivo allí)

Es posible que deba cambiarlo a 1 trabajador si intenta ejecutar su prueba en paralelo.

Para mí, ese código abre 1 navegador, 1 página, pasa ambas pruebas y cierra. ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Report

0

¿Puedes intentar envolver las pruebas en un bloque de descripción? Por lo tanto, se tratan como un grupo y no como pruebas individuales.

 test.describe('two tests for same page', () => { test('nav test', async ({ page }) => { const name = await page.innerText('.navbar__title'); expect(name).toBe('Playwright'); }); test('header test', async ({ page }) => { const name = await page.innerText('.navbar__header'); expect(name).toBe('Playwright'); }); });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!