Solar Field
Solar Field

Reputation: 45

Call a karate feature, which include another call inside

I am trying to call a feature file, which is also calling another one inside. The feature I am calling is in another directory. Therefore, when I execute the scenario it is looking in the wrong place.

Here is an example:

-scenarios
--directoryA
---feature1
---feature2
--directoryB
---feature3
Feature: feature2

  Scenario: scenario2
    * url testUrl
    * def testCall = call read('feature1.feature')

    Given request { test: 'test' }
    When method post
    Then status 201
Feature: feature3

   Scenario: scenario3
   * url testUrl
   * def testCall = call read('classpath:scenarios/directoryA/feature2.feature')

   Given request { test: 'test' }
   When method post
   Then status 201

The error I get after feature 3 is executed:

feature2.feature:9 - javascript evaluation failed: read('feature1.feature'), java.io.FileNotFoundException: /Users/svetoslavlazarov/project/src/test/java/scenarios/directoryB/feature1.feature (No such file or directory)

The problem here is that call for feature1 is in wrong directory. It should look at directoryA, instead of directoryB. However, if I execute the scenario2 standalone, it is fine.

Can you help me with this? Thanks.

Upvotes: 3

Views: 1678

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58098

Try this:

* def testCall = call read('this:feature1.feature')

Upvotes: 4

Related Questions