Rob C
Rob C

Reputation: 737

Is there a way to wait for a window to close, with TestCafe

I have a set of automated tests which open a child window + click a button to close the child window, which then causes a page navigation. Asserting the URL results in Failed to restore connection to window within the allocated timeout.

// In child window
await t.typeText(<field>, 'text').click(<submitButton>);

// Main window
await t.expect(getCurrentUrl()).contains('thank_you')

My assumption here is that TestCafe still believes it is in the child window, without waiting for the window to close, and subsequent page navigation.

I can add in some validation, to ensure we're back on the main window... but I was wondering if there was an inbuilt solution to this problem? (I couldn't see anything in the docs).

Upvotes: 1

Views: 741

Answers (1)

Ilya Afanasenko
Ilya Afanasenko

Reputation: 527

After closing the child window, execute the following command:

await t.switchToMainWindow();

Upvotes: 1

Related Questions