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

Feature request: Affordances for asserting on js console output #785

Open axelson opened 2 months ago

axelson commented 2 months ago

Elixir and Erlang/OTP versions

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

Elixir 1.16.2 (compiled with Erlang/OTP 2

Operating system

macOS and Ubuntu

Browser

N/A or all

Driver

ChromeDriver

Correct Configuration

Current behavior

I'd like to be able to easily assert on the js console output in my tests. Ideally I'd be able to assert that a specific console log was output for a given step of the test.

This is kind of possible right now with CaptureIO.capture_io but there's some drawbacks currently:

the helper is small:

  defp assert_io(session, fun, expected) when is_function(fun, 0) do
    js_io = CaptureIO.capture_io(fun)

    assert js_io =~ expected
  end

Although it might be possible to workaround that with a macro (but that might feel a bit too magical)

Expected behavior

I'd like it to be easier to assert on js console output and have that documented within the library

Test Code & HTML

N/A

Demonstration Project

No response

mhanberg commented 2 months ago

Seems like a reasonable request and enhancement.

Another potential API is to make it so you could do something like

session
|> click(@button)
|> assert_console(~r/success/)

where assert_console has the same "waiting" functionality that some of the other assertions have, could also have like count: 2 etc options

axelson commented 2 months ago

Yeah that would be a great UX 👍