Skip to content

Commit 8667b9d

Browse files
committed
Show warning with text if applicable
1 parent 8833a3f commit 8667b9d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/capybara/cuprite/page.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ def prepare_page
158158
options.merge!(promptText: response) if response
159159
command("Page.handleJavaScriptDialog", **options)
160160
else
161-
warn "Modal window has been opened, but you didn't wrap your code into (`accept_prompt` | `dismiss_prompt` | `accept_confirm` | `dismiss_confirm` | `accept_alert`), accepting by default"
161+
with_text = params["message"] ? "with text `#{params["message"]}` " : ""
162+
warn "Modal window #{with_text}has been opened, but you didn't wrap "\
163+
"your code into (`accept_prompt` | `dismiss_prompt` | "\
164+
"`accept_confirm` | `dismiss_confirm` | `accept_alert`), "\
165+
"accepting by default"
162166
options = { accept: true }
163167
response = params["defaultPrompt"]
164168
options.merge!(promptText: response) if response

spec/integration/session_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,15 @@
926926
end
927927

928928
context "modals" do
929+
it "accepts by default with warning" do
930+
@session.visit "/cuprite/with_js"
931+
expect(@session.driver.browser.page).to receive(:warn).with("Modal window with text `{T}ext \\w|th [reg.exp] (chara©+er$)?` has been opened, but you didn't wrap your code into (`accept_prompt` | `dismiss_prompt` | `accept_confirm` | `dismiss_confirm` | `accept_alert`), accepting by default")
932+
933+
expect { @session.click_link("Open for match") }.not_to raise_error
934+
935+
expect(@session).to have_xpath("//a[@id='open-match' and @confirmed='true']")
936+
end
937+
929938
it "matches on partial strings" do
930939
@session.visit "/cuprite/with_js"
931940
expect do

0 commit comments

Comments
 (0)