capybara-wait_before_click 0.1.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: 0035551bd4ee668708eabad5f2b1efe246a168b6a41edc564b50596e739a3759
4
+ data.tar.gz: 7c8140e61f71a5d7a693a05f7f86e8fe869862e73e1ca3db9f625ea1da2c96ab
5
+ SHA512:
6
+ metadata.gz: fc9a780be9b35fc980029b81b5a53261421221dd8568f0485cfd0b24b475356248efc8a1187bc9aec3c3569fe240218b7ceca558598c5bf54f79bb07a858b27a
7
+ data.tar.gz: 29e66ab3d47b837bda68170975ec5da1bb2870170bffc64180a840177302d6fe4d0b0c29fe92d90cfb196a609260a2fb653d015825ac372fc9165f20a0dbda05
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ SuggestExtensions: false
4
+ NewCops: enable
5
+ Exclude:
6
+ - "capybara-wait_before_click.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
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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in capybara-wait_before_click.gemspec
6
+ gemspec
7
+
8
+ gem "puma"
9
+ gem "rake", "~> 13.0"
10
+ gem "rspec", "~> 3.0"
11
+ gem "rubocop", "~> 1.21"
12
+ gem "sinatra", "~> 3.0"
13
+ gem "webdrivers"
data/Gemfile.lock ADDED
@@ -0,0 +1,111 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capybara-wait_before_click (0.1.0)
5
+ capybara (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.1)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
+ ast (2.4.2)
13
+ capybara (3.38.0)
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-linux)
32
+ racc (~> 1.4)
33
+ parallel (1.22.1)
34
+ parser (3.2.0.0)
35
+ ast (~> 2.4.1)
36
+ public_suffix (5.0.1)
37
+ puma (6.0.2)
38
+ nio4r (~> 2.0)
39
+ racc (1.6.2)
40
+ rack (2.2.6)
41
+ rack-protection (3.0.5)
42
+ rack
43
+ rack-test (2.0.2)
44
+ rack (>= 1.3)
45
+ rainbow (3.1.1)
46
+ rake (13.0.6)
47
+ regexp_parser (2.6.1)
48
+ rexml (3.2.5)
49
+ rspec (3.12.0)
50
+ rspec-core (~> 3.12.0)
51
+ rspec-expectations (~> 3.12.0)
52
+ rspec-mocks (~> 3.12.0)
53
+ rspec-core (3.12.0)
54
+ rspec-support (~> 3.12.0)
55
+ rspec-expectations (3.12.2)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.12.0)
58
+ rspec-mocks (3.12.3)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.12.0)
61
+ rspec-support (3.12.0)
62
+ rubocop (1.43.0)
63
+ json (~> 2.3)
64
+ parallel (~> 1.10)
65
+ parser (>= 3.2.0.0)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ regexp_parser (>= 1.8, < 3.0)
68
+ rexml (>= 3.2.5, < 4.0)
69
+ rubocop-ast (>= 1.24.1, < 2.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (>= 2.4.0, < 3.0)
72
+ rubocop-ast (1.24.1)
73
+ parser (>= 3.1.1.0)
74
+ ruby-progressbar (1.11.0)
75
+ ruby2_keywords (0.0.5)
76
+ rubyzip (2.3.2)
77
+ selenium-webdriver (4.7.1)
78
+ rexml (~> 3.2, >= 3.2.5)
79
+ rubyzip (>= 1.2.2, < 3.0)
80
+ websocket (~> 1.0)
81
+ sinatra (3.0.5)
82
+ mustermann (~> 3.0)
83
+ rack (~> 2.2, >= 2.2.4)
84
+ rack-protection (= 3.0.5)
85
+ tilt (~> 2.0)
86
+ tilt (2.0.11)
87
+ unicode-display_width (2.4.2)
88
+ webdrivers (5.2.0)
89
+ nokogiri (~> 1.6)
90
+ rubyzip (>= 1.3.0)
91
+ selenium-webdriver (~> 4.0)
92
+ websocket (1.2.9)
93
+ xpath (3.2.0)
94
+ nokogiri (~> 1.8)
95
+
96
+ PLATFORMS
97
+ arm64-darwin-21
98
+ arm64-darwin-22
99
+ x86_64-linux
100
+
101
+ DEPENDENCIES
102
+ capybara-wait_before_click!
103
+ puma
104
+ rake (~> 13.0)
105
+ rspec (~> 3.0)
106
+ rubocop (~> 1.21)
107
+ sinatra (~> 3.0)
108
+ webdrivers
109
+
110
+ BUNDLED WITH
111
+ 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::WaitBeforeClick
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, 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_before_click --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_before_click. 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_before_click/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::WaitBeforeClick project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/willnet/capybara-wait_before_click/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_before_click/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capybara-wait_before_click"
7
+ spec.version = Capybara::WaitBeforeClick::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 before clicking"
13
+ spec.homepage = "https://github.com/willnet/capybara-wait_before_click"
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_before_click"
19
+ spec.metadata["changelog_uri"] = "https://github.com/willnet/capybara-wait_before_click/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 WaitBeforeClick
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "wait_before_click/version"
4
+ require "capybara"
5
+
6
+ module Capybara
7
+ # Wait for image to load before clicking automatically
8
+ module WaitBeforeClick
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_before_click]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_before_click]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 _logger
34
+ @_logger ||= if defined?(Rails)
35
+ Rails.logger
36
+ else
37
+ Logger.new("/dev/null")
38
+ end
39
+ end
40
+ end
41
+
42
+ module Node
43
+ class Element < Base
44
+ prepend WaitBeforeClick
45
+ end
46
+ end
47
+ 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_before_click
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - willnet
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-17 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 before clicking
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_before_click.gemspec
45
+ - lib/capybara/wait_before_click.rb
46
+ - lib/capybara/wait_before_click/version.rb
47
+ - sig/capybara/wait_before_click.rbs
48
+ homepage: https://github.com/willnet/capybara-wait_before_click
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/willnet/capybara-wait_before_click
53
+ source_code_uri: https://github.com/willnet/capybara-wait_before_click
54
+ changelog_uri: https://github.com/willnet/capybara-wait_before_click/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.3.26
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Reduce click miss in E2E tests and increases test stability
74
+ test_files: []