1

I have test data based on environments. Need to use respecitive environment test data for webservice testing in karate framework. So I have config file which load variable based on environment. I have edited my feature file as runtime variable to get the path accordingly something like below. It looks I am missing something or might not using right way.

I have kept testdata based on environment in my folders as like below

TestData
  |->DEV
      |-> applicationFeature_scenorio1_Req.json
  |->SIT
      |-> applicationFeature_scenorio1_Req.json
  |->UAT
      |-> applicationFeature_scenorio1_Req.json
  |->PROD
      |-> applicationFeature_scenorio1_Req.json

Please help me on this how to pick data based on environment.

Config file

dev: {
      baseUrl: 'https://applicationsit.company.com',
      TestData : 'TestData/DEV'
     },
sit: {
    baseUrl: 'https://applicationsit.company.com',
    TestData : 'TestData/SIT'
    },
uat: {
    baseUrl: 'https://applicationuat2.company.com',
    TestData : 'TestData/UAT'
    },
prod: {
    baseUrl: 'https://applicationnewprod.company.com',
    TestData : 'TestData/PROD'
    }

Feature file

Background:
    * def testdata = TestData
      
@smoke @prod
Scenario: This is success scenario
    Given url baseUrl
    Given path '/cryptoService'
    And request read('#(testdata)/applicationFeature_scenorio1_Req.json')
    When method POST
    Then status 200
    * def encryptedPayload = response

Error found in karate

And request read('#(testdata)/applicationFeature_scenorio1_Req.json') 
js failed: 
>>>> 
01: read('#(testdata)/applicationFeature_scenorio1_Req.json') 
<<<< 
org.graalvm.polyglot.PolyglotException: java.io.FileNotFoundException: /tmp/workspace/application-prod-test/Continous_Testing/KarateConfigDir/#(testdata)/applicationFeature_scenorio1_Req.json (No such file or directory) 
- com.intuit.karate.resource.FileResource.getStream(FileResource.java:98) 
- com.intuit.karate.core.ScenarioFileReader.readFileAsStream(ScenarioFileReader.java:99) 
- com.intuit.karate.core.ScenarioFileReader.readFileAsString(ScenarioFileReader.java:95) 
- com.intuit.karate.core.ScenarioFileReader.readFile(ScenarioFileReader.java:53) 
- com.intuit.karate.core.ScenarioEngine.lambda$new$0(ScenarioEngine.java:124) 
- <js>.:program(Unnamed:1)

1 Answer 1

1

The '#(var)' system works only for JSON: https://github.com/karatelabs/karate#rules-for-embedded-expressions

Karate syntax is mostly JS and variables just work normally. With that in mind please make this change:

And request read(testdata + '/applicationFeature_scenorio1_Req.json')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.