Capybara drivers will usually delete all cookies after each scenario. If you need to lose cookie data in the middle...
TLDR: In tests you need to clean out the database before each example. Use :transaction where possible. Use :deletion for Selenium features or when you have a lot of MyISAM...
Understanding database cleaning You want to clean out your test database after each test, so the next test can start from a blank database. To do so you have...
I needed to make sure that an element is visible and not overshadowed by an element that has a higher...
...jQueryUI's Sortable plugin (either directly or via Angular's ui.sortable), you might struggle testing your nice drag&drop GUI since Selenium webdriver does not support native dragging events.
...jQueryUI uses jquery.simulate for their testing, so why shouldn't you? There is even an extension to it that makes testing drag & drop quite easy. Here is what you need...
...don't provide canditional validations (validations with if: option). Here is how to write tests for the condition: Class: class Employee < ActiveRecored::Base validates :office, presence: true, if: manager?
... end end Test: describe Employee do describe '#office' do context 'is a manager' do before { allow(subject).to receive(:manager?).and_return(true) } it { is_expected.to validate_presence_of(:office...
Plugins (and gems) are typically tested using a complete sample rails application that lives in the spec folder of the plugin. If your gem is supposed to work with multiple...
...this instead of the spec_helper: --require rails_helper If you are using parallel_tests and this is not working for you, .rspec might be ignored. Try using a .rspec...
...start playing video or audio. E.g. if you attempt to call video.play() in a test, the call will reject with a message like this: NotAllowedError: play() failed because the user...
...with the document first. https://goo.gl/xX8pDD Workaround To pretend document interaction in a test you can create an element, click on it, and remove the element again. This unblocks...
...the print stylesheet. This card describes how to write a simple Cucumber feature that tests some aspects of a print stylesheets. This way, the requirement of having a print stylesheet...
...is manifested in your tests and cannot be inadvertedly removed from the code. Note that you can always use your DevTools to preview the print styles in your browser.
The ActionDispatch module of Rails gives you the helper method flash to access the flash messages in a response.
...when it was called during browser interaction in development but doesn't make the test fail. The reason Development autoloading isn't smart enough to find the referenced class
...other environments (test, staging, production) autoloading is disabled, that all classes are already loaded when browser interaction takes place what makes rails able to find the class even without the...
When testing code that uses pushState / replaceState, your browser will appear to navigate away from http://localhost:3000/specs (or wherever you run your Jasmine tests). This is inconvenient, since reloading...
...the document will no longer re-run the test suite. To remedy this, copy the attached file to a place like spec/javascripts/helpers and #= require it from your tests. It will...
...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...
...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...
...ETags can again match. Before I make this change I like to add a test that ensures I did it correctly. For this add the following code to spec/requests/default_etag_spec.rb. You...
...ActionView::Base).to receive(:image_path).and_return('image') # CSRF protection is disabled in tests by default. Activate it for this spec as # randomly masked CSRF tokens are a major...
...you need additional form fields (like tax IDs) to bill customers in another language. Tests Tests should continue to use the base language you had before starting localization. Don't...
...rewrite all tests and don't test every screens with every language unless repeatedly broken translations becomes a pain point. Do test non-trivial language-specific customizations like the parsing...
...by CSS, the following will work with Selenium, but not when using the Rack::Test driver. The Selenium driver correctly only considers text that is actually visible to a user...
...Then I should not see "foobear" This is because the Rack::Test driver does not know if an element is visible, and only looks at the DOM. Spreewald offers steps...
...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
...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...
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...
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