diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index 40e481df0..f00b0c23a 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -1,9 +1,9 @@ name: Ruby on Rails CI on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] jobs: test: runs-on: ubuntu-latest @@ -46,8 +46,7 @@ jobs: run: bin/rails test system_tests: - if: github.repository == 'AllYourBot/hostedgpt' - runs-on: large-runner + runs-on: ubuntu-latest concurrency: group: ${{ github.workflow }}-${{ github.head_ref }}-system cancel-in-progress: true @@ -71,13 +70,6 @@ jobs: DISPLAY: "=:99" steps: - - uses: nanasess/setup-chromedriver@v2 - - name: Start chromedriver - run: | - set -x - chromedriver --url-base=/wd/hub & - # sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional - - name: Checkout code uses: actions/checkout@v4 @@ -85,6 +77,35 @@ jobs: with: bundler-cache: true + - name: Set Playwright version env var + run: | + PLAYWRIGHT_CLI_VERSION=$(bundle exec ruby -e 'require "playwright"; puts Playwright::COMPATIBLE_PLAYWRIGHT_VERSION.strip') + echo "PLAYWRIGHT_CLI_VERSION=$PLAYWRIGHT_CLI_VERSION" >> $GITHUB_ENV + + - name: Print Playwright version (DEBUG) + run: echo 'playwright version:'; echo $PLAYWRIGHT_CLI_VERSION + + - name: Print CI and Playwright env vars + run: echo 'env vars:'; echo $CI; echo $PLAYWRIGHT_HEADLESS + + - name: Install playwright + run: npx playwright@${{ env.PLAYWRIGHT_CLI_VERSION }} install + + - name: Cache Playwright Chromium browser + id: playwright-cache + uses: actions/cache@v4 + with: + path: ~/.cache/ms-playwright + key: playwright-browsers-${{ runner.os }}-${{ env.PLAYWRIGHT_CLI_VERSION }} + + - name: Install Playwright Chromium browser (with deps) + if: steps.playwright-cache.outputs.cache-hit != 'true' + run: npx playwright@${{ env.PLAYWRIGHT_CLI_VERSION }} install --with-deps chromium + + - name: Install Playwright Chromium browser deps + if: steps.playwright-cache.outputs.cache-hit == 'true' + run: npx playwright@${{ env.PLAYWRIGHT_CLI_VERSION }} install-deps chromium + - name: Set up database schema run: bin/rails db:prepare @@ -95,7 +116,7 @@ jobs: run: | echo -e "###\n###\n###\n### NOTICE: If these tests fail because of Net::ReadTimeout then re-run the test suite. I can't figure out this sporadic failure.\n###\n###\n###" sed -i 's/hoverOnlyWhenSupported: true/hoverOnlyWhenSupported: false/' config/tailwind.config.js - PARALLEL_WORKERS=2 bin/rails test:system + bin/rails test:system - name: Upload screenshots uses: actions/upload-artifact@v4 diff --git a/Dockerfile b/Dockerfile index 6fd6c66cd..a328263f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -105,6 +105,9 @@ RUN --mount=type=cache,id=gems,target=/tmp/bundle \ RUN apk add --no-cache postgresql-client +# # install nodejs +# RUN apk add --no-cache nodejs npm + ENTRYPOINT ["/rails/bin/docker-entrypoint"] CMD ["./bin/dev"] diff --git a/Gemfile b/Gemfile index a17c20e2d..c08c6395e 100644 --- a/Gemfile +++ b/Gemfile @@ -80,7 +80,7 @@ end group :test do # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] gem "capybara" - gem "selenium-webdriver", "~> 4.23.0" + gem "capybara-playwright-driver" gem "minitest-stub_any_instance" gem "rails-controller-testing" end diff --git a/Gemfile.lock b/Gemfile.lock index cd24904b4..9b2efe513 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -121,6 +121,10 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + capybara-playwright-driver (0.5.2) + addressable + capybara + playwright-ruby-client (>= 1.16.0) coderay (1.1.3) concurrent-ruby (1.2.3) connection_pool (2.4.1) @@ -141,7 +145,11 @@ GEM faraday-multipart (1.0.4) multipart-post (~> 2) faraday-net_http (3.0.2) - ffi (1.17.0) + ffi (1.17.0-aarch64-linux-musl) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-darwin) + ffi (1.17.0-x86_64-linux-gnu) + ffi (1.17.0-x86_64-linux-musl) globalid (1.2.1) activesupport (>= 6.1) hashie (5.0.0) @@ -176,6 +184,9 @@ GEM marcel (1.0.4) matrix (0.4.2) method_source (1.0.0) + mime-types (3.5.2) + mime-types-data (~> 3.2015) + mime-types-data (3.2024.0903) mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.22.3) @@ -234,6 +245,9 @@ GEM ast (~> 2.4.1) racc pg (1.5.6) + playwright-ruby-client (1.47.0) + concurrent-ruby (>= 1.1.6) + mime-types (>= 3.0) postmark (1.25.1) json postmark-rails (0.22.1) @@ -357,13 +371,6 @@ GEM ruby_parser (3.21.0) racc (~> 1.5) sexp_processor (~> 4.16) - rubyzip (2.3.2) - selenium-webdriver (4.23.0) - base64 (~> 0.2) - logger (~> 1.4) - rexml (~> 3.2, >= 3.2.5) - rubyzip (>= 1.2.2, < 3.0) - websocket (~> 1.0) sexp_processor (4.17.1) snaky_hash (2.0.1) hashie @@ -407,6 +414,7 @@ GEM tiktoken_ruby (0.0.6-arm64-darwin) tiktoken_ruby (0.0.6-x86_64-darwin) tiktoken_ruby (0.0.6-x86_64-linux) + tiktoken_ruby (0.0.6-x86_64-linux-musl) timecop (0.9.8) timeout (0.4.1) tins (1.33.0) @@ -426,7 +434,6 @@ GEM bindex (>= 0.4.0) railties (>= 6.0.0) webrick (1.8.1) - websocket (1.2.11) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -439,8 +446,11 @@ PLATFORMS arm64-darwin-21 arm64-darwin-22 arm64-darwin-23 + x86-linux-gnu + x86-linux-musl x86_64-darwin-23 - x86_64-linux + x86_64-linux-gnu + x86_64-linux-musl DEPENDENCIES actioncable-enhanced-postgresql-adapter @@ -451,6 +461,7 @@ DEPENDENCIES bootsnap byebug capybara + capybara-playwright-driver debug dockerfile-rails (>= 1.6) image_processing (~> 1.13.0) @@ -475,7 +486,6 @@ DEPENDENCIES rubocop-rails ruby-lsp ruby-openai (~> 7.0.1) - selenium-webdriver (~> 4.23.0) solid_queue (~> 0.2.1) sprockets-rails standard diff --git a/bin/dev b/bin/dev index be1eec70e..448dee235 100755 --- a/bin/dev +++ b/bin/dev @@ -36,6 +36,9 @@ fi bundle install bin/rails db:prepare +# export PLAYWRIGHT_CLI_VERSION=$(bundle exec ruby -e 'require "playwright"; puts Playwright::COMPATIBLE_PLAYWRIGHT_VERSION.strip') +# npx playwright@${PLAYWRIGHT_CLI_VERSION} install + # Trap SIGTERM and SIGINT and forward them to Overmind trap 'kill -TERM $PID' TERM INT exec overmind start -f Procfile.dev "$@" & diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index fb5f8f6ab..f1fa69d11 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -1,8 +1,14 @@ require "test_helper" +Capybara.register_driver :my_playwright do |app| + Capybara::Playwright::Driver.new(app, + browser_type: ENV["PLAYWRIGHT_BROWSER"]&.to_sym || :chromium, + headless: (false unless ENV["CI"] || ENV["PLAYWRIGHT_HEADLESS"])) +end + class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, - using: :headless_chrome, + driven_by :my_playwright, + # using: :headless_chrome, screen_size: [1400, 800], # this is a short height (800 px) so the viewport scrolls so we can test some scroll interactions options: { timeout: 120 } @@ -79,8 +85,8 @@ def send_keys(keys) key_array = keys.split("+").collect do |key| case key - when "up" - :arrow_up + # when "up" + # :arrow_up when "meta" :command when "esc" @@ -98,7 +104,7 @@ def send_keys(keys) end end - element.send_keys key_array + element.send_keys key_array.first end def click_text(text, params = {})