Execution Arguments

The main execution arguments are the following:

The commands provided in this section are based on command line execution to ensure that we will have the same behaviour when executing in the scope of CI/CD. You can also use your favorite IDE for test development, execution, debugging, …​.

Karate Env

default karate.env = local
  • Execute all tests with default environment (local)

    mvn clean test
  • Execute all tests on a specified environment using karate.env

    mvn clean test -Dkarate.env=local
    mvn clean test -Dkarate.env=pre
    mvn clean test -Dkarate.env=pre_zero

In order to filter the tests per environment use the karate environment tags.

These are two special tags (@env and @envnot) that allow you to "select" or "un-select" a Scenario depending on the value of the karate.env.

For example:

  • @env=local,pre,pre_zero: the scenario will be executed only when the value of karate.env is equal to local on pre or pre_zero.

  • @envnot=local: the scenario will be executed only when the value of karate.env is anything other than local.

Karate Options

Karate Options - Classpath

  • Execute tests on a specified classpath folder using karate.options classpath:

    mvn clean test -Dkarate.options="classpath:com/.../xxx-api-rest-stable/functional"

    The execution will include all the tests in the contained feature files in the folder and subfolders

  • Execute tests on a specified classpath file using karate.options classpath:

    mvn clean test -Dkarate.options="classpath:com/.../xxx-api-rest-stable/functional/e2e/e2e.feature"

    The execution will include only the tests in the specified feature file

The classpath filter should be at the end of the karate.options

Karate Options - Tags

  • Execute tests with specific tags using karate.options -t or --tags

    mvn clean test -Dkarate.options="-t ..."
    mvn clean test -Dkarate.options="--tags ..."

Karate Tests support combinations of TAGS.

  • AND: Features with both @TAG1 and @TAG2 but not @TAG3.

    -Dkarate.options="-t @TAG1 -t @TAG2 -t ~@TAG3".

    For example:

    • Smoke Tests for a single operation

      mvn clean test -Dkarate.options="-t @smoke -t @op.showItemById"
    • Functional Tests for a single operation

      mvn clean test -Dkarate.options="-t @functional -t @op.showItemById"
  • OR: Features with either @TAG1 or @TAG2

    -Dkarate.options="-t @TAG1,@TAG2".

    For example:

    • All Tests for two operations

      mvn clean test -Dkarate.options="-t @op.showItemById,@op.listItems"
  • AND and OR Combination: Features with either @TAG1 or @TAG2 and @TAG3 but not @TAG4

    -Dkarate.options="-t @TAG1,@TAG2 -t @TAG3 -t ~@TAG4".

    For example:

    • Smoke Tests for two operations

      mvn clean test -Dkarate.options="-t @smoke -t @op.showItemById,@op.listItems"
    • Functional Tests for two operations

      mvn clean test -Dkarate.options="-t @functional -t @op.showItemById,@op.listItems"

Karate Options - Tags & Classpath

Karate tags and classpath can be combined.

For example:

  • Execute tests on a specified classpath folder with a specific tag

    mvn clean test -Dkarate.options="-t @op.showItemById classpath:com/mypackage/api/xxx-api-rest-stable/functional"
    The classpath filter should be at the end of the karate.options

Karate Options - Number of Threads

  • Execute tests with a specified number of threads using karate.options --threads

    mvn clean test -Dkarate.options="... --threads XX ..."
    default number of threads = 1, the custom number of threads is capped up to number of cores / 2