Let’s explore and learn JBehave !




I have off-late been doing a lot of BDD and have never written a single post about the same. There is so much about this on web that I really never felt to clone the information.
The reason I decided to write this post is to help all of them who have been asking me - how to join the JBehave bandwagon of testing using BDD approach?


Let’s get into the meat of what it takes to learn JBehave.
JBehave + Selenium +Java +Maven

Installations:
1.       JDK6+
a.       Download JDK/JRE Portable Zip from here http://staticchaos.freeoda.com/java/
b.      Set environment variables (system ) – JAVA_HOME e.g.: JAVA_HOME=C:\Program Files\Java\jdk1.7.0_10
c.       Add to Path variable - C:\Program Files\Java\jdk1.7.0_10 \bin\; C:\Program Files\Java \ jdk1.7.0_10\jre\bin
d.      Add to CLASSPATH a dot "."and e:\jdk7\jre\lib\ext
2.       Maven 2+
b.      Unzip the distribution archive, i.e. apache-maven-3.1.1-bin.zip to the directory you wish to install Maven 3.1.1. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.1.1 will be created from the archive.
c.       Add the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.1.1.
    1. In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.
    2. Add to Path variable -%M2% to make Maven available on command line.
    3. Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.
  1. Firefox 10+
    1. Add to Path variable -  C:\Program Files (x86)\Mozilla Firefox
IDE of my choice – Eclipse
1.       eclipse-java-juno-SR1-win32     
2.       m2e - Help > Install New Software... - http://download.eclipse.org/technology/m2e/releases

 Most common jars you might want to have a look at:
1.       jbehave-core-3.9.jar http://mvnrepository.com/artifact/com.google.guava

Pick any of these samples and Import Maven project into eclipse
a.       File Import existing maven projects - will download all maven dependencies and add to build path
b.      Maven > Update Project Configuration... on project (right click)


Execution and Reporting
Once you have the entire project all set, To run these stories
1.       In Eclipse Right-click on the Story class, select "Run as" -> "JUnit Test"
2.       To run stories from the command line:
       Navigate to the project where the pom.xml is located and type - mvn clean install
3.       To Run a single story based on story filter:
mvn clean install -DstoryFilter=storyName
4.       To run a suite based on the meta filters in the story files:
mvn clean install -Dmeta.filter="+page home"

Once all the dependencies are downloaded, you will see the execution results in one of the target folders: e.g.: target/jbehave/view
Generally report file is named: 'reports.html' and there should be a row for each story. The story reports are clickable via links on the right-most column.


Issues you might face
1.       Maven Unable to locate the Javac Compiler - m2eclipse is unable to locate C:\Program Files\Java\jre6\..\lib\tools.jar  http://stackoverflow.com/questions/10367286/m2eclipse-is-unable-to-locate-c-program-files-java-jre6-lib-tools-jar
2.       invalid LOC header (bad signature)  http://stackoverflow.com/questions/13044628/spring-error-during-build

Happy Testing!!!

Comments

Popular posts from this blog

Software Testing @ Microsoft

Trim / Remove spaces in Xpath?