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

88
Views
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 answers
Answer question

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