4

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.

Roy Scheffers
  • 3,832
  • 11
  • 31
  • 36
Sneha Shukla
  • 373
  • 1
  • 4
  • 19

1 Answers1

1

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?

Oliver Gondža
  • 3,386
  • 4
  • 29
  • 49
Babu Sekaran
  • 4,129
  • 1
  • 9
  • 20
  • This works but every time i call the other feature , it executes the feature steps again and then gives the newly generated values of the variables. What i really want is , call another feature and fetch the last saved value from that feature . Is that possible? – Sneha Shukla Nov 07 '18 at 03:55
  • @sneha If you want to run any feature only on time instead of using call use callonce, then it will not rerun and you will get the last generated value only – Babu Sekaran Nov 07 '18 at 11:08
  • * def getAdmin = callonce read('classpath:Component1/Admin.feature') {"SomeInput":"toAdmin"} – Babu Sekaran Nov 07 '18 at 11:58
  • So if I do * def getAdmin = callonce read('classpath:Component1/Admin.feature') {"SomeInput":"toAdmin"} once and then do * def getAdmin = call read('classpath:Component1/Admin.feature') {"SomeInput":"toAdmin"} at other places where i want to use it, then the second statement is going to just call the feature and take the last generated values ? – Sneha Shukla Nov 08 '18 at 03:00
  • if you want to use the value of your Admin feature in multiple scenarios inside a feature, you can keep the callonce step in the background and it will execute first time only and cache the value for rest of the scenarios – Babu Sekaran Nov 08 '18 at 03:34
  • Cool Thanks a lot – Sneha Shukla Nov 08 '18 at 03:47
  • 1
    @BabuSekaran - Is it possible to reference a feature file in another maven project directory which is within the same workspace through the use of read() ? I would like to re-use an authentication feature throughout multiple projects but would like to only write the log in feature once rather than in multiple places throughout my project. – zwanchi101 Jan 08 '20 at 10:22
  • It should work as long as that external maven project is added as a maven dependency for your current project and the file is kept in its classpath. And use read('classpath:file_name') to read that file – Babu Sekaran Jan 08 '20 at 10:26