<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="323291" data-post-id="323291">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="stratigos" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stratigos/120/5629_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  stratigos
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I have this login helper working for my app, using wallaby, ex machina, and auth generator:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyAppElixirWeb.TestHelpers.AdminAuthHelper do
  use Wallaby.DSL

  import MyAppElixir.Factories.AdminFactory

  @admin_cookie "_myapp_elixir_web_admin_remember_me"

  def create_admin_and_log_in(session) do
    admin =
      build(:admin, %{})
      |&gt; set_password("1VeryValidPassword$")
      |&gt; insert()

    admin_token = MyAppElixir.Accounts.generate_admin_session_token(admin)

    endpoint_opts =
      Application.get_env(:myapp_elixir, MyAppElixirWeb.Endpoint)

    secret_key_base = Keyword.fetch!(endpoint_opts, :secret_key_base)

    conn =
      %Plug.Conn{secret_key_base: secret_key_base}
      |&gt; Plug.Conn.put_resp_cookie(
        @admin_cookie,
        admin_token,
        sign: true
      )

    visit_a_page_to_set_auth_cookie_for_wallaby(session, conn)

    {:ok, %{session: session, admin: admin}}
  end

  defp visit_a_page_to_set_auth_cookie_for_wallaby(session, conn) do
    session
    |&gt; visit("/")
    |&gt; set_cookie(
      @admin_cookie,
      conn.resp_cookies[@admin_cookie][:value]
    )
  end
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="323291" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-323291" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="323291"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="324708" data-post-id="324708">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="thomasbrus" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/thomasbrus/120/40196_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  thomasbrus
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I think you may have to add <code>import Wallaby.Browser</code> to the module</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="324708" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-324708" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="324708"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="358802" data-post-id="358802">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="slouchpie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/slouchpie/120/34819_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  slouchpie
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Is this still working for you?<br>
I have been working on a very similar problem, trying to set a cookie that will work for the phx_gen_auth session cookie.<br>
I am having a problem with signed cookies because the session cookie uses the configured signing salt but <code>put_resp_cookie</code> uses a different signing salt (the cookie name appended to “_cookie”).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="358802" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-358802" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="358802"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="362482" data-post-id="362482">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ravecat" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ravecat/120/34767_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ravecat
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/slouchpie" rel="nofollow">@slouchpie</a> did you find a solution for the examples above?</p>
<p>I tried to use <a class="mention" href="/u/stratigos" rel="nofollow">@stratigos</a> example (but using the <code>user_id</code> with map)</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">feature "put cookie directly", ctx do
      endpoint_opts = Application.get_env(:runa, RunaWeb.Endpoint)
      secret_key_base = Keyword.fetch!(endpoint_opts, :secret_key_base)

      conn =
        %Plug.Conn{secret_key_base: secret_key_base}
        |&gt; Plug.Conn.put_resp_cookie("_runa_key", %{user_id: ctx.user.id},
          sign: true
        )

      resp_cookie = conn.resp_cookies["_runa_key"][:value]

      ctx.session
      |&gt; visit("/")
      |&gt; set_cookie("_runa_key", resp_cookie)
      |&gt; visit("/team")
      |&gt; assert_has(Query.css("[aria-label='Team members']"))
    end
