Reputation: 47
karate api testing - How to read tag names from command line to feature file
My feature file
Feature: validating tag name reading from maven command line
Background:
Given url baseURL
When param validation = I want to read tagname here
Then method get
Then status 200
@com_status @all @I want to read tagname here
Scenario Outline: Testing tag input scenarios
Command - mvn clean test -Dtest=Runner -DargLine="-Dkarate.env=dev" -Dcucumber.options="--tags @com_status"
Upvotes: 1
Views: 3680
Reputation: 58058
You cannot. Tags are designed to be passed on the command line to filter scenarios to run - and cannot be retrieved within a test. You can retrieve the tag of a Scenario
though: https://github.com/intuit/karate#karate-tags
You can try using karate.properties
or something similar to retrieve what was passed on the command-line: https://github.com/intuit/karate#dynamic-port-numbers
Command:
mvn clean test -DcustomName=foo
Feature:
* def customName = karate.properties['customName']
Feel free to contribute this feature if you think it is important.
EDIT - update in 1.1.0 onwards, there is a new feature "Exvironment Tags" that may solve what is being asked for here: https://github.com/intuit/karate#environment-tags
Also see: https://stackoverflow.com/a/50693388/143475
Also for advanced filtering using tag values when the tag is in the form @name=value1,value2
, refer: https://stackoverflow.com/a/67219165/143475
Upvotes: 0
Reputation: 119
Below is the command to execute the tag from the command line in Karate Api automation testing.
mvn test -DargLine="-Dkarate.env=e2e" "-Dkarate.options=--tags @user_management_get_vender_types"
Upvotes: 1