|
| Apache Maven & Failsafe |
Disclosure
Before you start reading further: The following article may contain errors, imprecisions or be out-of-date. If you have any question you don't see answered here, please leave your comment on the section below to help me improve this article.
This time I'll be picking up the previous Bootify+MySQL project used in the previous post, and add a couple of Selenium tests. I will be posting the final solution as an 'archetype' for others to use, but i recall the system where the tests are being run needs to be configured so that Firefox can be instrumented by Selenium WebDriver. It depends on what system you will be running your tests.
Add Selenium tests
So, to start off, we need to check if 'Selenium' is already available in the scope, which in my case it already is, but I'll be adding the 'dependency' explicitly on my Maven POM so that we can keep track of the Selenium version we are using:
Next we can start writing our tests, which in this case it's just a couple of 'GET' requests to ensure the titles of the page are as expected:
The key points here are that we are using 'Firefox specific' instructions for the WebDriver, such as, requesting the WebDriver to perform the operations in 'headless' mode. The test proceeds into getting the index page of the WebApp, and then get the bikeModels view. However, this is not going to work without a couple more configs in Maven.
Configuring the Firefox WebDriver environment
We need to set the following variables in the 'failsafe' test run:
- SE_SKIP_DRIVER_IN_PATH - Set this to true if you want Maven to download a new version from the web each time you test.
- TMPDIR - This will be the temp folder used by Firefox during browsing
The folder set in the TMPDIR must be created explicitly, as Firefox will not create the folder if it does not exist. We have several options for this, such as, adding an instruction on the pre-integration-test.sh script. However, and for exemplification purposes, this can also be done by Maven in a 'platform agnostic' way using Ant like so:
After all of the above, you should now be able to run your first Selenium tests using Firefox. The whole project should be run as usual using the following command:
Project sources: selenium_integration_tests.tar.gz
Happy Coding!
