12.4.17

Config to implement BDD using JBehave and Selenium

This post describes the steps to configure the complete environment and tools to be used to automate BDD tests using JBehave and Selenium
[This is a consolidated version of some earlier posts that deal with some of the topics here; refer other posts from this blog for more details]


OS / Software / Libraries / Version -
1. OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
i. Even though am having 64bit machine, all the software being used is 32-bit
2. Apache Maven 3.3.9
i. Maven home: C:\Program Files [x86]\Apache\Maven\apache-maven-3.3.9
3. Java 8 (32 bit) - 1.8.0_112
i. Java home: C:\Program Files (x86)\Java\jdk1.8.0_112
4. Selenium 3.3.1
5. Eclipse Java EE IDE Version: Neon
6. M2E Plugin [always update to latest version]
7. Log4J 1.2.17
8. Apache POI 3.15
9. OpenCSV 3.9
10. IE 11 - 32 Bit
     i. Though the parent IE process is 64 bit, but the actual instance is of 32 bit, hence, we need to run with the 32 bit driver for selenium
11. Firefox
12. Chrome

Steps -

1. Install the JDK, set the Environment variables
2. Install Maven
3. Download IDE - Eclipse
4. Download JBehave plugin

Installation and Update via the Eclipse Installer:

Help > Install New Software...
Add the new site location http://jbehave.org/reference/eclipse/updates/
Select JBehave Eclipse feature and follow standard Eclipse installation procedure
How to verify:
Go to file > new > other, and then select JBehave > New Story
If you can see the JBehave or 'New Story' then installation was succesfull.

5. Create your JBehave project -

Refer this link for more details - Create a Maven project for JBehave

  1. Create a folder - C:\Automation\BDD\
  2. Navigate to this folder via maven
  3. Run command - Use the latest version of JBehave. Update the value of this parameter -DarchetypeVersion=<latest ver>. This can be checked from Maven Central
mvn archetype:generate -DarchetypeGroupId=org.jbehave -DarchetypeArtifactId=jbehave-simple-archetype -DarchetypeVersion=4.6.3 -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/releases/org/jbehave/jbehave-simple-archetype/

  • groupID: com.automation
  • artifactID:bdd
  • others as default
This would download an empty project based on jbehave-simple-archetype
  4. Go to the pom dir, then run this
mvn dependency:resolve
This could download a bunch of stuff in your local .m2 dir
  5. Go to the pom dir, and then run the command
mvn eclipse:eclipse
This could download a bunch of stuff too.


6. Import this project in eclipse -

 - Go to File > Import > Maven project
You may get a few errors when you first load the project. Try the below things to resolve.
- Go to Project > Clean
This will rebuild the project
- Use Alt+F5 with 'Force update of Snapshots/Releases' checked
This could resolve most of the errors.
Sometimes we get the following error after importing the default jbehave project in eclipse

  • ERROR Description - Plugin execution not covered by lifecycle configuration: org.jbehave:jbehave-maven-plugin:4.0.5:unpack-view-resources (execution: unpack-view-resources, phase: process-resources)
  • ERROR Resource Path - pom.xml /bddproject
  • ERROR Location - line 70
  • ERROR Type - Maven Project Build Lifecycle Mapping Problem
Resolution 1 - This is a very common error, associated with M2E plugin, and usually it goes away if we update the M2E to latest version. 
Resolution 2 - Use the QuickFix action in eclipse to mark the goal to be 'ignored'
If not use this link to figure out what needs to be done - https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html
If eclipse does not throw any errors with your new jbehave project, then your project setup is successful, but your setup is far from complete!


7. External Dependencies -

At this point you can try adding/installing other software/libraries that you need for your project, as maven dependencies. Search and copy all the dependency coordinates from the Maven Central directly, nowhere else. Add these new dependencies above the 3 jbehave dependencies already present in the pom.xml

Add dependencies for the following
  • Selenium
  • Log4J
  • Apache POI

Then the run the mvn command to resolve the dependencies
mvn dependency:resolve

Then download the required style-files for the reporting via:
mvn generate-resources
This is required only once, unless you run the clean command.

The tests can be executed via:
mvn integration-test
If this step results in BUILD SUCCESS then your basic project setup is correct and complete


Additional configuration can be done as below...

8. Configure Log4J

9. Add custom configurations for JBehave


No comments:

Post a Comment