gfk-ba / senbot

Cucumber / Selenium framework in Java
MIT License
10 stars 11 forks source link

Senbot

Java based Cucumber and Selenium framework.

Goals

Our goal is to make it easy to create, run and report on automated tests for webbased applications (by using behavior driven development).

Features

Prerequisites

To run the framework tests you minimal need:

Getting started

If you want to get started with SenBot use our Demo Archetype to create a new SenBot project showcasing the SenBot possibilities. First create your project using:

mvn archetype:generate -DarchetypeGroupId=com.gfk.senbot -DarchetypeArtifactId=SenBotDemo-archetype -DgroupId=com.yourdomain.namespace -DartifactId=YourProjectName

This will result in a new folder in your current directory called 'YourProjectName', cd into it and call mvn clean install. This will start the maven build cycle which will also run all included cucumber tests utilizing Selenium.

Build from sources

After the prerequisites are installed clone the repository git clone git@github.com:gfk-ba/senbot.git
Run a mvn clean install in the cloned directory
This will build the senbot and fire the its own test run containg many examples.

Configuration

You can configure by means of properties files and runtime variables. The properties files can be contributed as part of your project but can also be configured outside of the project on your local system to allow for flexible development setups.

It is also possible to overwrite reference data values by providing property values in your properties file. So let's say you have used an implementation of ReferenceServicePopulator to register a GenericUser to the SenBotReferenceService.addUser("loginUser1", new GenericUser(...values...)) method. By providing the property GenericUser.loginUser1.userName=anotherUserName, you will overwrite the default value during execution allowing for execution specific data configurations. This setup applies to all POJO's contributed to the reference service.

Runtime arguments

SenBot uses Maven as a build, dependency and test execution tool. Both for building SenBot itself as for running projects using SenBot maven is used. You can configure SenBot by means of runtime arguments. The following options are available:

-Dfeatures

This is a shorthand for the -Dcucumber.options and can be used as such. Provide the path to the folder file from which to read the fature files from. mvn test -Dfeatures=path/to/folder/file.feature. It is also possible to specify you wish to run scenario's with specific tags defined mvn test -Dfeatures="path/to/folder --tags @mytag". You can even isolate a single scenario by name like so: mvn test -Dfeatures="path/to/folder -n='name of scenario'"

-Dtest

Maven uses the surefire plugin to run JUnit tests which in turn will fireup the cucumber tests. If you use multiple JUnit runners to run your tests you can choose to run just one of them by passing in the -Dtest parameter with the fully qualified name of the JUnit class. mvn test -Dtest=com.domain.NameOfYourJUnitTest

-Denv

Changing the default test environment (read:browser) can be done with -Denv. mvn test -Denv=FF will run the tests against FireFox where mvn test -Denv=CH;IE,IE7,XP will run the tests against any Chrome version on any Operating System and run them against IE7 on Windows XP. Available options: FF, CH, IE, SF and phantomjs (for a headless browser).

-Durl

Senbot allows you to define a default url to use. If not specified http://localhost:8080 is used. If this needs to be different use mvn clean install -Durl=http://www.domain.com/context/path/.

-DopenReport

If you want the senbot report to open automaticaly at the end of your run use: mvn clean install -DopenReport

Running cucumber selenium tests in parallel

SenBot supports running cucumber selenium tests in parallel. If you use the ParameterizedCucumber class as shown in the example test ParameterizedCucumberTestBaseTest the feature files will be devided over multiple threads. By default 5 threads will be used but this can be overwritten by using the -Dthreads=n commandline argument.

Logging options

SenBot uses slf4j configured though log4j for its logging. This allows you to overwrite how senbot logs its messages in your projects using SenBot. The default SenBot logger is configured to log to PROJECT_ROOT/target/logs/senbot.log as specified in the log4j.xml file. If you need to add log messages to your own StepDefinitions you can do so by adding a logger like so (example taken from the SenBotContext):

private static Logger log = LoggerFactory.getLogger(SenBotContext.class);

In your code you can then log your messages by calling:

log.trace("Trace message");
log.debug("Debug message");
log.info("Info message");
log.warn("Warn message");
log.error("Error message");