Maven profiles with Cucumber JVM

Profiles are not available for use on the JVM in Cucumber.  Oftentimes, though, you may want to run specific scenarios based on the environment you want to test.  For instance, you may have a web application you are testing, in two separate environments.  You might also want to test those using different web drivers.

Feature: Log in to web application

Scenario:  Dev environment
Given dev URL

Scenario: Test environment
Given test URL

While we cannot achieve this behavior using the JVM alone, we can use Maven  or Gradle profiles.

For a background on Maven’s Build Profiles, see here.  For this tutorial, I used the archetype generated from Cucumber’s 10 Minute Tutorial.

Remember, our goal is to run different scenarios based on their tags using profiles, and have the ability to switch web drivers.  I added four profiles to my pom, as shown here.  One for each environment (dev and qa), and one for each web driver (chrome and firefox).

You will also need to add the maven-surefire plugin and set the value for cucumber.options.  Here is where we rely on –tags to run the specific set of tests we’re looking for.

Now, you can run tests using your desired profile(s), for instance:

$ mvn test -P qa,firefox

For this example, you will see the following:


Notice how only one of our two tests is run.  Since we are using the qa profile, only scenarios tagged with @qa are run.

To debug your configuration and check what active profiles are running, you can use the Maven Help Plugin.

For more information on how to achieve this using Gradle, see the Migrating Maven profiles and properties section of the Gradle docs.

Thank you for following along, and I hope this helps!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s