Closed saxenarajat closed 1 year ago
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?
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 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.
Thanks for sharing the context @saxenarajat
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.
I can run the login logic in
beforeInitialPageLoad
but the session is maintained in the subsequent runs. Is there any way to either:beforeInitiaPageLoad
only when the session is not found plus how to check if the user already has a session.OR
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.