makandracards.com

...a problem when using Selenium with Firefox. We recommend using ChromeDriver for your Selenium tests. Firefox will not trigger focus/blur events when its window is not focused. While this makes...

...sense in standard usage, it breaks in parallel test execution. Please do not rely on focus events in your tests. The linked card has an example of how to build...

After installing Bundler 1.1 you will get the following warning when running tests: WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being defered until env.rb is...

To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile The warning is misleading because it has nothing to do with moving cucumber-rails...

docs.ruby-lang.org

...or an argument. return # => LocalJumpError: unexpected return example { return 4 } # => LocalJumpError: unexpected return def test example { return 4 } return 'test' end test # => 4 Note how test returns the return value...

...from the block; neither code after the example invocation (returning "test") nor code after the yield inside example (putsing "done", returning "example") are executed. As you always knew, and in...

You might wonder about this request in your test.log: Started GET "/__identify__" for 127.0.0.1 at 2015-04-29 18:00:02 +0100 This is what happens: For drivers like Selenium...

...last_name = last_name end attr_reader :first_name, :last_name end To just test if an argument is a Person, you have several options: Test that the argument is...

...instance of a certain class expect(object).to receive(:foo).with(instance_of(Person)) Test that the argument responds to certain methods expect(object).to receive(:foo).with(duck_type...

...the user is certain. Solution If you need to circumvent this protection, e.g. to test that your application behaves correctly despite being misused, do this: page.execute_script 'history.back()' page.execute_script...

...already have a database.yml which defines the database for the cucumber environment instead of test. (Spreewald database.sample.yml has changed) Fix Change cucumber to test in your databse.yml test: # <--- adapter: mysql2...

...database: spreewald_test encoding: utf8 host: localhost username: root password: password

If the application under test makes sound, you probably want to disable this during integration testing. You can use the args option to pass parameters to the browser. For Chrome...

...from you Rails timezone settings / system timezone. I usually have this use case in tests. Example Time.parse('2020-08-09 00:00') will return different results e.g...

In Ruby you can communicate between processes with sockets. This might be helpful in tests that validate parallel executions or custom finalization logic after the garbage collector. Here is an...

...headless chrome via Selenium. This might be useful for debugging issues with flaky integration tests or slow page simulations. page.driver.browser.network_conditions = {offline: false, latency: 5, download_throughput: 2 * 1024, upload...

Sometimes PDF cucumber tests fail at the first test run and succeed at the second run. You can fix this with this step: When PDF generation is ready

...current .users container in the DOM: window.reloadUsers = -> $.get('/users').then (html) -> $('.users').html(html) Testing this simple function poses a number of challenges: It only works if there is a...

...The code requests /users and we want to prevent network interaction in our unit test. The AJAX call is asynchronously and we don't have control over when it returns...

...no user at the end of a web browser, e.g. on the console, during tests or during batch processes. You will often want to access Power.current from another model, to...

called as part of processing a browser request, e.g. on the console, during tests and during batch processes. In such cases your model should simply skip authorization and assume...

makandra dev

...both Gemfile as well as Gemfile.lock to the repository. Use bundle to execute your tests using the current bundled environment. Make sure you didn't break anything: bundle exec spec...

Update your scripts Most of us have some alias scripts to run all tests (e.g. ~/bin/tests). Update those scripts so they use bundle exec like this: #!/bin/sh

...a problem when using Selenium with Firefox. We recommend using ChromeDriver for your Selenium tests. This setup allows to test focus/blur events in Cucumber tests (using Selenium). For background information...

...solve Selenium focus issues. Cucumber step definition: # This step is needed because in Selenium tests, blur events are not triggered # when the browser has no focus. When /^I unfocus the...

The step definition below allows you to write: Then I should see an HTML redirect to "http://www.makandracards.com" in the...

...fast binstubs like bin/rails or bin/rspec which avoid Rails boot time. You want parallel_tests to speed up full test runs of large test suites. Unfortunately, you do not want...

...parallel_tests to use your Spring binstubs as those parallelized tests will share data and/or loose some information. There are some issues about this on GitHub and there is a...

In case your integration tests crash with a message like below, try to upgrade Capybara to a newer version (3.35.3 was good enough). You might encounter this issue when you...

Most of these will not work in newer projects because these use the Capybara/Rack::Test combo in lieu of Webrat. Find input fields Then /^there should be a "([^"]+)" field$/ do...

If you want to test that a certain text is contained within the document title of your page, you can do so using Selenium and a step such as

...Selenium note, I found yet another solution for the problem to hide your selenium tests away. This has the advantages ^ not to require a gem (so you do not force...

...at the running webdriver if necessary Simply make a script that runs your cucumber tests and runs this before: vncserver :6 -localhost -nolisten tcp -SecurityTypes None &>/dev/null DISPLAY=":6"

makandra dev
github.com

...for the first time (bundle install, create database.yml, create databases, migrate), optionally run all tests (--test) or load a dump (--dump staging) update: update a Rails project that has been...

...open a shell on a Capistrano target, optionally selecting the server with --select-server tests: run all employed tests; checks for: Cucumber, RSpec, Test::Unit and rake with-firefox-for...

...same regardless of the driver Capybara is using (drivers are e.g. the headless Rack::Test or Selenium). It is a stupid idea to call #node on such a Capybara node...

...used by the driver, e.g. instances Nokogiri::XML::Element if you are using Rack::Test, or of Selenium::WebDriver::Element if you are using Selenium. Because the API of these...