</code></pre>
<p>but ran into a few problems (these are pictured), <a href="https://github.com/ravecat/runa/blob/b678f3778dc77b6d333ef4ce1d3f37ff70d94916/test/runa_web/live/team/show_test.exs#L35" rel="noopener nofollow ugc">code here</a></p>
<ol>
<li>
<p>Empty session data inside <code>Plug.Session</code><br>
</p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.elixirforum.com/uploads/default/original/3X/9/d/9da5b238526ea183fd07c3db8816fc04830bb133.jpeg" data-download-href="https://forum.elixirforum.com/uploads/default/9da5b238526ea183fd07c3db8816fc04830bb133" title="image" rel="nofollow"><img src="https://forum.elixirforum.com/uploads/default/original/3X/9/d/9da5b238526ea183fd07c3db8816fc04830bb133.jpeg" alt="image" data-base62-sha1="muBXQvePDSXVofmxdu3MG0nWFXB" width="690" height="303" data-dominant-color="232322"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1200×528 55.4 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><p></p>
</li>
<li>
<p>Strange format of encoded cookies, tuple with timestamp instead of map</p>
</li>
</ol>
<pre data-code-wrap="elixir"><code class="lang-elixir">req_cookies: SFMyNTY.g2gDdAAAAAF3B3VzZXJfaWRiAAInSG4GAEA0WjSWAWIAAVGA.I4hPlHmkS2Jrz5qZgpwHv7AvGXVCqpW7Hy6oxNmCdQo
encoded_cookie_data: {%{user_id: 141128}, 1744635049024, 86400}
</code></pre>
<p>If someone can explain the obtained result, I will be grateful. I have prepared a test example</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">git clone -b demo_e2e_set_cookie --single-branch git@github.com:ravecat/runa.git
mix setup
mix test.watch --only only
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="362482" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-362482" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="362482"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="362487" data-post-id="362487">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="slouchpie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/slouchpie/120/34819_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  slouchpie
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I stopped using <code>wallaby</code> and I am using <a href="https://github.com/ftes/phoenix_test_playwright" class="inline-onebox" rel="noopener nofollow ugc">GitHub - ftes/phoenix_test_playwright: Execute PhoenixTest cases in an actual browser via Playwright. · GitHub</a> instead.</p>
<p>I did some work on this repo to set session cookies and response cookies. <a href="https://github.com/ftes/phoenix_test_playwright/pull/18" rel="noopener nofollow ugc">https://github.com/ftes/phoenix_test_playwright/pull/18</a></p>
<p>I have found playwright to be very stable (less random failures) and recommend switching to this library, if you can.</p>
<p>See the new <code>add_session_cookie</code> function. It works great</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="362487" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-362487" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="362487"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="362491" data-post-id="362491">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ravecat" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ravecat/120/34767_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ravecat
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Ok, Is the problem that set_cookie is not working as expected? Could you give more information</p>
<p>About <a href="https://github.com/ftes/phoenix_test_playwright?tab=readme-ov-file" rel="noopener nofollow ugc">PhoenixTestPlaywright</a>. How’s the parity of features relative to playwright?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="362491" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-362491" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="362491"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="362512" data-post-id="362512">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="slouchpie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/slouchpie/120/34819_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  slouchpie
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I am not an expert on the Wallaby code but I know from working on the feature for the playwright lib that <code>put_resp_cookie</code> and the session cookie use different signing salt. Looking at the wallaby code here <a href="https://github.com/elixir-wallaby/wallaby/blob/e71ce54ac4ae03d9847ba00b2af99fa52a1da308/lib/wallaby/webdriver_client.ex#L430" class="inline-onebox" rel="noopener nofollow ugc">wallaby/lib/wallaby/webdriver_client.ex at e71ce54ac4ae03d9847ba00b2af99fa52a1da308 · elixir-wallaby/wallaby · GitHub</a> i see nothing being done to support session cookies in Phoenix. I am happy for somebody else to prove me wrong.</p>
<p>As for the comparison of features between the libs, I imagine Wallaby has more features due its maturity. But I am really not an authority on either library.</p>
<p>Here is a real test that uses playwright in one of my projects:</p>
<p></p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.elixirforum.com/uploads/default/original/3X/d/4/d49fb61b1e1171cf41d6297a5a849f8698c45825.png" data-download-href="https://forum.elixirforum.com/uploads/default/d49fb61b1e1171cf41d6297a5a849f8698c45825" title="image" rel="nofollow"><img src="https://forum.elixirforum.com/uploads/default/optimized/3X/d/4/d49fb61b1e1171cf41d6297a5a849f8698c45825_2_690x526.png" alt="image" data-base62-sha1="ukXp1VuJAwp3ys0m9HboeDT368B" width="690" height="526" srcset="https://forum.elixirforum.com/uploads/default/optimized/3X/d/4/d49fb61b1e1171cf41d6297a5a849f8698c45825_2_690x526.png, https://forum.elixirforum.com/uploads/default/original/3X/d/4/d49fb61b1e1171cf41d6297a5a849f8698c45825.png 1.5x, https://forum.elixirforum.com/uploads/default/original/3X/d/4/d49fb61b1e1171cf41d6297a5a849f8698c45825.png 2x" data-dominant-color="191926"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">827×631 53.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><p></p>
<p>You can see how easy it is to set the session cookie. That is the primary reason I recommend using this lib. This project in particular only has “passkey” (WebAuthn) authentication and I really wanted to avoid dealing with that <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"></p>
<p>BTW the session options module looks like this:</p>
<p></p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.elixirforum.com/uploads/default/original/3X/f/7/f77ecc0b5ef92f7ec147fa7491ed6ac7de6449fa.png" data-download-href="https://forum.elixirforum.com/uploads/default/f77ecc0b5ef92f7ec147fa7491ed6ac7de6449fa" title="image" rel="nofollow"><img src="https://forum.elixirforum.com/uploads/default/original/3X/f/7/f77ecc0b5ef92f7ec147fa7491ed6ac7de6449fa.png" alt="image" data-base62-sha1="zjrAZqjp3BVvK70k1dRFRPmYOGC" width="690" height="466" data-dominant-color="171625"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">725×490 33.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><p></p>
<p>and the <code>produce(context</code> thing in the test is using <a href="https://hex.pm/packages/seed_factory" class="inline-onebox" rel="nofollow">seed_factory | Hex</a></p>
<p>PS When using Wallaby (and previously Hound), I had bad problems when running async tests with concurrent sessions. I got failures that I could not reproduce reliably, nor even understand. The playwright lib has simply been working well for me. This is anecdotal “evidence” and I strongly suggest you use whatever works best for you.</p>
<p>PPS If using an older Elixir version, you will need to do <code>Base.encode64(token, padding: false)</code>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="362512" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-362512" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="362512"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="362513" data-post-id="362513">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="hubertlepicki" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hubertlepicki/120/6822_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  hubertlepicki
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I see this discussion reanimated and maybe just 2 cents from me. I usually solve this with having “autologin” controller, and corresponding route that <em>are only present if Mix.env() == :test</em>.</p>
<p>Then, I just do “visit /autologin/:user_id” as a first step of the test and user is logged in to the account specified by ID.</p>
<p>Again, this needs to be deployed carefully so that the route nor controller are not present in other environments, but should work well with Playwright and Wallaby alike.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="362513" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-362513" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="362513"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="362522" data-post-id="362522">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ravecat" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ravecat/120/34767_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ravecat
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Wrote helper for change Wallaby session based on desired data, I’ve try to generate a session cookie without a real request by manually simulating parts of the Plug pipeline. It forces the execution of any <code>before_send</code> hooks to finalize the response (which includes generating the cookie). Current approach is a bit closer to actual cookie generation than just <code>put_resp_cookie</code></p>
<p><a href="https://github.com/ravecat/runa/blob/292382c41e6d719d8c4ea9f7b00b2abc2cda14e8/test/support/feature_case.ex#L37" rel="noopener nofollow ugc">put_session.ex</a></p>
<pre data-code-wrap="elixir"><code class="lang-elixir"> @spec put_session(Wallaby.Session.t(), atom(), term()) :: Wallaby.Session.t()
  def put_session(session, key, value) do
    endpoint_opts = Application.get_env(:runa, AppWeb.Endpoint)
    secret_key_base = Keyword.fetch!(endpoint_opts, :secret_key_base)
    session_opts = Keyword.fetch!(endpoint_opts, :session_options)
    cookie_key = Keyword.fetch!(session_opts, :key)

    conn =
      %Plug.Conn{secret_key_base: secret_key_base}
      |&gt; Plug.Session.call(Plug.Session.init(session_opts))
      |&gt; Plug.Conn.fetch_session()
      |&gt; Plug.Conn.put_session(key, value)
      |&gt; Plug.Conn.resp(:ok, "")
      |&gt; then(fn conn -&gt;
        Enum.reduce_while(conn.private.before_send || [], conn, fn fun, acc -&gt;
          {:cont, fun.(acc)}
        end)
      end)

    resp_cookie = conn.resp_cookies[cookie_key][:value]

    session
    |&gt; Wallaby.Browser.visit("/")
    |&gt; Wallaby.Browser.set_cookie(cookie_key, resp_cookie)
  end
</code></pre>
<p>Helper required session options inside test environment <a href="https://github.com/ravecat/runa/blob/d1d89df3891afa9402be2cf5435ef6504ca9dc0e/config/test.exs#L22" rel="noopener nofollow ugc">test.exs</a></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">config :runa, AppWeb.Endpoint,
  http: [ip: {127, 0, 0, 1}, port: 4002],
  secret_key_base:
    "C3Vz504bPAE0Ik6A4nGbALDBrwNFGurw445+WHG8e7H9toKW8EfaXfhJN+K",
  session_options: [
    store: :cookie,
    key: "_awesome_test",
    signing_salt: "buKCuE47",
    same_site: "Lax"
  ],
  server: true
</code></pre>
<p>and minor changes <a href="https://github.com/ravecat/runa/blob/d1d89df3891afa9402be2cf5435ef6504ca9dc0e/lib/runa_web/endpoint.ex#L8" rel="noopener nofollow ugc">endpoint.ex</a></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  @session_options Application.compile_env(
                     :runa,
                     [AppWeb.Endpoint, :session_options],
                     store: :cookie,
                     key: "_default_key",
                     signing_salt: "buKCuE42",
                     same_site: "Lax"
                   )
</code></pre>
<p><a href="https://github.com/ravecat/runa/blob/292382c41e6d719d8c4ea9f7b00b2abc2cda14e8/test/runa_web/live/team/show_test.exs#L77" rel="noopener nofollow ugc">Example</a></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    feature "has ability to delete non-owner members", ctx do
      session =
        put_session(ctx.session, :user_id, ctx.user.id)
        |&gt; visit("/team")
        |&gt; assert_has(Query.css("[aria-label='Team members']"))

      {member, _} =
        Enum.find(ctx.members, fn {_, role} -&gt; role.role != :owner end)

      assert_has(
        session,
        Query.css("[aria-label=\"Member #{member.name} form\"]",
          text: member.name
        )
      )
      |&gt; click(Query.css("[aria-label=\"Delete #{member.name} from team\"]"))
      |&gt; click(Query.css("[aria-label=\"Confirm delete contributor\"]"))
      |&gt; visit("/team")
      |&gt; assert_has(
        Query.css("[aria-label=\"Member #{member.name} form\"]", count: 0)
      )
    end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="362522" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-362522" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="362522"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="362524" data-post-id="362524">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ravecat" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ravecat/120/34767_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ravecat
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/slouchpie" rel="nofollow">@slouchpie</a> thank you for your answer and advices, some later I’ll try playwright, your experience is encouraging</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="362524" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-362524" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="362524"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/8034/load_more?page=3">Load more posts</a>
</div></template></turbo-stream>