You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to run beforeInitialPageLoad conditionally? #61
I can run the login logic in beforeInitialPageLoad but the session is maintained in the subsequent runs. Is there any way to either:
Run beforeInitiaPageLoad only when the session is not found plus how to check if the user already has a session.
OR
Clear the session so that beforeInitialPageLoad can work without interruption (i.e. interaction fail error due to email/password fields not found on the page as the user is not redirected to a login screen).
Thanks for this wonderful project. Loving it so far.
Hi @saxenarajat, please check out the answers below:
Run beforeInitiaPageLoad only when the session is not found
Could you explain a little bit about the use case for this? One thing to try is to invoke await page.goto(url) inside beforeInitiaPageLoad and see if it can establish a session (although the session would be different from the session created from url).
how to check if the user already has a session
One way is to check the user session in the action callback via the page argument.
Clear the session so that beforeInitialPageLoad can work without interruption.
beforeInitialPageLoad is the optional callback before establishing a session, not sure what interruption means in this context. Could you elaborate more on your use cases and what problem you are trying to solve?
So I am trying to test a protected route in my app. If a user is not signed in, she would be redirected to the login screen before she could access that route. I added the logic to log in (searching of email/password fields and filling in the details) in the beforeInitialPageLoad method and it works fine.
However, when I re-run the scenario subsequently, it breaks as the user already have a session and is not redirected to the login screen.
I would recommend using the cookies callback and void logging in if possible.
As an alternative for re-running the scenario, the beforeInitialPageLoad could use Puppeteer APIs to check the url of the redirected page, if the user is not redirected to the login page, just skip the login logic.
Activity
JacksonGL commentedon Feb 2, 2023
Hi @saxenarajat, please check out the answers below:
Could you explain a little bit about the use case for this? One thing to try is to invoke
await page.goto(url)insidebeforeInitiaPageLoadand see if it can establish a session (although the session would be different from the session created fromurl).One way is to check the user session in the
actioncallback via thepageargument.beforeInitialPageLoadis the optional callback before establishing a session, not sure what interruption means in this context. Could you elaborate more on your use cases and what problem you are trying to solve?saxenarajat commentedon Feb 3, 2023
Thanks @JacksonGL for replying,
So I am trying to test a protected route in my app. If a user is not signed in, she would be redirected to the login screen before she could access that route. I added the logic to log in (searching of email/password fields and filling in the details) in the
beforeInitialPageLoadmethod and it works fine.However, when I re-run the scenario subsequently, it breaks as the user already have a session and is not redirected to the login screen.
JacksonGL commentedon Feb 3, 2023
Thanks for sharing the context @saxenarajat
I would recommend using the
cookiescallback and void logging in if possible.As an alternative for re-running the scenario, the
beforeInitialPageLoadcould use Puppeteer APIs to check the url of the redirected page, if the user is not redirected to the login page, just skip the login logic.chore(deps): Bump proxy-addr from 2.0.7 to 2.0.8 in /website (#159)