elixir-wallaby/wallaby

Multiple wallaby configs for different umbrella apps

Arp-G opened this issue · 4 comments

Arp-G commented

Elixir and Erlang/OTP versions

Erlang/OTP 24 [erts-12.3.2.12] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1]

Elixir 1.14.5 (compiled with Erlang/OTP 24)

Operating system

macos version 13.4.1

Browser

Chrome Version 114.0.5735.198

Driver

ChromeDriver 114.0.5735.90

Correct Configuration

  • I confirm that I have Wallaby configured correctly.

Current behavior

We have an umbrella app set up with a separate web and admin app. I would like to configure wallaby separately for the two. However, since umbrella apps share configs so the web app seems to override the configs I set in the admin app test.exs file.

Is there any way to avoid this problem? I was hoping for a way to override the configs somewhere for example when starting a session something like Wallaby.start_session(screenshot_dir: "custom_dir")

Expected behavior

There is a way for different ubmrella apps to have separate wallaby configurations.

Test Code & HTML

NA

Demonstration Project

No response

Can you put the configuration in the test helper? (I assume umbrellas have a test helper for each app)

Arp-G commented

Thanks for replying. I tried adding this to my admin app in app/apps/admin_app/test/test_helper.exs

  import Config

  config :wallaby,
    otp_app: :admin_app,
    driver: Wallaby.Chrome,
    screenshot_dir: "wallaby_screenshots",
    # Wallaby should take screenshots on test failures
    screenshot_on_failure: true,
    # Amount of time that Wallaby should wait to find an element on the page.
    max_wait_time: 5000,
    # Throw JavaScript errors in elixir
    js_errors: true,
    # IO device where JavaScript console logs are written
    js_logger: :stdio,
    chromedriver: [
      headless: true
    ]

  {:ok, _} = Application.ensure_all_started(:wallaby)
  Application.put_env(:wallaby, :base_url, MyApp.AdminApp.Endpoint.url())

But on trying to run tests I get a

** (RuntimeError) could not set configuration via Config. This usually means you are trying to execute a configuration file directly, instead of reading it with Config.Reader

I guess configs are to be set only at compile time

Sorry, I meant by doing Application.put_env

Arp-G commented

Thanks a lot @mhanberg that solved my problem.

For anyone encountering the same issue, this is how I set my wallaby configs now, I have set the configurations separately for the different apps in their respective test_helper.exs files and I no longer set the configs in the config/test.exs files

  Application.put_all_env([
    {
      :wallaby,
      otp_app: :web_app,
      driver: Wallaby.Chrome,
      screenshot_dir: "wallaby_screenshots",
      screenshot_on_failure: true,
      max_wait_time: 5000,
      js_errors: true,
      js_logger: :stdio,
      chromedriver: [
        headless: true
      ]
    }
  ])

  {:ok, _} = Application.ensure_all_started(:wallaby)
  Application.put_env(:wallaby, :base_url, ConnectWeb.Endpoint.url())