Sneha Shukla
Sneha Shukla

Reputation: 383

Can I pass values from one feature file of one folder to another feature file of another folder under /src/java/test using karate dsl

My project structure is something like this:

/src/java/test

TestRunner -> main.java
Component1 --> Admin.feature
Component2 --> Publisher.feature
Component3 --> Store.feature

I want to pass some value from Admin.feature file to Publisher.feature file. Is that possible?

I know we can pass values from one feature file to another under the same folder, but I'm unsure if the value can be used throughout my folder structure.

Upvotes: 4

Views: 915

Answers (1)

Babu Sekaran
Babu Sekaran

Reputation: 4239

Yes, as long as you are able to read() your feature file and both the features are in the same scenario.

Let's say you want to pass values from Admin to Publisher inside a Store feature.

Store.feature

Scenario:
    * def getAdmin = call read('classpath:Component1/Admin.feature') {"SomeInput":"toAdmin"}
    * def getPublisher = call read('classpath:Component2/Publisher.feature') {"Admin": "#(getAdmin.response)"}

now inside your Publisher.feature you can get the admin response details in the Admin varaible

Note: To find any file under /src/java/test directory you can prefix with classpath: as mentioned in the above example.

Lets say I have multiple scenariosinside my called feature (with tags=@scenario) and I only want to run scenario1. Is it possible to achieve that?

Upvotes: 1

Related Questions