Cucumber is a tool to write Behavioral Test in the process of Behavioral Driven Development.
1. Install Nodejs
It depends on your operating system, you have different ways to install Nodejs.
2. Install cucumber-js:
npm install -g cucumber
3. Install cucumber-mink
npm install -g cucumber-mink
Cucumber Mink is a cucumber-js step definition library. Most of the steps to perform actions on browser are predefined. You don't have to work with regular expressions to write popular step definitions yourself.
4 - Install phantomjs if you want to do headless testing
It depends on your operating system, you have different ways to install phantomjs.
5. Install selenium stand alone server if you want to use different browsers (Chrome, Firefox) to run cucumber tests.
6. Install Java JDK
Download what you need from here and install the JDK. It is used to run selenium standalone server.
II. Writing the tests
1. Get familiar with Gherkin syntax.
2. Create a directory to contain the test files with following structure:
[any other sub directories that contain "*.feature" files]
See this project for example: https://github.com/linhchauatl/cucumber_js
3. Test files
Test files have ".feature" extension, written in Gherkin syntax. They are stored in the subdirectories of "<top_project>/features".
You can write tests to test any web-based applications running on any ports on your localhost.
III. Running the tests
1. Start the application you want to test on designated port.
2. Start phantomjs for headless testing, or selenium for browsers testing
If you start phantomjs, you don't need to start selenium, and vice versa.
Start selenium: Go to the directory where you keep the file selenium-server-standalone-2.48.2.jar (or whatever version.jar) you downloaded at the step I.5.
java -jar selenium-server-standalone-2.48.2.jar -port 8910
3. Run the tests
Go to the directory of your test project, in this case, my directory is $HOME/projects/cucumber_js.
Run the command:
cucumber-mink -r features/
Test with firefox
cucumber-mink -r features/ --browser firefox
Test with chrome
cucumber-mink -r features/ --browser chrome
You should see some thing like this in your terminal:
Have fun testing :)