mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
handle default prompt value for headless chrome
This commit is contained in:
parent
7e2e6e433b
commit
e74bfa092e
4 changed files with 42 additions and 6 deletions
|
@ -252,7 +252,9 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
else
|
||||
yield if block_given?
|
||||
modal = find_modal(options)
|
||||
|
||||
modal.send_keys options[:with] if options[:with]
|
||||
|
||||
message = modal.text
|
||||
modal.accept
|
||||
message
|
||||
|
@ -391,13 +393,13 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
}
|
||||
window.capybara.add_handler(modal_handler);
|
||||
|
||||
window.alert = window.confirm = function(str) {
|
||||
window.capybara.handler_called(modal_handler, str);
|
||||
window.alert = window.confirm = function(str = "") {
|
||||
window.capybara.handler_called(modal_handler, str.toString());
|
||||
return #{accept ? 'true' : 'false'};
|
||||
};
|
||||
window.prompt = function(str) {
|
||||
window.capybara.handler_called(modal_handler, str);
|
||||
return #{accept ? "'#{response_text}'" : 'null'};
|
||||
}
|
||||
window.prompt = function(str = "", default_text = "") {
|
||||
window.capybara.handler_called(modal_handler, str.toString());
|
||||
return #{accept ? (response_text.nil? ? "default_text" : "'#{response_text}'") : 'null'};
|
||||
}
|
||||
JS
|
||||
execute_script script
|
||||
|
|
|
@ -109,6 +109,14 @@ $(function() {
|
|||
$(this).attr('response', response);
|
||||
}
|
||||
});
|
||||
$('#open-prompt-with-default').click(function() {
|
||||
var response = prompt('Prompt opened', 'Default value!');
|
||||
if(response === null) {
|
||||
$(this).attr('response', 'dismissed');
|
||||
} else {
|
||||
$(this).attr('response', response);
|
||||
}
|
||||
});
|
||||
$('#open-twice').click(function() {
|
||||
if (confirm('Are you sure?')) {
|
||||
if (!confirm('Are you really sure?')) {
|
||||
|
|
|
@ -11,6 +11,13 @@ Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
|
|||
expect(@session).to have_xpath("//a[@id='open-prompt' and @response='']")
|
||||
end
|
||||
|
||||
it "should accept the prompt with no message when there is a default" do
|
||||
@session.accept_prompt do
|
||||
@session.click_link('Open defaulted prompt')
|
||||
end
|
||||
expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='Default value!']")
|
||||
end
|
||||
|
||||
it "should return the message presented" do
|
||||
message = @session.accept_prompt do
|
||||
@session.click_link('Open prompt')
|
||||
|
@ -25,6 +32,21 @@ Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
|
|||
expect(@session).to have_xpath("//a[@id='open-prompt' and @response='the response']")
|
||||
end
|
||||
|
||||
it "should accept the prompt with a response when there is a default" do
|
||||
@session.accept_prompt with: 'the response' do
|
||||
@session.click_link('Open defaulted prompt')
|
||||
end
|
||||
expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='the response']")
|
||||
end
|
||||
|
||||
it "should accept the prompt with a blank response when there is a default", :focus_ do
|
||||
pending "Geckodriver doesn't set a blank response currently" if @session.respond_to?(:mode) && @session.mode.to_s == "selenium_marionette"
|
||||
@session.accept_prompt with: '' do
|
||||
@session.click_link('Open defaulted prompt')
|
||||
end
|
||||
expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='']")
|
||||
end
|
||||
|
||||
it "should accept the prompt if the message matches" do
|
||||
@session.accept_prompt 'Prompt opened', with: 'matched' do
|
||||
@session.click_link('Open prompt')
|
||||
|
|
|
@ -96,6 +96,10 @@
|
|||
<a href="#" id="open-prompt">Open prompt</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="#" id="open-prompt-with-default">Open defaulted prompt</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input id="disable-on-click"/>
|
||||
</p>
|
||||
|
|
Loading…
Add table
Reference in a new issue