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
- Configuring the POM.xml
- Run the Tests
- View the results
- Tips and Tricks
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
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.
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.
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.
Now go somewhere within githubSteps.java 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.
Tips and Tricks
To enable debugging set ForkCount maven surefire property within the pom.xml this can slow down testing and functionality.
<configuration> <forkCount>0</forkCount> </configuration>
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.
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
- JBehave official site
- JBehave Topics official site
- Serenity official site
- Well detailed JBehave configuration tutorial
Please let me know if you have any questions or comments and best of luck on the journeys ahead!