TestCafe not waiting for window switch
What is your Scenario?
Upon signin with Firebase via popup dialog, I want to verify that I got redirected to the correct url.
What is the Current behavior?
My test for checking for content in the expected new page fails, as TestCafe didn't wait for the firebase window to close
What is the Expected behavior?
TestCafe should wait for the firebase popup to close, for the app signin to complete and for the user to be redirected to the new page before checking for content.
What is your public website URL? (or attach your complete example)
Re-using the Automatic Switch to New Windows example, which also appears to be using firebase (same ids).
What is your TestCafe test code?
Since the example didn't work, I tried to await for the url, but get an error
1) AssertionError: expected
-https://gounite-dev.firebaseapp.com/__/auth/handler?state=ABbdmanr-8tjXn9aGlY55kFoHq9F91NzKVRIjF_OfvXylgkrqkFneb54CmX8tgLtCdcCrPYaDQ-6BYKAMk6Z4i33LTSLXzZ3oCd7IkAW8U8NHyZqfGEpa8VSY5m_ojH1YT32wNqownOahVB1ss7_eQA01cobM_MqMWS3dpJXrY-rVI3Z-jX_VwOKFAt6sSX32mJ-OwWr0J3N3VdLkVaE8BHMnXLmowupP9kCSr2xK3GtezzHSipKpeHuuvx1mrSfN5VJt6BG0pMazcjE3F2Pvv_2rQOe54eekqwg7tqsrCKhxA2QcfGwqJBccNMzw3Mb3VacpNh2o5_&code=4%2F0AX4XfWiXCdfusvM-G40YJ0ft4ZxaA2a6Mz73shO1tt2MV398i1ovXB02ElPjCSgluhtGspg&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&authuser=0&prompt=consent
+https://localhost/dashboard/
// Enter firebase credentials
await t
.typeText("#identifierId", "[email protected]")
.click("#identifierNext")
.typeText("input[type=password]", "password")
.click("#passwordNext");
await t
.expect(await t.eval(() => document.documentURI))
.eql("https://localhost/dashboard/");
t.expect(Selector("h1").textContent)
.contains("Dashboard")
.ok("We have landed on the Dashboard page");
}
Your complete configuration file
// vi: se ft=json5:
// Check out https://json5.org/
{
skipJsErrors: true,
hostname: "localhost",
compilerOptions: {
// Run testcafe with TS v4
typescript: { "customCompilerModulePath": "../typescript" }
},
clientScripts: [
"./scripts/fix-firebase.js", // force Firebase to use localStorage
{ module: "@testing-library/dom/dist/@testing-library/dom.umd.js" },
],
}
Steps to Reproduce
- Proceed to login with Firebase popup method
- Fill in the email / passwords and press next
- Expect that your app has been redirected and contains content.
TestCafe version
1.18.4
Node.js version
v16.10.0
Command-line arguments
testcafe chrome src/
Browser name(s) and version(s)
Google Chrome Version 98.0.4758.80 (Official Build) (64-bit)
Platform(s) and version(s)
Arch Linux
Other
Being new to TestCafe, I'm assuming that I missed something in regards to awaiting for the new content, and hope that the "Automatic Switch to New Windows" example will be updated following the resolution of this issue to better help newcomers.
When debugging this more with a long timeout and client-side console.log, I notice that the firebase authentication fails with error code 'auth/popup-closed-by-user'. I cannot reproduce this error outside testcafe's environment. From this thread, it seems that this error can occur when the domain is missing from Firebase's list of authorized domains.
Both my app's local domain app.local and localhost are already in Firebase Authorised domains.
It seems that TestCafe runs tests from localhost using a random port, but since ports aren't part of the domain name, and localhost is authorized, I'm confused as to why I'm getting that error.
From firebase doc
auth/popup-closed-by-user
Thrown if the popup window is closed by the user without completing the sign in to the provider.
I confirmed that the email identifier and password that are typed through typeText are correct.
Thank you for the provided code snippet, but unfortunately, I don't understand how I should reproduce the problem on my side. Could you please provide me with a complete example and instructions in a step by step manner on how to reproduce the problem? (it can be either a .zip archive with your complete example of the test, a public project on github or any other way).
Upgrading firebase to v9 solved the issue.