Troubleshoot sign-in tests
Use this page when a sign-in test fails, or when a reused session or cookie leaves a test on the wrong page. Each entry starts with what you see in the test results.
The test shows the sign-in page
The session loaded, but the server didn’t accept it. Sessions expire, and a sign-out or a password change revokes them on the server. To fix it:
- Check that your sign-in spec runs in
beforeAlland sets"overwrite": true, so each run saves a fresh session. - Check that no test selects Sign out or changes the account’s password. That ends the session for every test that loads the same file. Give that test its own sign-in.
- Add a
findfor an element that only a signed-in reader sees, such as Sign out, after each load and before eachscreenshot. The test then fails at that step instead of taking a screenshot of the sign-in page.
The session loads, but the page still shows the sign-in form
Most apps read their session only when a page loads, so the page that was open during loadState or loadCookie doesn’t know about it yet. Add a goTo after the load step, to the page you want to test:
loadState or loadCookie fails because the right site isn’t open
loadState and loadCookie set cookies and storage on the open site, so they need that site open first. With no site open, loadState fails with the first message. When the open page’s host doesn’t fit the cookie, loadCookie fails with the second, and the host is empty when no site is open:
Add a goTo to the site the file was saved from before the load step, as in the preceding example.
loadState has no data for the open site
The file holds cookies and storage for another site. Check that:
- The
goTobeforeloadStateopens the same host that the sign-in spec saved from.www.example.comandexample.comare different hosts, andlocalStoragealso depends onhttporhttpsand the port. - You saved a file for each site your tests open. One
saveStatesaves one site. For a sign-in that passes through an identity provider, see Sign in through single sign-on.
The state or cookie file doesn’t exist
The path resolves to a different place than the sign-in spec saved to, or the sign-in didn’t run. Check that:
- The sign-in spec is listed in
beforeAll, and it passed. - Each spec’s
directorypoints at the same folder. By default, a relativedirectoryresolves against the spec file that contains the step, so specs in different folders need differentdirectoryvalues.
The state or cookie file already exists
Add "overwrite": true to the saveState or saveCookie step.
A saved cookie has expired
loadCookie doesn’t set a cookie past its expiry. Sign in again in a beforeAll spec on every run, rather than keeping a cookie file between runs. loadState skips expired cookies instead. When something else in the file still fits the site, an expired session shows up as the sign-in page in your test. When nothing else fits, loadState fails with no data for the open site.
A one-time code is rejected
The app says the code from totp() is wrong or expired. Check these causes in order:
- The clock is off. The code depends on the time, so the machine that runs the test needs an accurate clock. Turn on network time sync. Containers and virtual machines that were paused or restored can drift.
- The secret is out of date. Re-enrolling the authenticator, or resetting MFA on the account, creates a new key. Update the
TOTP_SECRETCI secret and your.envfile with the new key. - The authenticator uses other settings.
totp()generates SHA-1, 6-digit, 30-second codes. An app that asks for 8 digits or uses another period or algorithm rejects them. - The code was already used. Many apps accept each code only once. Two tests or CI jobs that sign in within the same 30 seconds can get the same code, and the app rejects the second. Sign in once in
beforeAlland reuse the session. Give jobs that run at the same time their own test accounts.
When the secret isn’t valid base32, the step that generates the code fails with a message that ends like this:
Check that the variable holds the setup key itself, letters A–Z and digits 2–7, and not the whole otpauth:// link.
The app keeps its session in sessionStorage
saveState doesn’t save sessionStorage, so the test is signed out after loadState, even with a fresh file. To fix it, choose one:
- Sign in during each test that needs the session, instead of in
beforeAll. - Ask your engineering team whether the test environment can keep the session in a cookie or
localStorage. Also ask whether there’s a test-only way to create a session. See Ask your engineering and QA teams.