From 535139b6075ba2267174b7be73d74b0b6a29d7ed Mon Sep 17 00:00:00 2001 From: Christian Llupo Date: Sat, 4 Jan 2025 14:24:23 +0200 Subject: [PATCH 1/5] Added Chrome and ChromeDriver checkout on CI and added user data isolation --- .github/workflows/ci.yml | 35 +++++++++++++++++++++++++---------- test/test_helper.rb | 15 +++++++++++++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee37681..7a88f20 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: CI on: pull_request: push: - branches: [ main ] + branches: [main] jobs: scan_ruby: @@ -64,7 +64,7 @@ jobs: test: runs-on: ubuntu-latest - + services: postgres: image: postgres @@ -79,23 +79,35 @@ jobs: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: chronio_test - + steps: - name: Install packages - run: sudo apt-get update && sudo apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 - + run: sudo apt-get update && sudo apt-get install --no-install-recommends -y curl libjemalloc2 libvips42 postgresql-client + + - name: Install Google Chrome and ChromeDriver + uses: browser-actions/setup-chrome@v1 + with: + install-chromedriver: true + install-dependencies: true + id: setup-chrome + + - name: Check for Chrome and ChromeDriver + run: | + ${{ steps.setup-chrome.outputs.chrome-path }} --version + ${{ steps.setup-chrome.outputs.chromedriver-path }} --version + - name: Checkout code uses: actions/checkout@v4 - + - name: Set permissions for bin scripts run: chmod +x bin/* - + - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: .ruby-version bundler-cache: true - + - name: Wait for PostgreSQL to be ready run: | for i in {1..10}; do @@ -108,12 +120,15 @@ jobs: done; echo "PostgreSQL failed to start."; exit 1; - + - name: Run tests env: RAILS_ENV: test DATABASE_URL: postgres://postgres:postgres@localhost:5432/chronio_test - run: bin/rails db:prepare && bin/rails test:system + run: | + # Create a unique user data directory for each test run + export CHROME_USER_DATA_DIR=$(mktemp -d) + bin/rails db:prepare && bin/rails test:system - name: Keep screenshots from failed system tests uses: actions/upload-artifact@v4 diff --git a/test/test_helper.rb b/test/test_helper.rb index 4212510..3ce38df 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,3 +24,18 @@ class TestCase end end end + +Capybara.register_driver :selenium_chrome do |app| + options = Selenium::WebDriver::Chrome::Options.new + options.add_argument('--no-sandbox') + options.add_argument('--disable-dev-shm-usage') + options.add_argument('--headless') # Run in headless mode for CI + options.add_argument("--user-data-dir=#{ENV['CHROME_USER_DATA_DIR']}") # Use unique user data directory + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) +end + +Capybara.javascript_driver = :selenium_chrome + +class ActionDispatch::SystemTestCase + driven_by :selenium_chrome +end From afa3c573cec5646dc864dcc9dbfde914cf91ce47 Mon Sep 17 00:00:00 2001 From: Christian Llupo Date: Sat, 4 Jan 2025 14:26:55 +0200 Subject: [PATCH 2/5] fixed visiting_the_index and should_create_post test --- app/views/posts/_post.html.erb | 2 +- test/system/posts_test.rb | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/views/posts/_post.html.erb b/app/views/posts/_post.html.erb index 2dec497..ac4a94f 100644 --- a/app/views/posts/_post.html.erb +++ b/app/views/posts/_post.html.erb @@ -1,6 +1,6 @@
-
+

Title: <%= post.caption %> diff --git a/test/system/posts_test.rb b/test/system/posts_test.rb index b389c6b..3f8d176 100644 --- a/test/system/posts_test.rb +++ b/test/system/posts_test.rb @@ -1,7 +1,7 @@ require "application_system_test_case" require "devise/test/integration_helpers" -class PostsTest < ApplicationSystemTestCase +class PostsTest < ActionDispatch::SystemTestCase include Devise::Test::IntegrationHelpers setup do @@ -12,18 +12,17 @@ class PostsTest < ApplicationSystemTestCase test "visiting the index" do visit posts_path(locale: I18n.default_locale) - assert_selector ".post", text: @post.body.to_plain_text + assert_selector ".post", text: @post.body.to_plain_text, wait: 5 # Add a wait time end test "should create post" do visit posts_path(locale: I18n.default_locale) click_on "New post" - + fill_in "Title", with: "My first post" - page.execute_script("document.querySelector('trix-editor').editor.insertString('This is the body of the first post.');") - page.execute_script("document.querySelector('trix-editor').dispatchEvent(new Event('input', { bubbles: true }));") + fill_in_rich_text_area "Content", with: "This is the body of the first post." click_on "Submit" - + assert_text "Post was successfully created" end From 18d137144caf2008ef8922e4499733021a362ce3 Mon Sep 17 00:00:00 2001 From: Christian Llupo Date: Sat, 4 Jan 2025 15:01:37 +0200 Subject: [PATCH 3/5] Update ci.yml to use ubuntu 22.04 to fix subsequent t64 package installation errors Ubuntu 24.04 LTS solves the Year 2038 problem 2.0k that existed on armhf. More than a thousand packages have been updated to handle time using a 64-bit value rather than a 32-bit one, making it possible to handle times up to 292 billion years in the future. That is the reason for the new name libasound2t64 with t64 at the end. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a88f20..a8d0555 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: jobs: scan_ruby: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout code From 13f5a1352bb86a413fc38b32d8f262458d6ecfdf Mon Sep 17 00:00:00 2001 From: Christian Llupo Date: Sat, 4 Jan 2025 15:10:09 +0200 Subject: [PATCH 4/5] Update ci.yml Turns out install-dependencies might be the issue --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8d0555..10e7c53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: jobs: scan_ruby: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout code @@ -88,7 +88,7 @@ jobs: uses: browser-actions/setup-chrome@v1 with: install-chromedriver: true - install-dependencies: true + install-dependencies: false id: setup-chrome - name: Check for Chrome and ChromeDriver From 4016dc7903be8bcc02fa7890201e511f99d9b8ca Mon Sep 17 00:00:00 2001 From: Christian Llupo Date: Sat, 4 Jan 2025 15:16:11 +0200 Subject: [PATCH 5/5] Update ci.yml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10e7c53..09e9037 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,6 +87,7 @@ jobs: - name: Install Google Chrome and ChromeDriver uses: browser-actions/setup-chrome@v1 with: + chrome-version: stable install-chromedriver: true install-dependencies: false id: setup-chrome