Skip to content

Commit

Permalink
Attempt to improve test stability
Browse files Browse the repository at this point in the history
  • Loading branch information
hopsoft committed Mar 26, 2024
1 parent 2b8bc31 commit da65e21
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bin/docker/run/local
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fi
# ============================================================================================================
npm install
if [ ! -f "/mnt/external/.playwright" ]; then
npx playwright install chromium --with-deps
npx playwright@latest install chromium --with-deps
touch /mnt/external/.playwright
fi
bundle install
Expand Down
11 changes: 4 additions & 7 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ def before_setup
@playwright_exec = Playwright.create(playwright_cli_executable_path: "npx playwright")
@playwright = @playwright_exec.playwright
@browser = @playwright.public_send(BROWSER).launch
@context = @browser.new_context(
bypassCSP: true,
ignoreHTTPSErrors: true
)
@context = @browser.new_context
@page = @context.new_page
@page.set_default_timeout Capybara.default_max_wait_time * 1_000
end
Expand Down Expand Up @@ -78,14 +75,15 @@ def element_mutated?(testid)
# @param interval [Integer] The time interval to wait between checks (default: 20ms)
def wait_for_mutations(testid, timeout: 5.seconds, interval: 0.02)
wait_for_mutations_finished testid, timeout: timeout, interval: interval
sleep 0.1 # TODO: figure out why this is needed
yield element(testid).element_handle if block_given?
Timeout.timeout timeout.to_i do
sleep interval.to_f until element_mutated?(testid)
end
yield element(testid).element_handle if block_given?
rescue Timeout::Error
sleep 0.5 # last ditch effort to avoid flakiness
yield element(testid).element_handle if block_given?
ensure
wait_for_mutations_finished testid, timeout: timeout, interval: interval
end

# Waits for an element's mutation tracking to reset, then yields the element handle.
Expand All @@ -95,7 +93,6 @@ def wait_for_mutations(testid, timeout: 5.seconds, interval: 0.02)
# @param timeout [Integer] The maximum time to wait (default: 5s)
# @param interval [Integer] The time interval to wait between checks (default: 20ms)
def wait_for_mutations_finished(testid, timeout: 5.seconds, interval: 0.02)
sleep 0.1 # TODO: figure out why this is needed
Timeout.timeout timeout.to_i do
sleep interval.to_f while element_mutated?(testid)
end
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand Down
14 changes: 8 additions & 6 deletions test/system/tests/drivers/window_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ class DriversWindowTest < ApplicationSystemTestCase
end

COUNT.times do
wait_for_mutations :window_driver_message do
element(:window_driver_allow).click
end
# wait_for_mutations :window_driver_message do
element(:window_driver_allow).click
sleep 0.1 # TODO: Figure out why this is needed for the window driver/allow rails mechanics
# end
end

wait_for_mutations_finished :window_driver_message do |el|
assert_equal "AllowControllerActionCommand invoked #{COUNT} times", el.inner_text
end
# wait_for_mutations_finished :window_driver_message do |el|
# assert_equal "AllowControllerActionCommand invoked #{COUNT} times", el.inner_text
assert_equal "AllowControllerActionCommand invoked #{COUNT} times", element(:window_driver_message).inner_text
# end
end

test "command that ALLOWS the rails controller action to perform handles abort" do
Expand Down

0 comments on commit da65e21

Please sign in to comment.