Wallaby testing when browser session is required (i.e. login)

How do I test some code if a browser session with some user data inside (perhaps from Guardian) is required? How do I get that session data into my Wallaby session?

1 Like

By performing the steps necessary to create that data. Click login, fill form etc

If you’re not concerned about phoenix’s ability to hold the session you can also test this without browser testing. You should also be able to set values to the conn’s session manually like so:

conn =
      conn
      |> bypass_through(MyAppWeb.Router, [:browser])
      |> put_session(:account_id, 1)

get conn, …
1 Like

Yeah. But doesn’t Wallaby create a new session for each test? If so, I must perform the steps each time I want to test something that requires me to authenticate?

Yeah, but when I’m using Wallaby (feature/acceptance testing), there is no conn, only the wallaby session. How do I then insert data into the browser session?

Yes. That’s what setup is for. Or you can write a helper function that does this.

1 Like

There’s no session data on the browser side. There is in the case of a default phoenix project just a cookie, which identifies the session a user does have on the server side. So you might want to see how wallaby does handle cookies in browser sessions (in the wallaby docs sessions seem to mean browsing sessions).

Edit:
Also logging in in browser testing is probably simplest done with the login page or whatever login machanism you’re using.

1 Like

Thanks a lot everyone! After googling for the terms that were suggested, I found a GitHub issue that explained that the best way of going about this is to write a helper method thats called in setup to login via the normal steps a user would take.

https://github.com/keathley/wallaby/issues/57

It’s 2020 and Wallaby can access browser cookies. Is there any way to login a user without walking through the login steps?

I asked on stackoverflow as well: