Bhave – Web-based BDD framework based on Play!, WebDriver/Selenium2 and Knockout.js
Written by Ed Southey
Bhave allows you to easily create ‘Acceptance Tests’ of your web-accessible application, by turning natural language constructs into WebDriver commands to drive a real browser to interact with your application.
BDD rocks. I won’t go into details on BDD specifics (Google is your friend). Selenese is all very well and good, but it still requires intimate knowledge of the syntax. Guiding the user through syntax or allowing them to create their own opens the door to a wider range of people being able to write and more importantly read the tests.
- Use the standard Play module installation command:
play install bhave 0.1
- Add the dependency to your project:
require: - play -> bhave 0.1: transitive: false
Bhave has a dependencies on Selenium and we don’t want those jars to be copied over to the application’s lib directory. That is why we specified
play dependencies --sync
In your routes file you should include the following line to allow access through to the underlying Bhave module views etc:
* / module:bhave
application.conf there are three properties that can/should be included:
Whether to fire up a local Selenium server on startup. This is useful when you are developing/debugging. If you have a Selenium Grid or external Selenium Servers, then this is unnecessary.
What port your local Selenium server should start on.
If you want to run tests in Chrome locally, then ChromeDriver (http://code.google.com/p/chromedriver/) needs to be on the path or specified here.
To persist your data, you’ll need to tell Play! to use a ‘real’ database, rather than the in-memory one by default. For performance/architectural reasons, you may want to use a MySQL/Postgres/Oracle database, see Play! documentation for configuring this easily. For testing/development purposes, a simple file-system based h2 database is fine. Change this line:
Fire up your application with:
Then simply access your application on http://localhost:9000/ (by default) and start creating tests!