capybara-wait_image 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d5c10cf9ec96ac3fac24de6bce81a52659ec13a055e2dbeb9bc309e9649978f3
4
+ data.tar.gz: 75fe4376400c092a76383b7d0571c27296bffe8f991679302a130684bc02db34
5
+ SHA512:
6
+ metadata.gz: fe2ec92fee1fd86b0745b2611f7ff8f66c81dbe39cf26ee2fa0450b9ef77924bf00b0e75de19538a6b630de142b1614739ac219d2acf96c4ecf0e66b98db6a87
7
+ data.tar.gz: 18a9edd98eca4a49a7d2edd51808411e442ab854e5a77f035adc26d63a57ffcfba1eeb14662231b2e24cb63833b59d3a32749cd91f0769e5644ddbfe667100a9
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ SuggestExtensions: false
4
+ NewCops: enable
5
+ Exclude:
6
+ - "capybara-wait_image.gemspec"
7
+ - 'node_modules/**/*'
8
+ - 'tmp/**/*'
9
+ - 'vendor/**/*'
10
+ - '.git/**/*'
11
+ Style/StringLiterals:
12
+ Enabled: true
13
+ EnforcedStyle: double_quotes
14
+
15
+ Style/StringLiteralsInInterpolation:
16
+ Enabled: true
17
+ EnforcedStyle: double_quotes
18
+
19
+ Layout/LineLength:
20
+ Max: 120
21
+
22
+ Metrics/BlockLength:
23
+ Exclude:
24
+ - 'spec/**/*'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-08-24
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at netwillnet@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in capybara-wait_image.gemspec
6
+ gemspec
7
+
8
+ gem "puma"
9
+ gem "rake", "~> 13.0"
10
+ gem "rspec", "~> 3.0"
11
+ gem "rubocop", "~> 1.21"
12
+ gem "selenium-webdriver"
13
+ gem "sinatra", "~> 3.0"
14
+ gem "webdrivers"
data/Gemfile.lock ADDED
@@ -0,0 +1,115 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capybara-wait_image (0.3.0)
5
+ capybara (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.4)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
+ ast (2.4.2)
13
+ capybara (3.39.1)
14
+ addressable
15
+ matrix
16
+ mini_mime (>= 0.1.3)
17
+ nokogiri (~> 1.8)
18
+ rack (>= 1.6.0)
19
+ rack-test (>= 0.6.3)
20
+ regexp_parser (>= 1.5, < 3.0)
21
+ xpath (~> 3.2)
22
+ diff-lcs (1.5.0)
23
+ json (2.6.3)
24
+ matrix (0.4.2)
25
+ mini_mime (1.1.2)
26
+ mustermann (3.0.0)
27
+ ruby2_keywords (~> 0.0.1)
28
+ nio4r (2.5.8)
29
+ nokogiri (1.14.0-arm64-darwin)
30
+ racc (~> 1.4)
31
+ nokogiri (1.14.0-x86_64-darwin)
32
+ racc (~> 1.4)
33
+ nokogiri (1.14.0-x86_64-linux)
34
+ racc (~> 1.4)
35
+ parallel (1.22.1)
36
+ parser (3.2.0.0)
37
+ ast (~> 2.4.1)
38
+ public_suffix (5.0.1)
39
+ puma (6.0.2)
40
+ nio4r (~> 2.0)
41
+ racc (1.6.2)
42
+ rack (2.2.6)
43
+ rack-protection (3.0.5)
44
+ rack
45
+ rack-test (2.1.0)
46
+ rack (>= 1.3)
47
+ rainbow (3.1.1)
48
+ rake (13.0.6)
49
+ regexp_parser (2.6.1)
50
+ rexml (3.2.5)
51
+ rspec (3.12.0)
52
+ rspec-core (~> 3.12.0)
53
+ rspec-expectations (~> 3.12.0)
54
+ rspec-mocks (~> 3.12.0)
55
+ rspec-core (3.12.0)
56
+ rspec-support (~> 3.12.0)
57
+ rspec-expectations (3.12.2)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.12.0)
60
+ rspec-mocks (3.12.3)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.12.0)
63
+ rspec-support (3.12.0)
64
+ rubocop (1.43.0)
65
+ json (~> 2.3)
66
+ parallel (~> 1.10)
67
+ parser (>= 3.2.0.0)
68
+ rainbow (>= 2.2.2, < 4.0)
69
+ regexp_parser (>= 1.8, < 3.0)
70
+ rexml (>= 3.2.5, < 4.0)
71
+ rubocop-ast (>= 1.24.1, < 2.0)
72
+ ruby-progressbar (~> 1.7)
73
+ unicode-display_width (>= 2.4.0, < 3.0)
74
+ rubocop-ast (1.24.1)
75
+ parser (>= 3.1.1.0)
76
+ ruby-progressbar (1.11.0)
77
+ ruby2_keywords (0.0.5)
78
+ rubyzip (2.3.2)
79
+ selenium-webdriver (4.7.1)
80
+ rexml (~> 3.2, >= 3.2.5)
81
+ rubyzip (>= 1.2.2, < 3.0)
82
+ websocket (~> 1.0)
83
+ sinatra (3.0.5)
84
+ mustermann (~> 3.0)
85
+ rack (~> 2.2, >= 2.2.4)
86
+ rack-protection (= 3.0.5)
87
+ tilt (~> 2.0)
88
+ tilt (2.0.11)
89
+ unicode-display_width (2.4.2)
90
+ webdrivers (5.2.0)
91
+ nokogiri (~> 1.6)
92
+ rubyzip (>= 1.3.0)
93
+ selenium-webdriver (~> 4.0)
94
+ websocket (1.2.9)
95
+ xpath (3.2.0)
96
+ nokogiri (~> 1.8)
97
+
98
+ PLATFORMS
99
+ arm64-darwin-21
100
+ arm64-darwin-22
101
+ x86_64-darwin-22
102
+ x86_64-linux
103
+
104
+ DEPENDENCIES
105
+ capybara-wait_image!
106
+ puma
107
+ rake (~> 13.0)
108
+ rspec (~> 3.0)
109
+ rubocop (~> 1.21)
110
+ selenium-webdriver
111
+ sinatra (~> 3.0)
112
+ webdrivers
113
+
114
+ BUNDLED WITH
115
+ 2.3.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 willnet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Capybara::WaitImage
2
+
3
+ The main cause of flaky tests in E2E tests using a browser is a click error caused by an element being out of alignment with the timing of image display.
4
+
5
+ By adding this gem, the test will wait for the image to be displayed just before each click, hover, etc, thus improving the reliability of the test.
6
+
7
+ Currently, this gem supports only RSpec, so if you want to use it for other than RSpec, please submit a pull request.
8
+
9
+ ## Installation
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add capybara-wait_image --group=test
14
+
15
+ ## Development
16
+
17
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
18
+
19
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
20
+
21
+ ## Contributing
22
+
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/willnet/capybara-wait_image. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/willnet/capybara-wait_image/blob/main/CODE_OF_CONDUCT.md).
24
+
25
+ ## License
26
+
27
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
28
+
29
+ ## Code of Conduct
30
+
31
+ Everyone interacting in the Capybara::WaitImage project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/willnet/capybara-wait_image/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/capybara/wait_image/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capybara-wait_image"
7
+ spec.version = Capybara::WaitImage::VERSION
8
+ spec.authors = ["willnet"]
9
+ spec.email = ["netwillnet@gmail.com"]
10
+
11
+ spec.summary = "Reduce click miss in E2E tests and increases test stability"
12
+ spec.description = "Reduce click miss in E2E tests and increases test stability due to waiting for image to load automatically"
13
+ spec.homepage = "https://github.com/willnet/capybara-wait_image"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.7.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/willnet/capybara-wait_image"
19
+ spec.metadata["changelog_uri"] = "https://github.com/willnet/capybara-wait_image/releases"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "capybara", "~> 3.0"
33
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capybara
4
+ module WaitImage
5
+ VERSION = "0.3.0"
6
+ end
7
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "wait_image/version"
4
+ require "capybara"
5
+
6
+ module Capybara
7
+ # Wait for image to load automatically
8
+ module WaitImage
9
+ def _wait_for_image_loading # rubocop:disable Metrics/MethodLength
10
+ Timeout.timeout(Capybara.default_max_wait_time) do
11
+ sleep 0.5 until evaluate_script(<<~JS)
12
+ Array.prototype.every.call(
13
+ document.querySelectorAll('img'),
14
+ (e) => e.complete
15
+ )
16
+ JS
17
+ end
18
+ rescue Timeout::Error
19
+ _logger.debug "[capybara-wait_image]Timeout::Error"
20
+ rescue Capybara::NotSupportedByDriverError
21
+ # It comes here when you run it in rack-test, but you can ignore it
22
+ rescue ::Selenium::WebDriver::Error::StaleElementReferenceError
23
+ _logger.debug "[capybara-wait_image]Selenium::WebDriver::Error::StaleElementReferenceError"
24
+ reload
25
+ _wait_for_image_loading
26
+ end
27
+
28
+ def click(*keys, **options)
29
+ _wait_for_image_loading
30
+ super
31
+ end
32
+
33
+ def hover
34
+ _wait_for_image_loading
35
+ super
36
+ end
37
+
38
+ def _logger
39
+ @_logger ||= if defined?(Rails)
40
+ Rails.logger
41
+ else
42
+ Logger.new("/dev/null")
43
+ end
44
+ end
45
+ end
46
+
47
+ module Node
48
+ class Element < Base
49
+ prepend WaitImage
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,6 @@
1
+ module Capybara
2
+ module WaitBeforeClick
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-wait_image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - willnet
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: Reduce click miss in E2E tests and increases test stability due to waiting
28
+ for image to load automatically
29
+ email:
30
+ - netwillnet@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - capybara-wait_image.gemspec
45
+ - lib/capybara/wait_image.rb
46
+ - lib/capybara/wait_image/version.rb
47
+ - sig/capybara/wait_before_click.rbs
48
+ homepage: https://github.com/willnet/capybara-wait_image
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/willnet/capybara-wait_image
53
+ source_code_uri: https://github.com/willnet/capybara-wait_image
54
+ changelog_uri: https://github.com/willnet/capybara-wait_image/releases
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.7.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.4.12
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Reduce click miss in E2E tests and increases test stability
74
+ test_files: []