JBehave and Selenium Testing with IntelliJ IDEA example

For the last couple of weeks I’ve been doing QA testing using Serenity, Selenium, and JBehave. I’ve been writing tests and configuring a framework to test our websites and I’m more and more convinced about the power of JBehave. You can find my learning Github repo at JBehave social example. Also for the most part I recommend using Idea IntelliJ.

Getting started

One of the benefits of using Java is the ease of getting everything ready…. when everything works. I went through dozens of examples and tutorials online and very few had a comprehensive package available. A package that does testing on various websites, uses Selenium, Serenity, and JBehave properly with @FindBy examples.

Let’s start by opening up IntelliJ and cloning the JBehave Social Example repo. When asked “Yes” we would like to open it.

Configuring the POM.xml

The example connects to Github, Twitter, and Google for testing purposes and for fun sends a tweet and stars the Git repo. If you don’t want the full experience you don’t need to provide credentials.
Open up the pom.xml
open up the pom.xml
Between the properties tags replace the TestUser with the desired credentials. These credentials are then passed into the Selenium to insert further down in the systemPropertyVariable which is read in the individual tests.

Run the Tests

If you are using IntelliJ IDEA you should see the configuration profiles already populated.
configuration profiles
But we can also run the tests using the terminal as long as Maven is installed.

% mvn clean test 

Runs the tests generates output files.

% mvn clean test serenity:aggregate

Runs the tests, generates output files, and combines them. This second one will be the most important command becuase of the generated reports.

View the results

Once you run the aggregation then the results of the tests will be available in the target/site/serenity/index.html file. Just navigate and open it up to browse through the results of the tests. There’s plenty of information about the tests that ran, duration, status, dependencies, and even screenshots.

Debugging …..

There are a couple of things important to debugging tests. The ability to run a single story and correct configuration.

So how do we run a single story?

Create a class with the same name as the story you are trying to run just camelcased. So if you are trying to run click_on_something.story the class will be ClickOnSomething it also needs to be located in the parent folder where the main Test Java class is located.

Single test class
Now go somewhere within githubSteps.java and set a breakpoint.
Go somewhere along the way and set a breakpoint

We also have to configure maven to wait and stop it from forking? I’m not sure what the script does actually, just copy and paste into the terminal!

export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787 -Xnoagent -Djava.compiler=NONE"

Now we can select the SingleStory configuration we created earlier and click the debug mode.
select debug mode
actually executing the debugger

Tips and Tricks


To enable debugging set ForkCount maven surefire property within the pom.xml this can slow down testing and functionality.


Multiple Test Suites

In one of our projects we have multiple packages and testsuites. To aggregate all of the reports, create a serenity.properties file and set serenity.outputDirectory to some folder serenity_reports. Then in each of the test suites insert a serenity.properties and serenity.outputDirectory to the ../serenity_reports. This way all of the output will be inserted into a single folder and during the aggregation step everything will be found.

Meta Filtering

In the configuration manager we can add a metafilter property. This will either be a + or – depending on whether to exclude or include the property.

Some other links


Please let me know if you have any questions or comments and best of luck on the journeys ahead!


One thought on “JBehave and Selenium Testing with IntelliJ IDEA example”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s