Skip to content

Commit

Permalink
Improve timeout specs
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeIwaki committed Aug 25, 2023
1 parent 7301fbb commit c6287e6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
35 changes: 30 additions & 5 deletions spec/feature/timeout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
sleep params[:s].to_i
'OK'
end
sinatra.get('/ng_to_ok') do
<<~HTML
<body>
NG
</body>
<script type="text/javascript">
setTimeout(() => {
document.body.innerHTML = 'OK'
}, #{(params[:s] || 1).to_i * 1000})
</script>
HTML
end
end

around do |example|
Expand Down Expand Up @@ -35,11 +47,24 @@
expect { visit '/sleep?s=3' }.to raise_error(Playwright::TimeoutError)
end

it "respects the custom default time out", driver: :playwright_timeout_2 do
visit "/sleep?s=0"
it 'does timeout respecting default_navigation_timeout option', driver: :playwright_timeout_2_default_timeout_3_default_navigation_timeout_4 do
visit '/sleep?s=3'
expect(page).to have_content('OK')
end

it "respects the custom default time out", driver: :playwright_timeout_2_default_timeout_3 do
visit "/ng_to_ok?s=5"

expect {
page.driver.with_playwright_page(&:itself).get_by_label('does not exist').text_content
}.to raise_error(Playwright::TimeoutError, /Timeout 2000ms exceeded/)
page.driver.with_playwright_page do |playwright_page|
expect {
playwright_page.get_by_text('OK').text_content
}.to raise_error(Playwright::TimeoutError, /Timeout 3000ms exceeded/)
end

visit "/ng_to_ok?s=2"

page.driver.with_playwright_page do |playwright_page|
expect(playwright_page.get_by_text('OK').text_content).to eq('OK')
end
end
end
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
Capybara::Playwright::Driver.new(app, **driver_opts, timeout: 2)
end

Capybara.register_driver(:playwright_timeout_2_default_timeout_3) do |app|
Capybara::Playwright::Driver.new(app, **driver_opts, timeout: 2, default_timeout: 3)
end

Capybara.register_driver(:playwright_timeout_2_default_timeout_3_default_navigation_timeout_4) do |app|
Capybara::Playwright::Driver.new(app, **driver_opts, timeout: 2, default_timeout: 3, default_navigation_timeout: 4)
end

Capybara.default_driver = :playwright
Capybara.save_path = 'tmp/capybara'
Capybara.server = :webrick

0 comments on commit c6287e6

Please sign in to comment.