Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use playwright instead of selenium #508

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -71,20 +70,42 @@ 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

- uses: ruby/setup-ruby@v1
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

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 21 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -451,6 +461,7 @@ DEPENDENCIES
bootsnap
byebug
capybara
capybara-playwright-driver
debug
dockerfile-rails (>= 1.6)
image_processing (~> 1.13.0)
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@" &
Expand Down
16 changes: 11 additions & 5 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -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 }

Expand Down Expand Up @@ -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"
Expand All @@ -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 = {})
Expand Down
Loading