elixir-wallaby / wallaby

Concurrent browser tests for your Elixir web apps.
https://twitter.com/elixir_wallaby
MIT License
1.67k stars 197 forks source link

Error tracking db ownership when overriding the useragent of the session #731

Closed pshoukry closed 1 year ago

pshoukry commented 1 year ago

Elixir and Erlang/OTP versions

Erlang/OTP 25 [erts-13.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.14.3 (compiled with Erlang/OTP 25)

Operating system

Windows with WSL2

Browser

Chrome

Driver

Chrome

Correct Configuration

Current behavior

  1. Setup Wallaby following default steps

  2. Create a session with mobile configuration (to test specific behavior on mobile )

      @mobile [
        capabilities: %{
          chromeOptions: %{
            args: [
              "--no-sandbox",
              "--disable-gpu",
              "--headless",
              "--fullscreen"
            ],
            mobileEmulation: %{
              deviceName: "iPhone 12 Pro"
            }
          }
        }
      ]
  3. Use the session in a test with DB access

    @sessions [@mobile, @small_screen, @default]
    feature "Users sees sidenav", %{sessions: [m, sm, desktop]} do
    user = AccountsFixtures.valid_user_attributes()
    
    m
    |> sign_up(user.username, user.email, user.password)
    |> assert_has(@sidenav)
  4. Run the tests to see the error

    
    ** (DBConnection.OwnershipError) cannot find ownership process for #PID<0.1414.0>.

When using ownership, you must manage connections in one of the four ways:

Expected behavior

Tests run properly which is what happens when you use normal useragent without the mobile capabilities.

The bug is definitely related to the way wallaby uses user_agent to track every session.

Test Code & HTML

@mobile [
        capabilities: %{
          chromeOptions: %{
            args: [
              "--no-sandbox",
              "--disable-gpu",
              "--headless",
              "--fullscreen"
            ],
            mobileEmulation: %{
              deviceName: "iPhone 12 Pro"
            }
          }
        }
      ]

      @small_screen [
        capabilities: %{
          chromeOptions: %{
            args: [
              "--window-size=640,640",
              "--no-sandbox",
              "--disable-gpu",
              "--headless",
              "--fullscreen"
            ]
          }
        }
      ]

      @default []

@sessions [@mobile, @small_screen, @default]
  feature "Users sees sidenav", %{sessions: [m, sm, desktop]} do
    user = AccountsFixtures.valid_user_attributes()

    m
    |> sign_up(user.username, user.email, user.password)
    |> assert_has(@sidenav)

Demonstration Project

No response

pshoukry commented 1 year ago

Opted to manipulate window size using wallaby instead of manipulating the browser capabilities.