-
Notifications
You must be signed in to change notification settings - Fork 0
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
Introduction of system tests in Capybara #357
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Defaults profile_examples to 10 examples [1] > when @profile_examples is true. This value determines the number of the slowest tests displayed. [1]: https://rspec.info/documentation/3.1/rspec-core/RSpec/Core/Configuration.html#profile_examples-instance_method
We want to create high-level tests in Selenium [1] [2] using Capybara. [3] To make using Selenium easier, it is worth installing webdrivers. [4] > Run Selenium tests more easily with automatic installation > and updates for all supported webdrivers. However, recently there have been major changes, which we can read about in the webdrivers documentation. > With Google's new Chrome for Testing project, [5] > and Selenium's new Selenium Manager feature, > what is required of this gem has changed. > > If you can update to the latest version of Selenium (4.11+), > please do so and stop requiring this gem. > Provide feedback or raise issues to Selenium Project My further research led me to an article published by Evil Martians. [6] This in turn led me to Cuprite [7] [8] and related gems like Vessel [9] and Ferrum. [10] > Cuprite is a pure Ruby driver > (read as no Selenium/WebDriver/ChromeDriver dependency) > for Capybara. > Vessel - high-level web crawling framework > It is Ruby high-level web crawling framework > based on Ferrum for extracting the data you need from websites. > Ferrum - high-level API to control Chrome in Ruby > It is Ruby clean and high-level API to Chrome. > Runs headless by default, > but you can configure it to run in a headful mode. > Ferrum connects to the browser by CDP protocol > and there's no Selenium/WebDriver/ChromeDriver dependency. [1]: https://www.selenium.dev/ [2]: https://github.com/SeleniumHQ/selenium [3]: https://github.com/teamcapybara/capybara [4]: https://github.com/titusfortner/webdrivers [5]: https://developer.chrome.com/blog/chrome-for-testing/ [6]: https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing [7]: https://github.com/rubycdp/cuprite [8]: https://cuprite.rubycdp.com/ [9]: https://github.com/rubycdp/vessel [10]: https://github.com/rubycdp/ferrum
Based on the article I found earlier, [1] I prepared a configuration for Capybara and Cuprite. The `system_helper.rb` file contain general RSpec configuration for system tests. The `capybara_setup.rb` contains configuration for Capybara framework. The `cuprite_setup.rb` is responsible for configuring Cuprite. The `precompile_assets.rb` file is responsible for precompiling assets before running system tests. > Why precompile assets manually if Rails can do that automatically? > The problem is that Rails precompiles assets lazily > (i.e., the first time you request an asset), > and this could make the first test example run much slower > and even encounter random timeout exceptions. Generally, I didn't want to go exactly in the direction presented by Evil Martians. My goal was to simplify their setup. [1]: https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing
Recently, an error occurred that our seeds were not compatible with the database structure. We want to avoid this in the future, so I created a simple integration test.
We want our test to monitor what versions of the JavaScript libraries we are using.
After adding the tests in Capybara, our Rubocop informed us: > The following RuboCop extension libraries are installed > but not loaded in config: > * rubocop-capybara So I added this extension to our Rubocop configuration.
torrocus
force-pushed
the
al-minor-improvements-in-tests
branch
from
October 5, 2023 09:59
cd2c516
to
f04ff58
Compare
torrocus
changed the title
Minor improvements in tests
Introduce system tests in Capybara
Oct 5, 2023
torrocus
changed the title
Introduce system tests in Capybara
Introduction of system tests in Capybara
Oct 5, 2023
ania-hm
approved these changes
Oct 5, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Summary
I have set up system tests. We can use Capybara to describe our test cases and Cuprite as the Headless Chrome driver.
I added two sample tests. The first one that tests whether our seeds are loading correctly. And the second one, which checks whether the JavaScript libraries are loaded correctly.
Feedback
Our tests are a little slower now, but this is acceptable.
The approach of using Cuprite which using Ferrum under the hood is made possible by the popularization of CDP protocol.
UI Changes
N/A