Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to close the current window/tab using cypress

Tags:

cypress

I need to close the tab/window after each test so I can start the next from scratch

describe('theImplementationIamTesting', () => {

   after(() => {
        // CLOSE THE TAB AFTER THE TEST...
   });
});

I am looking a way to close the current tab after the test. I am not talking about closing a child tab/window. I am talking about the initial tab.

In selenium, it will be something like webdriver.close().

I cannot find a single place online, including the cypress website, where it said how to close the tab browser.

Thanks for helping

like image 302
Richard77 Avatar asked Sep 06 '25 03:09

Richard77


1 Answers

If you separate the cases in different test files it will close the whole browser and reopen it every time. This is the only way I had found so far and works for me very well to start every case from scratch since sometimes it continues to run unfinished API requests from the first case after the start of the second case.

The downside is you need to make the initial preparation of the system every time and it increases the runtime.

like image 152
Rosen Mihaylov Avatar answered Sep 07 '25 21:09

Rosen Mihaylov