How to provoke Selenium focus issues in parallel test processes
As attachments to this card you will find a Cucumber feature and supplementing step definition that you can use to provoke Selenium focus issues that only occur when two focus-sensitive Selenium scenarios run at the same time (probably with parallel_tests). This can help you to detect and fix flickering integration tests.
The attached feature works by going to your
root_path and focusing a random form element every 5ms.
- Copy the attached feature and step definition into your project.
- If required, adjust the duration for which concurrency issues are provoked by editing
focus_issues.feature(you'll see). Default is 5 minutes. It should be longer than your flickering tests take to run.
- Make sure that your
root_pathcontains a form element (select, input) or edit the step definition to visit another path.
- Comment out non-flickering scenarios in your feature that contains flickering tests. The problematic feature should ideally only contain flickering Selenium-scenarios.
- Run the feature together with the feature that contains flickering tests, e.g. with Geordi:
cuc features/focus_issues.feature features/flickering_tests.feature
- Be careful not to use a line number in the call. Tests will not run in parallel when a line number is used.
- Observe how each test process now spawns a separate Firefox window (if you are using Geordi support for headless Selenium with VNC you need to call
cuc-showto see the Firefoxes). Make sure that the window opened by
focus_issues.featurestays on top (this will be the window showing your
root_pathwith randomly focused input elements).
- Wait until your flickering tests fail. You might need to run tests for a few times until this happens, because there are still external factors involved in the timing.
- Cucumber will seem to hang until
focus_issues.featurehas finished its duration. You can CTRL+C out of that.
You can now fix your focus-sensitive tests.