Skip to content

Commit 2187653

Browse files
authored
Fix unhandled alerts not being properly ignored (#779)
This is an improvement over #778. By falling back to the full message value from Chromedriver, we can correctly get the `:unexpected_alert` condition to match on the bizarre, not-quite-JSON message from Chromedriver like: ``` "message" => "unexpected alert open: {Alert text : Error loading data, please refresh and try again}\n (Session info: chrome-headless-shell=125.0.6422.142)\n (Driver info: chromedriver=125.0.6422.78 (14db42ec38aded3304a3e624a0a038e02956b87e-refs/branch-heads/6422@{#1088}),platform=Mac OS X 14.5.0 x86_64)" ``` Applying this patch to my local copy, my default-configured Chromedriver correctly ignores the alert and my tests that passed on v0.36.6 again pass.
1 parent 5cee4c0 commit 2187653

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

lib/wallaby/httpclient.ex

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,14 @@ defmodule Wallaby.HTTPClient do
165165

166166
defp coerce_json_message(%{"value" => %{"message" => message} = value} = response) do
167167
value =
168-
case Regex.named_captures(~r/(?<type>.*): (?<payload>{.*})\n.*/, message) do
169-
%{"payload" => payload, "type" => type} ->
170-
message =
171-
case Jason.decode(payload) do
172-
{:ok, message} -> message
173-
_ -> payload
174-
end
175-
176-
%{
177-
"message" => message,
178-
"type" => type
179-
}
180-
168+
with %{"payload" => payload, "type" => type} <-
169+
Regex.named_captures(~r/(?<type>.*): (?<payload>{.*})\n.*/, message),
170+
{:ok, message} <- Jason.decode(payload) do
171+
%{
172+
"message" => message,
173+
"type" => type
174+
}
175+
else
181176
_ ->
182177
value
183178
end

0 commit comments

Comments
 (0)