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 cuprite as capybara driver #195

Merged
merged 3 commits into from
Aug 23, 2023
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/rails-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
build:
runs-on: 'ubuntu-latest'

timeout-minutes: 15

strategy:
matrix:
ruby: [ '2.6', '2.7' ]
Expand Down Expand Up @@ -55,6 +57,8 @@ jobs:
RAILS_TEST_DB_USERNAME: 'postgres'
RAILS_TEST_DB_PASSWORD: 'postgres'
RAILS_ENV: 'test'
CI: 'true'
PGDATESTYLE: German
run: |
sudo apt-get -yqq install libpq-dev
gem install bundler --version '~> 2'
Expand Down
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,11 @@ end

group :test do
gem 'bundler-audit'
gem 'capybara'
gem 'cuprite'
gem 'database_cleaner'
gem 'fabrication'
gem 'headless'
gem 'mocha', require: false
gem 'rails-controller-testing'
gem 'selenium-webdriver'
gem 'webdrivers'
gem 'webmock'
end

Expand Down
26 changes: 11 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ GEM
xpath (~> 3.2)
chartjs-ror (3.6.4)
rails (>= 3.1)
childprocess (3.0.0)
choice (0.2.0)
chunky_png (1.4.0)
cliver (0.3.2)
coderay (1.1.3)
codez-tarantula (0.5.5)
hpricot (~> 0.8.4)
Expand All @@ -160,6 +160,9 @@ GEM
crack (0.4.5)
rexml
crass (1.0.6)
cuprite (0.13)
capybara (>= 2.1, < 4)
ferrum (~> 0.11.0)
daemons (1.4.0)
dalli (2.7.11)
database_cleaner (2.0.1)
Expand Down Expand Up @@ -244,6 +247,11 @@ GEM
faraday-patron (1.0.0)
fast_jsonapi (1.5)
activesupport (>= 4.2)
ferrum (0.11)
addressable (~> 2.5)
cliver (~> 0.3)
concurrent-ruby (~> 1.1)
websocket-driver (>= 0.6, < 0.8)
ffi (1.15.5)
globalid (1.0.0)
activesupport (>= 5.0)
Expand All @@ -260,7 +268,6 @@ GEM
sysexits (~> 1.1)
hashdiff (1.0.1)
hashie (4.1.0)
headless (2.3.1)
highrise (3.2.3)
activeresource (>= 3.2.13)
hpricot (0.8.6)
Expand Down Expand Up @@ -480,7 +487,6 @@ GEM
ruby-vips (2.1.4)
ffi (~> 1.12)
ruby2_keywords (0.0.4)
rubyzip (2.3.2)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
Expand All @@ -497,9 +503,6 @@ GEM
activerecord (>= 3.1)
activesupport (>= 3.1)
selectize-rails (0.12.6)
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
sentry-raven (3.1.2)
faraday (>= 1.0)
simplecov (0.21.2)
Expand Down Expand Up @@ -553,10 +556,6 @@ GEM
activemodel (>= 5.0)
bindex (>= 0.4.0)
railties (>= 5.0)
webdrivers (4.6.0)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (>= 3.0, < 4.0)
webmock (3.13.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand Down Expand Up @@ -588,12 +587,12 @@ DEPENDENCIES
bullet
bundler-audit
cancancan
capybara
chartjs-ror
codez-tarantula
coffee-rails
config
country_select
cuprite
daemons
dalli
database_cleaner
Expand All @@ -607,7 +606,6 @@ DEPENDENCIES
fast_jsonapi
haml
haml-lint
headless
highrise
image_processing
jbuilder
Expand Down Expand Up @@ -653,7 +651,6 @@ DEPENDENCIES
sdoc
seed-fu
selectize-rails
selenium-webdriver
sentry-raven
simplecov-rcov!
spring
Expand All @@ -663,8 +660,7 @@ DEPENDENCIES
validates_by_schema
validates_timeliness
web-console
webdrivers
webmock

BUNDLED WITH
2.3.9
2.3.12
5 changes: 4 additions & 1 deletion test/integration/choose_order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ class ChooseOrderTest < ActionDispatch::IntegrationTest
test 'keeps current tab when changing orders' do
timeout_safe do
click_link 'Positionen'
assert page.has_selector?('a', text: 'Buchungsposition hinzufügen') # dummy query to wait for page load

assert page.has_link?(href: new_order_accounting_post_path(order_id: order.id)) # query forces to wait for page load
assert_equal order_accounting_posts_path(order), current_path

selectize('choosable_order_id', 'Demo', term: 'demo', clear: true)

assert page.has_link?(href: new_order_accounting_post_path(order_id: orders(:hitobito_demo).id)) # query forces to wait for page load
assert_equal order_accounting_posts_path(orders(:hitobito_demo)), current_path
assert page.has_selector?('li.active', text: 'Positionen')
end
Expand Down
44 changes: 28 additions & 16 deletions test/integration/create_order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ class CreateOrderTest < ActionDispatch::IntegrationTest
selectize('client_work_item_id', 'Puzzle')
check('category_active')
click_link('category_work_item_id_create_link')
click_link('Abbrechen')
within('.modal-dialog') do
click_link('Abbrechen')
end
selectize('client_work_item_id', 'Swisstopo')
click_link('category_work_item_id_create_link')
fill_in('work_item_name', with: 'New Category')
fill_in('work_item_shortname', with: 'NECA')
click_button 'Speichern'
within('.modal-dialog') do
fill_in('work_item_name', with: 'New Category')
fill_in('work_item_shortname', with: 'NECA')
click_button 'Speichern'
end

assert find('#category_work_item_id + .selectize-control').
has_selector?('.selectize-input .item', text: 'New Category')
Expand Down Expand Up @@ -242,9 +246,11 @@ class CreateOrderTest < ActionDispatch::IntegrationTest
fill_in('order_crm_key', with: '123')
click_link('Übernehmen')

assert_equal 'New Client', find('#client_work_item_attributes_name')['value']
fill_in('client_work_item_attributes_shortname', with: 'NECL')
click_button 'Speichern'
within('.modal-dialog') do
assert_equal 'New Client', find('#client_work_item_attributes_name')['value']
fill_in('client_work_item_attributes_shortname', with: 'NECL')
click_button 'Speichern'
end

assert_equal 'New Order', find('#order_work_item_attributes_name')['value']

Expand Down Expand Up @@ -280,8 +286,10 @@ class CreateOrderTest < ActionDispatch::IntegrationTest
click_link('Übernehmen')

assert_equal 'New Client', find('#client_work_item_attributes_name')['value']
fill_in('client_work_item_attributes_shortname', with: 'NECL')
click_button 'Speichern'
within('.modal-dialog') do
fill_in('client_work_item_attributes_shortname', with: 'NECL')
click_button 'Speichern'
end

assert_equal 'New Order', find('#order_work_item_attributes_name')['value']

Expand Down Expand Up @@ -520,20 +528,24 @@ class CreateOrderTest < ActionDispatch::IntegrationTest

def create_client
click_link('client_work_item_id_create_link')
fill_in('client_work_item_attributes_name', with: 'New Client')
fill_in('client_work_item_attributes_shortname', with: 'NECL')
click_button 'Speichern'
within('.modal-dialog') do
fill_in('client_work_item_attributes_name', with: 'New Client')
fill_in('client_work_item_attributes_shortname', with: 'NECL')
click_button 'Speichern'
end
end

def create_category
click_link('category_work_item_id_create_link')
fill_in('work_item_name', with: 'New Category')
fill_in('work_item_shortname', with: 'NECA')
click_button 'Speichern'
within('.modal-dialog') do
fill_in('work_item_name', with: 'New Category')
fill_in('work_item_shortname', with: 'NECA')
click_button 'Speichern'
end
end

def click_add_contact
find("a.add_nested_fields_link[data-object-class='order_contact']").click
find("a.add_nested_fields_link[data-object-class='order_contact']").trigger("click")
end

def fill_mandatory_fields(with_name = true)
Expand Down
25 changes: 15 additions & 10 deletions test/integration/plannings_orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,15 @@ class PlanningsOrdersTest < ActionDispatch::IntegrationTest
click_button 'OK'
end

page.assert_selector('div.-definitive', count: 12)
within('.planning-calendar') do
assert_selector('div.-definitive', count: 12)
drag(row_mark.all('.day')[5], row_pascal.all('.day')[9])

drag(row_mark.all('.day')[5], row_pascal.all('.day')[9])
page.assert_selector('.day.-selected', count: 10)
drag(row_pascal.all('.day.-selected')[2], row_mark.all('.day')[0], row_mark.all('*')[0])
row_mark.assert_selector('.day.-selected.-definitive:nth-child(2)')
page.assert_selector('.day.-definitive:not(.-selected)', count: 10, text: 100)
assert_selector('.day.-selected', count: 10)
drag(row_pascal.all('.day.-selected')[2], row_mark.all('.day')[0])

assert_selector('.day.-definitive', count: 10)
end
end
end

Expand Down Expand Up @@ -373,8 +375,9 @@ class PlanningsOrdersTest < ActionDispatch::IntegrationTest
page.assert_selector('.planning-delete', visible: true)

assert_difference('Planning.count', -2) do
find('.planning-delete').click
accept_confirmation('Bist du sicher, dass du die selektierte Planung löschen willst?')
accept_confirm('Bist du sicher, dass du die selektierte Planung löschen willst?') do
find('.planning-delete').click
end
page.assert_selector('.planning-panel', visible: false)
page.assert_selector('div.day.-definitive', count: 0)
end
Expand Down Expand Up @@ -500,11 +503,13 @@ def assert_percents(percents, row)
end

def row_mark
find("#planning_row_employee_#{employees(:mark).id}_work_item_#{work_item_id}")
# TODO: without `sleep` I get "Node is either not visible or not an HTMLElement". Why??
@row_mark ||= find("#planning_row_employee_#{employees(:mark).id}_work_item_#{work_item_id}").tap { sleep 0.1 }
end

def row_pascal
find("#planning_row_employee_#{employees(:pascal).id}_work_item_#{work_item_id}")
# TODO: without `sleep` I get "Node is either not visible or not an HTMLElement". Why??
@row_pascal ||= find("#planning_row_employee_#{employees(:pascal).id}_work_item_#{work_item_id}").tap { sleep 0.1 }
end

def work_item_id
Expand Down
51 changes: 22 additions & 29 deletions test/support/integration_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ def timeout_safe
rescue Errno::ECONNREFUSED,
Timeout::Error,
Capybara::FrozenInTime,
Capybara::ElementNotFound,
Selenium::WebDriver::Error::StaleElementReferenceError => e
skip e.message || e.class.name
Capybara::ElementNotFound => e
if ENV['CI'] == true
skip e.message || e.class.name
else
raise
end
end

def open_selectize(id, options = {})
element = find("##{id} + .selectize-control")
element.find('.selectize-input').click unless options[:no_click]
element.find('.selectize-input').trigger('click') unless options[:no_click]
element.find('.selectize-input input').native.send_keys(:backspace) if options[:clear]
element.find('.selectize-input input').set(options[:term]) if options[:term].present?
element.find('.selectize-input input').native.send_keys(options[:term].chars) if options[:term].present?
if options[:assert_empty]
page.assert_no_selector('.selectize-dropdown-content')
else
Expand All @@ -44,43 +47,33 @@ def open_selectize(id, options = {})
end

def selectize(id, value, options = {})
open_selectize(id, options).find('.selectize-option,.option', text: value).click
open_selectize(id, options).find('.selectize-option,.option', text: value).trigger('click')
end

def drag(from_node, *to_node)
action = page.driver.browser.action.click_and_hold(from_node.native)
to_node.each { |node| action = action.move_to(node.native) }
action.release.perform
def mouse
page.driver.browser.mouse
end

def accept_confirmation(expected_message = nil)
if expected_message.present?
assert_equal expected_message, page.driver.browser.switch_to.alert.text
end
page.driver.browser.switch_to.alert.accept
def move_mouse_to(element)
x, y = element.native.node.find_position
mouse.move(x: x, y: y)
end

def dismiss_confirmation(expected_message = nil)
if expected_message.present?
assert_equal expected_message, page.driver.browser.switch_to.alert.text
def drag(from_element, *to_elements)
move_mouse_to(from_element)
mouse.down

to_elements.each do |to_element|
move_mouse_to(to_element)
end
page.driver.browser.switch_to.alert.dismiss
mouse.up
end

Capybara.add_selector(:name) do
xpath { |name| XPath.descendant[XPath.attr(:name).contains(name)] }
end

def clear_cookies
browser = Capybara.current_session.driver.browser
if browser.respond_to?(:clear_cookies)
# Rack::MockSession
browser.clear_cookies
elsif browser.respond_to?(:manage) && browser.manage.respond_to?(:delete_all_cookies)
# Selenium::WebDriver
browser.manage.delete_all_cookies
else
raise "Don't know how to clear cookies. Weird driver?"
end
Capybara.current_session.driver.clear_cookies
end
end
Loading
Loading