From 2187653f3659dc404ab5bd0e76c7e7298f6aed7e Mon Sep 17 00:00:00 2001 From: "Tyler A. Young" Date: Mon, 10 Jun 2024 15:58:21 -0500 Subject: [PATCH] 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. --- lib/wallaby/httpclient.ex | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/wallaby/httpclient.ex b/lib/wallaby/httpclient.ex index 36b85872..53ba7a0e 100644 --- a/lib/wallaby/httpclient.ex +++ b/lib/wallaby/httpclient.ex @@ -165,19 +165,14 @@ defmodule Wallaby.HTTPClient do defp coerce_json_message(%{"value" => %{"message" => message} = value} = response) do value = - case Regex.named_captures(~r/(?.*): (?{.*})\n.*/, message) do - %{"payload" => payload, "type" => type} -> - message = - case Jason.decode(payload) do - {:ok, message} -> message - _ -> payload - end - - %{ - "message" => message, - "type" => type - } - + with %{"payload" => payload, "type" => type} <- + Regex.named_captures(~r/(?.*): (?{.*})\n.*/, message), + {:ok, message} <- Jason.decode(payload) do + %{ + "message" => message, + "type" => type + } + else _ -> value end