1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

implement refresh

This commit is contained in:
Thomas Walpole 2017-07-04 15:14:55 -07:00
parent 9c3b053676
commit e8fe4e9f43
7 changed files with 61 additions and 2 deletions

View file

@ -10,6 +10,10 @@ class Capybara::Driver::Base
raise NotImplementedError
end
def refresh
raise NotImplementedError
end
def find_xpath(query)
raise NotImplementedError
end

View file

@ -22,6 +22,11 @@ class Capybara::RackTest::Browser
process_and_follow_redirects(:get, path, attributes)
end
def refresh
reset_cache!
request(last_request.fullpath, last_request.env)
end
def submit(method, path, attributes)
path = request_path if not path or path.empty?
process_and_follow_redirects(method, path, attributes, {'HTTP_REFERER' => current_url})

View file

@ -44,6 +44,10 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
browser.visit(path, attributes)
end
def refresh
browser.refresh
end
def submit(method, path, attributes)
browser.submit(method, path, attributes)
end

View file

@ -67,6 +67,13 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
browser.navigate.to(path)
end
def refresh
accept_modal(wait: 0.1) do
browser.navigate.refresh
end
rescue Capybara::ModalNotFound
end
def go_back
browser.navigate.back
end

View file

@ -58,7 +58,7 @@ module Capybara
]
SESSION_METHODS = [
:body, :html, :source, :current_url, :current_host, :current_path,
:execute_script, :evaluate_script, :visit, :go_back, :go_forward,
:execute_script, :evaluate_script, :visit, :refresh, :go_back, :go_forward,
:within, :within_element, :within_fieldset, :within_table, :within_frame, :switch_to_frame,
:current_window, :windows, :open_new_window, :switch_to_window, :within_window, :window_opened_by,
:save_page, :save_and_open_page, :save_screenshot,
@ -269,6 +269,15 @@ module Capybara
driver.visit(visit_uri.to_s)
end
##
#
# Refresh the page
#
def refresh
raise_server_error!
driver.refresh
end
##
#
# Move back a single entry in the browser's history.

View file

@ -0,0 +1,28 @@
# frozen_string_literal: true
Capybara::SpecHelper.spec '#refresh' do
it "reload the page" do
@session.visit('/form')
expect(@session).to have_select('form_locale', selected: 'English')
@session.select('Swedish', from: 'form_locale')
expect(@session).to have_select('form_locale', selected: 'Swedish')
@session.refresh
expect(@session).to have_select('form_locale', selected: 'English')
end
it "raises any errors caught inside the server", requires: [:server] do
quietly { @session.visit("/error") }
expect do
@session.refresh
end.to raise_error(TestApp::TestAppError)
end
it "it reposts" do
@session.visit('/form')
@session.select('Sweden', from: 'form_region')
@session.click_button('awesome')
expect {
@session.refresh
sleep 2
}.to change{ extract_results(@session)['post_count'] }.by(1)
end
end

View file

@ -17,6 +17,7 @@ class TestApp < Sinatra::Base
set :raise_errors, true
set :show_exceptions, false
@@form_post_count = 0
# Also check lib/capybara/spec/views/*.erb for pages not listed here
get '/' do
@ -147,7 +148,8 @@ class TestApp < Sinatra::Base
end
post '/form' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
@@form_post_count += 1
'<pre id="results">' + params[:form].merge({"post_count" => @@form_post_count}).to_yaml + '</pre>'
end
post '/upload_empty' do