Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
Testcafe close window

I have this simple page that opens a new window.

<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>

I also have this test:

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();
});

When trying to find the window based on a predicate the test fails

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)

I am not able to understand what should I do in order to get hold of the window oppened from js code.

How can I get the window and inspect some elements inside?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

We have fixed issues related to "Multiple browser windows" mode. Please install the current alpha version (npm i testcafe@alpha / npm i testcafe@1.17.2-alpha.2). Also, you need to fix your predicate's host value. The actual hostname of this CNN page is edition.cnn.com (you can check it without TestCafe by observing the window.location.hostname property in the browser console):

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

Alternatively, you can use t.getCurrentWindow instead of the predicate:

await t.click("#open");

const cnnWindow = await t.getCurrentWindow();

await t.closeWindow(cnnWindow);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda