bdd web application testing framework

Setup BDD-test-projects for web applications fast and easy

License

License

GroupId

GroupId

de.telekom.test
ArtifactId

ArtifactId

bdd-web-app
Last Version

Last Version

1.9
Release Date

Release Date

Type

Type

jar
Description

Description

bdd web application testing framework
Setup BDD-test-projects for web applications fast and easy
Project URL

Project URL

https://github.com/telekom/bdd-web-app
Source Code Management

Source Code Management

http://github.com/telekom/bdd-web-app

Download bdd-web-app

How to add to project

<!-- https://jarcasting.com/artifacts/de.telekom.test/bdd-web-app/ -->
<dependency>
    <groupId>de.telekom.test</groupId>
    <artifactId>bdd-web-app</artifactId>
    <version>1.9</version>
</dependency>
// https://jarcasting.com/artifacts/de.telekom.test/bdd-web-app/
implementation 'de.telekom.test:bdd-web-app:1.9'
// https://jarcasting.com/artifacts/de.telekom.test/bdd-web-app/
implementation ("de.telekom.test:bdd-web-app:1.9")
'de.telekom.test:bdd-web-app:jar:1.9'
<dependency org="de.telekom.test" name="bdd-web-app" rev="1.9">
  <artifact name="bdd-web-app" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.telekom.test', module='bdd-web-app', version='1.9')
)
libraryDependencies += "de.telekom.test" % "bdd-web-app" % "1.9"
[de.telekom.test/bdd-web-app "1.9"]

Dependencies

compile (16)

Group / Artifact Type Version
org.springframework : spring-context jar 5.1.20.RELEASE
org.jbehave : jbehave-core jar 4.8.3
org.jbehave : jbehave-maven-plugin jar 4.8.3
org.jbehave : jbehave-core zip 4.8.3
org.jbehave.site : jbehave-site-resources zip 3.4.1
com.github.valfirst : jbehave-junit-runner jar 2.3.0
org.seleniumhq.selenium : selenium-java jar 3.141.59
io.github.bonigarcia : webdrivermanager jar 4.4.0
org.seleniumhq.selenium : htmlunit-driver jar 2.49.1
net.sourceforge.htmlunit : htmlunit jar 2.49.1
ch.qos.logback : logback-classic jar 1.2.3
io.rest-assured : rest-assured jar 4.3.3
org.apache.commons : commons-lang3 jar 3.12.0
org.projectlombok : lombok jar 1.18.20
cglib : cglib jar 3.3.0
com.google.guava : guava jar 30.1.1-jre

test (3)

Group / Artifact Type Version
org.spockframework : spock-core jar 2.0-M5-groovy-3.0
net.bytebuddy : byte-buddy jar 1.11.0
org.objenesis : objenesis jar 3.2

Project Modules

There are no modules declared in this project.

bdd-web-app

This JBehave extension make automated acceptance tests for web applications much easier! It integrates Selenium for frontend testing and REST-assured for interface testing into a common test data lifecycle. The included sample project allows a quick introduction to the test framework.

Features

  • JBehave classes like stories or steps are automatic loaded by using annotations.
  • Access Selenium and REST-Assured in Spring context for uniform access.
  • Enhanced test data management for web applications integrated into the JBehave lifecycle, so can easily use dynamic test data.
  • Integration of WebDriver-manager for automatic WebDriver updates.
  • Optional extension of Selenium-Web-Element with convenient functions and the possibility to add own extensions.
  • Creation of screenshots in case of errors and if desired after each step.

Example project

At the bdd-web-app-demo folder you will find the example web-application, including the test-project using bdd-web-app. Here you will find an complete example of bdd-web-app integration.

The next sections will describe the integration of the test framework in general.

Maven Integration

Add this dependency to your test project. The dependency includes JBehave, Spring, Selenium, Webdrivermanager and other components for frontend testing:

            <dependency>
                <groupId>de.telekom.test</groupId>
                <artifactId>bdd-web-app</artifactId>
                <version>1.9</version>
            </dependency>

