0

I am testing a payment checkout. The normal flow is that you press a button with a dynamic url (href="javascript;:"), a popup window opens up, you enter the payment details and accept, when the payments has been processed the window then closes and the site you were previously on redirects to a receipt page.

I've managed to test the whole flow up until the step where the browser should close the popup window by itself. For some reason it doesn't. I've tried adding a step to manually close it but that doesn't seem to work because the way my testcafe test works is that instead of opening the popup window in a new window, it just replaces the current window with the new one. And I've come to the conclusion that the previous window still needs to be open for this to work.

I've tried many different combinations with these two

disableNativeAutomation: true,
disableMultipleWindows: true

but again it seems that the only way to open the popup window is by enabling these, but if I enable these then I can't have multiple windows/tabs open.

So I tried one last thing:

experimentalMultipleWindows: true,
disableNativeAutomation: false,
disableMultipleWindows: false

together with

await t.click(this.$button, { modifiers: { ctrl: true } })

which opens the payment checkout in a new tab. But now I need to switch to the new tab to continue my test. Both tabs use the same hostname, but they have different pathnames. I tried switching to the new tab by using one of these two:

await t.switchToWindow((w) => w.url.pathname === '[PATH_TO_PAYMENT_CHECKOUT]/.html')
await t.switchToWindow((w) => w.url.href !== 'https://[URL_TO_CURRENT_TAB]')

but none of them seemed to work.

It should also be noted that the payment checkout uses iframes inside of iframes which might cause issues.

My ideal test would look something like this:

await t.click(this.$button, { modifiers: { ctrl: true } })
await t.switchToWindow((w) => w.url.pathname === '[PATH_TO_PAYMENT_CHECKOUT]/.html')
await t.switchToIframe(this.$iframe_checkout)

But doesn't seem to work (for the above reasons).

Any pointers to any workaround to get this to work? (Especially switching tabs to a tab you don't know the full URL of)

0