From 1921e6503c665ded9b718f549e7bc435aa8a2069 Mon Sep 17 00:00:00 2001 From: Sebisnow Date: Wed, 11 Sep 2019 11:41:56 +0200 Subject: [PATCH 1/2] #212 add `dialog_present?/0` function check for dialogs by reading from a dialog, if that fails assume the dialog is not present. --- lib/hound/helpers/dialog.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/hound/helpers/dialog.ex b/lib/hound/helpers/dialog.ex index 379ad13..44ff37d 100644 --- a/lib/hound/helpers/dialog.ex +++ b/lib/hound/helpers/dialog.ex @@ -3,6 +3,21 @@ defmodule Hound.Helpers.Dialog do import Hound.RequestUtils + @doc """ + Checks if a dialog, javascript alert(), confirm() or prompt(), exists + + dialog_present?() + """ + @spec dialog_present?() :: Boolean.t + def dialog_present? do + try do + dialog_text() + true + rescue + RuntimeError -> false + end + end + @doc """ Gets text of a javascript alert(), confirm() or prompt(). From bb2713ef6e084a5a41e65ef62bc6ce199a41da02 Mon Sep 17 00:00:00 2001 From: Sebisnow Date: Wed, 11 Sep 2019 11:43:54 +0200 Subject: [PATCH 2/2] test the presence of a dialog on an alert --- test/helpers/dialog_test.exs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/helpers/dialog_test.exs b/test/helpers/dialog_test.exs index 51dc44b..edbef76 100644 --- a/test/helpers/dialog_test.exs +++ b/test/helpers/dialog_test.exs @@ -6,6 +6,12 @@ defmodule DialogTest do hound_session() + test "Dialog present" do + navigate_to "http://localhost:9090/page1.html" + execute_script("alert('hello')") + assert dialog_present?() == true + end + test "Get dialog text" do navigate_to "http://localhost:9090/page1.html" execute_script("alert('hello')")