02 Multiple Feature - biswajitsundara/Karate GitHub Wiki

MultipleFeature.feature

Feature: Check multiple feature from response
  
  Background:
      * url 'https://reqres.in'
      * def result = call read('../basic/BasicResponse.feature')
  
    Scenario: Get call test for multiple feature
    Given path '/api/users/3'
    When method GET
    Then status=200
    Then print 'status code value =', status
    * def fname = result.response.data.first_name
    Then print 'first name value =',fname

MultipleFeatureTestRunner.java

import org.junit.runner.RunWith;
import com.intuit.karate.junit4.Karate;

@RunWith(Karate.class)
public class MultipleFeatureTestRunner {

}

Explanation

  • We can call another feature file in a feature file.
  • Refer to the background section. It's actually reading a feature file & then calling it.
  • We have written in one line however we can break
  also like this
            def feature = read('BasicResponse.feature')
            def result = call feature
  • This approach is very helpful in place of authentication token
  • So we can always call another feature file that generates authentication token
  • And use it in the current feature file/scenario.
  • For printing some text before status we can follow this approach
  • print 'status code=', status
⚠️ **GitHub.com Fallback** ⚠️