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 @dev Scenario: Dev environment Given dev URL @qa Scenario: Test environment Given test URL
While we cannot achieve this behavior using the JVM alone, we can use Maven or Gradle profiles.
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).
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!