Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
I started this project with the purpose of waiting for the image to appear before clicking, but I realized that it is necessary to wait for images other than clicking, such as hovering, so I will change the name to something that is not limited to clicking.
  • Loading branch information
willnet committed May 19, 2023
1 parent 4709ac4 commit 1060ffc
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AllCops:
SuggestExtensions: false
NewCops: enable
Exclude:
- "capybara-wait_before_click.gemspec"
- "capybara-wait_image.gemspec"
- 'node_modules/**/*'
- 'tmp/**/*'
- 'vendor/**/*'
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

# Specify your gem's dependencies in capybara-wait_before_click.gemspec
# Specify your gem's dependencies in capybara-wait_image.gemspec
gemspec

gem "puma"
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
PATH
remote: .
specs:
capybara-wait_before_click (0.2.1)
capybara-wait_image (0.3.0)
capybara (~> 3.0)

GEM
remote: https://rubygems.org/
specs:
addressable (2.8.1)
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
capybara (3.38.0)
capybara (3.39.1)
addressable
matrix
mini_mime (>= 0.1.3)
Expand Down Expand Up @@ -42,7 +42,7 @@ GEM
rack (2.2.6)
rack-protection (3.0.5)
rack
rack-test (2.0.2)
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
rake (13.0.6)
Expand Down Expand Up @@ -102,7 +102,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
capybara-wait_before_click!
capybara-wait_image!
puma
rake (~> 13.0)
rspec (~> 3.0)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Capybara::WaitBeforeClick
# Capybara::WaitImage

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.

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.
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.

Currently, this gem supports only RSpec, so if you want to use it for other than RSpec, please submit a pull request.

## Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add capybara-wait_before_click --group=test
$ bundle add capybara-wait_image --group=test

## Development

Expand All @@ -20,12 +20,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## Contributing

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).
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).

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Code of Conduct

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).
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).
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

require "bundler/setup"
require "capybara/wait_before_click"
require "capybara/wait_image"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# frozen_string_literal: true

require_relative "lib/capybara/wait_before_click/version"
require_relative "lib/capybara/wait_image/version"

Gem::Specification.new do |spec|
spec.name = "capybara-wait_before_click"
spec.version = Capybara::WaitBeforeClick::VERSION
spec.name = "capybara-wait_image"
spec.version = Capybara::WaitImage::VERSION
spec.authors = ["willnet"]
spec.email = ["netwillnet@gmail.com"]

spec.summary = "Reduce click miss in E2E tests and increases test stability"
spec.description = "Reduce click miss in E2E tests and increases test stability due to waiting for image to load automatically before clicking"
spec.homepage = "https://github.com/willnet/capybara-wait_before_click"
spec.description = "Reduce click miss in E2E tests and increases test stability due to waiting for image to load automatically"
spec.homepage = "https://github.com/willnet/capybara-wait_image"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.7.0"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/willnet/capybara-wait_before_click"
spec.metadata["changelog_uri"] = "https://github.com/willnet/capybara-wait_before_click/releases"
spec.metadata["source_code_uri"] = "https://github.com/willnet/capybara-wait_image"
spec.metadata["changelog_uri"] = "https://github.com/willnet/capybara-wait_image/releases"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand Down
12 changes: 6 additions & 6 deletions lib/capybara/wait_before_click.rb → lib/capybara/wait_image.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require_relative "wait_before_click/version"
require_relative "wait_image/version"
require "capybara"

module Capybara
# Wait for image to load before clicking automatically
module WaitBeforeClick
# Wait for image to load automatically
module WaitImage
def _wait_for_image_loading # rubocop:disable Metrics/MethodLength
Timeout.timeout(Capybara.default_max_wait_time) do
sleep 0.5 until evaluate_script(<<~JS)
Expand All @@ -16,11 +16,11 @@ def _wait_for_image_loading # rubocop:disable Metrics/MethodLength
JS
end
rescue Timeout::Error
_logger.debug "[capybara-wait_before_click]Timeout::Error"
_logger.debug "[capybara-wait_image]Timeout::Error"
rescue Capybara::NotSupportedByDriverError
# It comes here when you run it in rack-test, but you can ignore it
rescue ::Selenium::WebDriver::Error::StaleElementReferenceError
_logger.debug "[capybara-wait_before_click]Selenium::WebDriver::Error::StaleElementReferenceError"
_logger.debug "[capybara-wait_image]Selenium::WebDriver::Error::StaleElementReferenceError"
reload
_wait_for_image_loading
end
Expand All @@ -46,7 +46,7 @@ def _logger

module Node
class Element < Base
prepend WaitBeforeClick
prepend WaitImage
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Capybara
module WaitBeforeClick
VERSION = "0.2.1"
module WaitImage
VERSION = "0.3.0"
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Capybara::WaitBeforeClick, type: :feature do
RSpec.describe Capybara::WaitImage, type: :feature do
it "wait a image before click" do
visit "/without_images"
without_images_before = Process.clock_gettime(Process::CLOCK_MONOTONIC)
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "capybara/wait_before_click"
require "capybara/wait_image"
require "capybara/rspec"
require_relative "app"

Expand Down

0 comments on commit 1060ffc

Please sign in to comment.