jbehave-support
Light extension to JBehave using Spring framework.
Provides several base steps for working with REST, SOAP, JMS, SQL, SSH, (Selenium based) web testing, health checks along with support for verification, expression commands and basic reporting.
Currently supported Java versions are 8, 11 (latest LTS) and 16 (latest version).
Java 16 support is limited due to JEP 396 and incompatibilities in some of our dependencies. When running on Java 16 please use --add-opens java.base/java.lang=ALL-UNNAMED
or --illegal-access=permit
to bypass the newly introduced restrictions in the meantime.
Contents
Modules
- core - details about integration and usage
- core-test - contains details about the simple application used for integration tests
Contributors guide
Contributors guide can be found in CONTRIBUTING.md
Examples
- examples - more example projects like the simple use case shown below.
Best practices
Known issues
Simple use case - Web testing
To show you how to set up a project using the jbehave-support library, I am going to make a test that Google searches EmbedITCZ jbehave-support
and checks the result. To learn more about this example check out Web-testing.md.
Of course you can use jbehave-support for much more than just selenium based testing. For example server communication (SOAP, REST, JMS) or database manipulation (SQL).
Add to Java project as a Maven dependency
To add jbehave-support to a java project, just add this dependency to your pom.xml.
<dependency>
<groupId>org.jbehavesupport</groupId>
<artifactId>jbehave-support-core</artifactId>
<version>[current version number]</version>
</dependency>
Then build your project (mvn clean install
) to download all the necessary dependencies.
Also, make sure to have the test resources setup correctly, simple setup to use can be like this:
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**/*.story</include>
<include>**/*.table</include>
</includes>
</testResource>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build>
Create a TestConfig configuration file
From this file, jbehave-support will take all the necessary information about tested applications and the types of reports you want. First create a Java class and call it TestConfig
. Add the spring annotation @Configuration
.
@Configuration
public class TestConfig {
Setting up the application you want to test largely depends on what do you want to test. Generally, you need to add a Spring bean method setting up the necessary parameters. We will be setting-up a WebSetting for Selenium to access google.com. (More about setting up web testing)
@Bean
@Qualifier("GOOGLE")
public WebSetting google() {
return WebSetting.builder()
.homePageUrl("https://www.google.com")
.elementLocatorsSource("home.yaml")
.build();
}
The @Qualifier
annotation sets up the name, under which we will be able to access this application in our story
.
The homePageUrl
method sets the url of the web applications home page.
The elementLocatorsSource
methods sets the name of a file containing addresses of web page elements we want to interact with.
Create a ui mapping file
In this yaml file, we need to setup the links to web page elements we want to interact with. It has to be placed in the resources directory, which is on one level above your main code directory:
- Project
- src
- main
- java
- your.main.code.directory
- resources
- home.yaml
- java
- test
- java
- your.test.code.directory
- java
- main
- src
At this point, your.main.code.directory
should contain the TestConfig class created previously.
Note also the location of your.test.code.directory
— this is where your story files will go later.
The links and names should be written like this:
home:
search.button.css: "#tsf > div:nth-child(2) > div > div.FPdoLc > center > input[type='submit']:nth-child(1)"
search.text.css: "input[type='text'][name='q']"
search.output.css: "#rso > div:nth-child(1) > div > div.r > a > h3"
The title home:
is the name of the page these elements can be found on.
Under the names search.button
, search.text
and search.output
, we can use these elements in a story.
The .css
extension tells the code, what type of address to look for. (Ex. .xpath
)
The part after the colon is the address of the element itself.
More about ui mapping files
Write your story
In your your.test.code.directory
directory create a .story
file. I will call it Google.story
.
(Optional) Inside, write the narrative, which should explain the purpose of this story. It has 3 mandatory parts: In order to
, As a
and I want to
.
Narrative:
In order to try jbehave-support
As a confused human
I want to see if I can set it up
Then write your scenario:
Scenario: Open Google
Given [GOOGLE] homepage is open
When on [home] page these actions are performed:
| element | action | data |
| search.text | FILL | embeditcz jbehave-support |
| search.button | CLICK | |
Then on [home] page these conditions are verified:
| element | property | data | verifier |
| search.output | TEXT | EmbedIT | CONTAINS |
This scenario opens www.google.com
, writes embeditcz jbehave-support
into the Google search bar. Clicks search
and checks if the first result contains the text EmbedIT
. Notice instead of lengthy element addresses, the element names defined in home.yaml
are used.
More about web testing steps for your story
Write your story class
In the same directory as your .story
file, create a Java class that extends AbstractSpringStories
and call it <yourStoryName>Story
(naming is important). Add the annotation @ContextConfiguration(classes = TestConfig.class)
to link it with your TextConfig class. Leave this class empty.
@ContextConfiguration(classes = TestConfig.class)
public class GoogleStory extends AbstractSpringStories {
}
This class is runnable. When you run it, it runs your story.
Thanks
For providing us open source licenses to IntelliJ IDEA.
for providing us with a free license for our project. We use BrowserStack in our build pipeline to make sure that our selenium based testing components are working correctly across multiple browsers.