BDD-Web-App is also available for other build-automation-tools like gradle. You will find the artefacts here: https://search.maven.org/artifact/de.telekom.test/bdd-web-app/1.9/jar.

Configuration

You need four java classes for configuration.

First add the spring configuration. Note that the component scan at bdd-web-app package "de.telekom.jbehave.webapp" is needed.

@Configuration
@ComponentScan({"de.telekom.test.bddwebapp", "your.package.structure"})
public class TestConfig {
}

At the second step, you need a bridge between jbehave and spring. Add an application context provider for this reason:

public class ApplicationContextProvider {
    private static final ApplicationContext applicationContext = createApplicationContext();
    
    private static AnnotationConfigApplicationContext createApplicationContext() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(TestConfig.class);
        applicationContext.refresh();
        return applicationContext;
    }
    
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}

Now you can use the application context for story execution. Therefore, extend the AbstractStory class from the test-framework. Note that the story name has to be the same like your story class:

public abstract class YourStory extends AbstractStory {
    @Override
    public ApplicationContext getApplicationContext() {
        return ApplicationContextProvider.getApplicationContext();
    }
}
    

If you want to run all stories, add a class to your configuration that extend the RunAllStories class from the test-framework:

public class RunAllMyStories extends RunAllStories {
    @Override
    public ApplicationContext getApplicationContext() {
        return ApplicationContextProvider.getApplicationContext();
    }
}

You can run this class as a JUnit class. If you want to integrate the test execution into your maven-lifecycle, then add this to your pom.xml:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <includes>
                        <include>**/RunAllMyStories.java</include>
                    </includes>
                </configuration>
            </plugin>

Build your first test

To build your first test you need a story class with the application context (described at configuration). The class name must be the same like your jbehave story file. Put the story file to the resources and use the same package structure like the class.

Then build a steps class with your jbehave test steps. Use the @Steps annotation so that the bdd-web-app framework will find the class. If you want to use the class for selenium tests, you can extend the SeleniumSteps class from the test-framework:

@Steps
public class YourSteps extends SeleniumSteps {
    @When("run step")
    public void runStep(){}
}

Map your web pages to page classes so that you can access these. Therefore, you can extend the Page class from the framework. If you use jquery you can use the JQueryPage.

public class YourPage extends Page {
    @Override
    public String getURL() {
        return "relative/url";
    }
    @FindBy(id = "username")
    private WebElementEnhanced usernameInput;
}

Now you can access your page object with the createExpectedPage method from SeleniumSteps. The URL will be checked at page creation. If the url in the page class no contain in the current URL, an exception will throw. You can also use regular expressions at the page URL. After the page object is created, you can use it directly or from the StoryInteraction by using the getCurrentPage method (recommended). If you use the page by the getCurrentPage method, then you can access it from every step object. Note that if you call the createExpectedPage method, an new current page will be set.

@Steps
public class YourSteps extends SeleniumSteps {
    @When("open page")
    public void openPage(){
        open("yourUrl.com/yourPage");
    }
    @Then("page is open")
    public void openPage(){
        createExpectedPage(YourPage.class);
    }
    @Then("page shows user name $userName")
    public void pageShowsUserName(String userName){
        LoginPage loginPage = getCurrentPage();
        assertTrue(loginPage.userNameIsShown(userName));   
    }
}

After you wrote your steps class, you can use it at your story. Note that your story file must be the same name as your story class for execution.

When open page
Then page is open
And page shows user name hans

Run your story and look at the test report. If you miss the report styling call the "mvn site" command on your test project.

Additional information

You will find additional information to the test framework in the wiki: https://github.com/telekom/bdd-web-app/wiki.

In the wiki is described:

  • What are the general system requirements
  • How you can configure the test run on different browsers, update browser driver behind a proxy and activate screenshot after successful step.
  • Run the same stories on different staging environments like almost simulated, almost real systems or fully integrative.
  • How to customize your test project for special needs.
de.telekom.test

Telekom Open Source Software

published by Deutsche Telekom AG and partner companies

Versions

Version
1.9
1.8.1
1.8
1.7.1
1.7
1.6
1.5
1.4
1.3
1.2