From c6287e644fac2826b2bcc3b19f64794c11156ad8 Mon Sep 17 00:00:00 2001 From: YusukeIwaki Date: Sat, 26 Aug 2023 06:22:22 +0800 Subject: [PATCH] Improve timeout specs --- spec/feature/timeout_spec.rb | 35 ++++++++++++++++++++++++++++++----- spec/spec_helper.rb | 8 ++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/spec/feature/timeout_spec.rb b/spec/feature/timeout_spec.rb index c324de8..605c6db 100644 --- a/spec/feature/timeout_spec.rb +++ b/spec/feature/timeout_spec.rb @@ -6,6 +6,18 @@ sleep params[:s].to_i 'OK' end + sinatra.get('/ng_to_ok') do + <<~HTML + + NG + + + HTML + end end around do |example| @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6288b0f..63baaa6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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