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

93
Views
Testcafe cerrar ventana

Tengo esta página simple que abre una nueva ventana.

 <html> <body> <button id="open">Open window</button> </body> <script> var windowObjectReference; function openRequestedPopup() { windowObjectReference = window.open("http://www.cnn.com/", "CNN"); } document.querySelector("#open").addEventListener("click", openRequestedPopup); </script> </html>

También tengo esta prueba:

 import {Selector} from 'testcafe'; fixture `Close window` .page('http://127.0.0.1:8080/'); test('Close window', async t => { await t.click("#open"); await t.switchToWindow(f => f.url.host==="www.cnn.com").closeWindow(); });

Al intentar encontrar la ventana basada en un predicado, la prueba falla

 PS C:\work\New folder> testcafe edge .\test.js Running tests in: - Microsoft Edge 96.0.1054.43 / Windows 10 Example page × Close the current window 1) Cannot find the window specified in the action parameters. Browser: Microsoft Edge 96.0.1054.43 / Windows 10 1/1 failed (5s)

No puedo entender qué debo hacer para obtener la ventana abierta desde el código js.

¿Cómo puedo obtener la ventana e inspeccionar algunos elementos en el interior?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hemos solucionado problemas relacionados con el modo "Múltiples ventanas del navegador". Instale la versión alfa actual ( npm i testcafe@alpha / npm i testcafe@1.17.2-alpha.2 ). Además, debe corregir el valor de host de su predicado. El nombre de host real de esta página de CNN es edition.cnn.com (puede comprobarlo sin TestCafe observando la propiedad window.location.hostname en la consola del navegador):

 await t.switchToWindow(f => f.url.host === 'edition.cnn.com').closeWindow();

Alternativamente, puede usar t.getCurrentWindow en lugar del predicado:

 await t.click("#open"); const cnnWindow = await t.getCurrentWindow(); await t.closeWindow(cnnWindow);
about 4 years ago · Juan Pablo Isaza 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!