Search code examples
callkaratereadfilemultipart

Karate read (multipart field) gives error if feature file called


When I run the test scenario Initial feature file passed but the test scenario that invokes the initial scenario failed.

Error messages give reference to the initial scenario.

16:37:47.713 [main] ERROR com.intuit.karate - feature call failed: classpath:features/Initial_Scenario.feature
arg: null
Initial_Scenario.feature:67 - could not find or read file: asd.png

com.intuit.karate.exception.KarateException: -unknown-:10 - 
Initial_Scenario.feature.feature:67 - could not find or read file: asd.png

    at ✽.* def result = call read('../Initial_Scenario.feature') (-unknown-:10)
  Initial_Scenario.feature
Feature: Initial feature file

    @wip
   Scenario: Sc-1
    Given url baseUrl
    When path '/api/Start'
    And header Content-Type = 'multipart/form-data'
    And multipart file files = { read: 'asd.png' , filename: 'asd.png'}
    And method post
    Then status 200

Test_Scenario.feature

Feature: Test Scenario

  Background:
    * def result = call read('../Initial_Scenario.feature')
    * def Partner_ID = result.Partner_ID
    * def Product_ID = result.Product_ID

    @wip
    Scenario: Test
        Given url baseUrl
        When path '/api/Qwe'
        And request expectedBody
        And header X-Partner-ID = Partner_ID
        And header Authorization = 'Bearer ' + internalWriterToken
        And method post
        Then status 200

When I use the call read feature, I take care not to use the 3rd order repetition. I know this usage is not correct but I had to because multipart file feature was added to the project.


Solution

  • Note that you can use the this: prefix like this:

    And multipart file files = { read: 'this:asd.png' , filename: 'asd.png'}
    

    Which will force the lookup from the "current feature" perspective, and relative paths can also be used. I think this will solve your problem.

    Refer to the docs also: https://github.com/karatelabs/karate#path-prefixes