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

Fix #205 #207

Merged
merged 3 commits into from
Dec 21, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 4.6.0
- Spreewald now explicitly depends on Capybara. We don't expect anyone used it without Capybara in the first place.
- Changes to "the ... field should (not) have (an error|the error ...)" step:
- fixed an edgecases where errors were nested deeper inside a .field_with_errors element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- fixed an edgecases where errors were nested deeper inside a .field_with_errors element
- fixed an edgecase where errors were nested deeper inside a .field_with_errors element

- significant speed-up in most situations

## 4.5.1
- Make `I should see an element for` and `I click on the element for` compatible for Ruby 3.0. ([#204](https://github.com/makandra/spreewald/issues/204))

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.ruby266
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ source 'https://rubygems.org'

ruby '2.6.6'

gemspec

gem 'rake'
gem 'rspec'
gem 'cucumber'
Expand Down
36 changes: 35 additions & 1 deletion Gemfile.ruby266.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
PATH
remote: .
specs:
spreewald (4.6.0)
capybara
cucumber
cucumber_priority (>= 0.3.0)
rspec (>= 2.13.0)
xpath

GEM
remote: https://rubygems.org/
specs:
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
aruba (2.0.0)
bundler (>= 1.17, < 3.0)
childprocess (>= 2.0, < 5.0)
Expand All @@ -9,6 +21,15 @@ GEM
rspec-expectations (~> 3.4)
thor (~> 1.0)
builder (3.2.4)
capybara (3.36.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (4.0.0)
contracts (0.16.0)
cucumber (7.1.0)
Expand Down Expand Up @@ -42,20 +63,30 @@ GEM
cucumber-core (~> 10.1, >= 10.1.0)
cucumber-cucumber-expressions (~> 14.0, >= 14.0.0)
cucumber-messages (~> 17.1, >= 17.1.1)
cucumber_priority (0.3.3)
cucumber
diff-lcs (1.4.4)
ffi (1.15.4)
gemika (0.8.1)
mail (2.7.1)
mini_mime (>= 0.1.1)
matrix (0.4.2)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.1115)
mini_mime (1.1.2)
mini_portile2 (2.5.3)
multi_test (0.1.2)
nokogiri (1.11.1-x86_64-linux)
nokogiri (1.11.1)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
public_suffix (5.0.4)
racc (1.5.2)
rack (3.0.8)
rack-test (2.1.0)
rack (>= 1.3)
rake (13.0.3)
regexp_parser (2.8.3)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -72,6 +103,8 @@ GEM
sys-uname (1.2.2)
ffi (~> 1.1)
thor (1.1.0)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
ruby
Expand All @@ -84,6 +117,7 @@ DEPENDENCIES
nokogiri
rake
rspec
spreewald!

RUBY VERSION
ruby 2.6.6p146
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.ruby320
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ source 'https://rubygems.org'

ruby '3.2.0'

gemspec

gem 'rake'
gem 'rspec'
gem 'cucumber'
Expand Down
32 changes: 32 additions & 0 deletions Gemfile.ruby320.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
PATH
remote: .
specs:
spreewald (4.6.0)
capybara
cucumber
cucumber_priority (>= 0.3.0)
rspec (>= 2.13.0)
xpath

GEM
remote: https://rubygems.org/
specs:
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
aruba (2.0.0)
bundler (>= 1.17, < 3.0)
childprocess (>= 2.0, < 5.0)
Expand All @@ -9,6 +21,15 @@ GEM
rspec-expectations (~> 3.4)
thor (~> 1.0)
builder (3.2.4)
capybara (3.39.2)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (4.0.0)
contracts (0.16.0)
cucumber (7.1.0)
Expand Down Expand Up @@ -42,6 +63,8 @@ GEM
cucumber-core (~> 10.1, >= 10.1.0)
cucumber-cucumber-expressions (~> 14.0, >= 14.0.0)
cucumber-messages (~> 17.1, >= 17.1.1)
cucumber_priority (0.3.3)
cucumber
date (3.3.3)
diff-lcs (1.4.4)
ffi (1.15.4)
Expand All @@ -51,6 +74,7 @@ GEM
net-imap
net-pop
net-smtp
matrix (0.4.2)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.1115)
Expand All @@ -67,8 +91,13 @@ GEM
net-protocol
nokogiri (1.14.1-x86_64-linux)
racc (~> 1.4)
public_suffix (5.0.4)
racc (1.5.2)
rack (3.0.8)
rack-test (2.1.0)
rack (>= 1.3)
rake (13.0.3)
regexp_parser (2.8.3)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -86,6 +115,8 @@ GEM
ffi (~> 1.1)
thor (1.1.0)
timeout (0.3.1)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
x86_64-linux
Expand All @@ -98,6 +129,7 @@ DEPENDENCIES
nokogiri
rake
rspec
spreewald!

RUBY VERSION
ruby 3.2.0p0
Expand Down
19 changes: 19 additions & 0 deletions lib/spreewald_support/capybara_wrapper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Spreewald
class CapybaraWrapper
def self.default_max_wait_time
if Capybara.respond_to?(:default_max_wait_time)
Capybara.default_max_wait_time
else
Capybara.default_wait_time
end
end

def self.default_max_wait_time=(value)
if Capybara.respond_to?(:default_max_wait_time=)
Capybara.default_max_wait_time = value
else
Capybara.default_wait_time = value
end
end
end
end
43 changes: 33 additions & 10 deletions lib/spreewald_support/field_errors.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spreewald_support/driver_info'
require 'spreewald_support/without_waiting'

module Spreewald
def self.field_error_class
Expand All @@ -21,36 +22,58 @@ def self.error_message_xpath_selector=(message_selector)

class FieldErrorFinder
include Spreewald::DriverInfo
include WithoutWaiting

def initialize(page, element)
@page = page
@element = element
end

def error_present?
custom_error? || bootstrap3_error? || bootstrap45_error? || rails_error?
without_waiting do
custom_error? || bootstrap3_error? || bootstrap45_error? || rails_error?
end
end

def custom_error?
Spreewald.field_error_class && @element.has_xpath?("ancestor-or-self::div[contains(@class, \"#{Spreewald.field_error_class}\")]")
return false unless Spreewald.field_error_class
kratob marked this conversation as resolved.
Show resolved Hide resolved

has_xpath? do |x|
x.ancestor_or_self(:div)[x.attr(:class).contains_word(Spreewald.field_error_class)]
end
end

def bootstrap3_error?
@element.has_xpath?('ancestor::div[@class="form-group has-error"]')
has_xpath? do |x|
x.ancestor(:div)[x.attr(:class).contains_word('form-group')][x.attr(:class).contains_word('has-error')]
end
end

def bootstrap45_error?
element_classes = @element[:class] &.split(' ') || []
invalid_elements = if javascript_capable?
@page.all(':invalid') # Collect all invalid elements as Bootstrap 4 and 5 support client validation
end
without_waiting do
element_classes = @element[:class]&.split(' ') || []
invalid_elements = if javascript_capable?
@page.all(':invalid') # Collect all invalid elements as Bootstrap 4 and 5 support client validation
end

element_classes.include?('is-invalid') || (invalid_elements && invalid_elements.include?(@element))
element_classes.include?('is-invalid') || (invalid_elements && invalid_elements.include?(@element))
end
end

def rails_error?
parent_element_classes = @element.find(:xpath, '..')[:class] &.split(' ') || []
parent_element_classes.include?('field_with_errors')
has_xpath? do |x|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brauchen wir dafür noch einen Test?

x.ancestor(:div)[x.attr(:class).contains_word('field_with_errors')]
end
end

private

def has_xpath?(&block)
xpath = XPath.generate(&block)
without_waiting do
@element.has_xpath?(xpath)
end
end

end
end
22 changes: 3 additions & 19 deletions lib/spreewald_support/tolerance_for_selenium_sync_issues.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'spreewald_support/capybara_wrapper'

module ToleranceForSeleniumSyncIssues
RETRY_ERRORS = %w[
ActionController::UrlGenerationError
Expand All @@ -17,24 +19,6 @@ module ToleranceForSeleniumSyncIssues
Selenium::WebDriver::Error::NoSuchAlertError
]

class CapybaraWrapper
def self.default_max_wait_time
if Capybara.respond_to?(:default_max_wait_time)
Capybara.default_max_wait_time
else
Capybara.default_wait_time
end
end

def self.default_max_wait_time=(value)
if Capybara.respond_to?(:default_max_wait_time=)
Capybara.default_max_wait_time = value
else
Capybara.default_wait_time = value
end
end
end

class Patiently
WAIT_PERIOD = 0.05

Expand Down Expand Up @@ -68,7 +52,7 @@ def retryable_error?(e)
end


def patiently(seconds = CapybaraWrapper.default_max_wait_time, &block)
def patiently(seconds = Spreewald::CapybaraWrapper.default_max_wait_time, &block)
if page.driver.wait?
Patiently.new.patiently(seconds, &block)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/spreewald_support/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Spreewald
VERSION = '4.5.1'
VERSION = '4.6.0'
end
13 changes: 13 additions & 0 deletions lib/spreewald_support/without_waiting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spreewald_support/capybara_wrapper'

module Spreewald
module WithoutWaiting
def without_waiting
prior_max_wait_time = CapybaraWrapper.default_max_wait_time
CapybaraWrapper.default_max_wait_time = 0
yield
ensure
CapybaraWrapper.default_max_wait_time = prior_max_wait_time
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

require 'pathname'

require 'capybara'

Dir[Pathname.new(__FILE__).join('..', 'support', '**', '*.rb')].each { |f| require f }


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
require 'spreewald_support/tolerance_for_selenium_sync_issues'

module Capybara
class ElementNotFound < StandardError; end

class << self
attr_accessor :default_max_wait_time
end
end

describe ToleranceForSeleniumSyncIssues do
subject { World.new }
let(:wait_time) { 0.2 }
Expand Down
Loading
Loading