improve tests for reliability with fully async driver - selenium w/chromedriver
This commit is contained in:
parent
a04c1456e6
commit
d087965f81
|
@ -74,7 +74,7 @@ Capybara::SpecHelper.spec "#attach_file" do
|
|||
|
||||
it "should not send anything when attaching no files to a multiple upload field" do
|
||||
@session.click_button('Upload Empty Multiple')
|
||||
expect(@session.body).to include("Successfully ignored empty file field")
|
||||
expect(@session).to have_content("Successfully ignored empty file field")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,11 +9,13 @@ Capybara::SpecHelper.spec '#body' do
|
|||
context "encoding of response between ascii and utf8" do
|
||||
it "should be valid with html entities" do
|
||||
@session.visit('/with_html_entities')
|
||||
expect(@session).to have_content('Encoding') # wait for content to appear if visit is async
|
||||
expect { @session.body.encode!("UTF-8") }.not_to raise_error
|
||||
end
|
||||
|
||||
it "should be valid without html entities" do
|
||||
@session.visit('/with_html')
|
||||
expect(@session).to have_content('This is a test') # wait for content to appear if visit is async
|
||||
expect { @session.body.encode!("UTF-8") }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
|
|
@ -386,8 +386,8 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
|
||||
it "should follow redirects" do
|
||||
@session.click_button('Go FAR')
|
||||
expect(@session.current_url).to match(%r{/landed$})
|
||||
expect(@session).to have_content('You landed')
|
||||
expect(@session.current_url).to match(%r{/landed$})
|
||||
end
|
||||
|
||||
it "should post pack to the same URL when no action given" do
|
||||
|
|
|
@ -92,14 +92,14 @@ Capybara::SpecHelper.spec '#click_link' do
|
|||
|
||||
it "should find a link matching an exact regex pattern" do
|
||||
@session.click_link('labore', :href => /\/with_simple_html/)
|
||||
expect(@session).to have_content('Bar')
|
||||
expect(@session).to have_content('Bar')
|
||||
end
|
||||
|
||||
|
||||
it "should find a link matching a partial regex pattern" do
|
||||
@session.click_link('labore', :href => /\/with_simple/)
|
||||
expect(@session).to have_content('Bar')
|
||||
end
|
||||
|
||||
|
||||
it "should raise an error if no link's href matched the pattern" do
|
||||
expect { @session.click_link('labore', :href => /invalid_pattern/) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.click_link('labore', :href => /.+d+/) }.to raise_error(Capybara::ElementNotFound)
|
||||
|
@ -122,8 +122,9 @@ Capybara::SpecHelper.spec '#click_link' do
|
|||
expect(@session).to have_content('You landed')
|
||||
end
|
||||
|
||||
it "should follow redirects" do
|
||||
it "should follow redirects back to itself" do
|
||||
@session.click_link('BackToMyself')
|
||||
expect(@session).to have_css('#referrer', text: /\/with_html$/)
|
||||
expect(@session).to have_content('This is a test')
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require "capybara/spec/test_app"
|
||||
|
||||
Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
|
||||
before :all do
|
||||
@servers = 2.times.map { Capybara::Server.new(TestApp.clone).boot }
|
||||
|
@ -11,6 +13,9 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
|
|||
end
|
||||
|
||||
def should_be_on server_index, path="/host", scheme="http"
|
||||
#This delay is to give fully async drivers (selenium w/chromedriver) time for the browser
|
||||
#to get to its destination - should be removed when we have a waiting current_url matcher
|
||||
sleep 0.1 # remove and adjust tests when a waiting current_url/path matcher is implemented
|
||||
# Check that we are on /host on the given server
|
||||
s = @servers[server_index]
|
||||
expect(@session.current_url.chomp('?')).to eq("#{scheme}://#{s.host}:#{s.port}#{path}")
|
||||
|
@ -62,13 +67,13 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
|
|||
should_be_on 1
|
||||
end
|
||||
|
||||
it "is unaffected by posting through a relative form", focus: true do
|
||||
it "is unaffected by posting through a relative form" do
|
||||
visit_host_links
|
||||
@session.click_button("Relative Host")
|
||||
should_be_on 0
|
||||
end
|
||||
|
||||
it "is affected by posting through an absolute form", focus: true do
|
||||
it "is affected by posting through an absolute form" do
|
||||
visit_host_links
|
||||
@session.click_button("Absolute Host")
|
||||
should_be_on 1
|
||||
|
|
|
@ -46,6 +46,7 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|||
context "with block" do
|
||||
before(:each) do
|
||||
@session.find(:css, '#openTwoWindows').click
|
||||
sleep(0.2) # wait for the windows to open
|
||||
end
|
||||
|
||||
it "should be able to switch to current window" do
|
||||
|
|
|
@ -114,7 +114,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|||
expect(@session.evaluate_script("[window.outerWidth, window.outerHeight];")).to eq([width-10, height-10])
|
||||
end
|
||||
|
||||
it 'should stay on current window if invoked not for current window' do
|
||||
it 'should stay on current window if invoked not for current window', requires: [:windows, :js] do
|
||||
|
||||
@other_window = @session.window_opened_by do
|
||||
@session.find(:css, '#openWindow').click
|
||||
|
|
|
@ -129,11 +129,11 @@ class TestApp < Sinatra::Base
|
|||
end
|
||||
|
||||
get '/with.*html' do
|
||||
erb :with_html
|
||||
erb :with_html, locals: { referrer: request.referrer }
|
||||
end
|
||||
|
||||
get '/:view' do |view|
|
||||
erb view.to_sym
|
||||
erb view.to_sym, locals: { referrer: request.referrer }
|
||||
end
|
||||
|
||||
post '/form' do
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<div id="referrer"><%= referrer %></div>
|
||||
<h1>This is a test</h1>
|
||||
|
||||
<h2 class="no text"></h2>
|
||||
|
|
Loading…
Reference in New Issue