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(). 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')")