jbehave-support

Lightweight extension to jbehave

License

License

MIT
GroupId

GroupId

org.jbehavesupport
ArtifactId

ArtifactId

jbehave-support
Last Version

Last Version

1.3.2
Release Date

Release Date

Type

Type

pom
Description

Description

jbehave-support
Lightweight extension to jbehave
Project URL

Project URL

https://embeditcz.github.io/jbehave-support/
Source Code Management

Source Code Management

https://github.com/EmbedITCZ/jbehave-support

Download jbehave-support

Filename Size
jbehave-support-1.3.2.pom 24 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/org.jbehavesupport/jbehave-support/ -->
<dependency>
    <groupId>org.jbehavesupport</groupId>
    <artifactId>jbehave-support</artifactId>
    <version>1.3.2</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/org.jbehavesupport/jbehave-support/
implementation 'org.jbehavesupport:jbehave-support:1.3.2'
// https://jarcasting.com/artifacts/org.jbehavesupport/jbehave-support/
implementation ("org.jbehavesupport:jbehave-support:1.3.2")
'org.jbehavesupport:jbehave-support:pom:1.3.2'
<dependency org="org.jbehavesupport" name="jbehave-support" rev="1.3.2">
  <artifact name="jbehave-support" type="pom" />
</dependency>
@Grapes(
@Grab(group='org.jbehavesupport', module='jbehave-support', version='1.3.2')
)
libraryDependencies += "org.jbehavesupport" % "jbehave-support" % "1.3.2"
[org.jbehavesupport/jbehave-support "1.3.2"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • jbehave-support-core-test
  • jbehave-support-core

Maven Central CI BrowserStack Maintainability Rating

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

  1. Modules
  2. Contributors guide
  3. Examples
  4. Best practices
  5. Known issues
  6. Simple use case
    1. Add to Java project as a Maven dependency
    2. Create a TestConfig configuration file
    3. Create a ui-mapping file
    4. Write your story
    5. Write your story class
  7. Thanks

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

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
      • test
        • java
          • your.test.code.directory

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

Jetbrains

For providing us open source licenses to IntelliJ IDEA.

Browserstack

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.

org.jbehavesupport

EmbedIT

Versions

Version
1.3.2
1.3.1
1.3.0
1.2.0
1.1.3
1.1.2
1.1.1
1.1.0
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0