Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions karate-tests/config/karate-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

function fn() {
function maskSensitiveFields(obj) {
var sensitiveKeys = ['password', 'token', 'authorization'];
for (var key in obj) {
if (sensitiveKeys.includes(key.toLowerCase())) {
obj[key] = '******';
} else if (typeof obj[key] === 'object' && obj[key] !== null) {
maskSensitiveFields(obj[key]);
}
}
return obj;
}
const envVars = {};
// Get all environment variables from the OS
const System = Java.type('java.lang.System');
const env = System.getenv();
// karate.log('env is:', env);
const keys = env.keySet().toArray();
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
envVars[key] = env.get(key);
if (key != 'API_TEST_SERVER_CONFIG' &&
(key.includes('API_HOST') || key.includes('BASE_URL') || key.includes('URL_BASE'))
) {
karate.log('set envVars for key:', key, ' with ', env.get(key));
}
}
// Add Karate's own env variable
envVars['karate.env'] = karate.env;
const config = {
maskSensitiveFields: maskSensitiveFields,
karate: {
properties: {...envVars,
//additionalProperty: 'value'
},
}
};
const LM = Java.type("com.example.logmodifier.LogModifier");
const logModifierInstance = new LM();
karate.configure("logModifier", logModifierInstance);

// karate.log('Karate configuration:', config);
return config;
}
79 changes: 79 additions & 0 deletions karate-tests/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Karate Feature File Execution Guide

This guide explains how to execute Karate feature files using the Karate JAR file via the command line.

---

## ✅ Prerequisites

1. **Karate JAR File**: Download the `karate.jar` file (see below for the command).
2. **Feature File**: Ensure you have a valid Karate `.feature` file.
3. **Configuration Directory**: *(Optional)* If you use `karate-config.js`, specify its directory.

---

## 📥 Download the Karate JAR File

Use this command to download the Karate JAR from GitHub releases:

```bash
curl -L "https://github.com/karatelabs/karate/releases/download/v\${KARATE_VERSION}/\${KARATE_JAR_NAME}" -o "\${KARATE_JAR_PATH}"
```

---

## 🚀 Command Syntax

To execute all feature files:

```bash
java -Dkarate.config.dir=<config-dir> -jar <karate_jar_filepath> <feature_filedir>
```

To execute a single feature file:

```bash
java -Dkarate.config.dir=<config-dir> -jar <karate_jar_filepath> <feature_filepath>
```

### Parameters:
- `<config-dir>`: *(Optional)* Path to the config directory with `karate-config.js`
- `<karate_jar_filepath>`: Path to the downloaded Karate JAR file
- `<feature_filepath>`: Path to the `.feature` file you want to run
- `<feature_filedir>`: Path to the feature files directory

---

## 💡 Example

Assume:
- Karate JAR is located at: `Downloads/karate-1.5.1.jar`
- Feature file is at: `karate-tests/tests/mf_api_v4_fund_schemes_list.json_get.feature`
- Config directory: `karate-tests/config`
- Feature files directory: `karate-tests/tests`

Then run the command:

```bash
java -Dkarate.config.dir=karate-tests/config -jar Downloads/karate-1.5.1.jar karate-tests/tests/mf_api_v4_fund_schemes_list.json_get.feature
```

To execute all feature files in the karate-tests/tests folder:

```bash
java -Dkarate.config.dir=karate-tests/config -jar Downloads/karate-1.5.1.jar karate-tests/tests
```
---
## 🛠 Troubleshooting

- ❌ **Incorrect paths** — Double-check the paths to JAR and feature files
- ⚠️ **Missing `karate-config.js`** — Ensure the file exists if you're using config

---

## 📌 Notes

- Ensure your `.feature` file is syntactically correct to avoid runtime errors
- You can pass a directory of feature files instead of a single file if needed

---
35 changes: 35 additions & 0 deletions karate-tests/tests/api_v3_funds_amc_list.json_get.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# ********RoostGPT********

# Test generated by RoostGPT for test kuvera_karate_get_api using AI Type Open AI and AI Model gpt-4o
#
# Feature file generated for /api/v3/funds/amc_list.json_get for http method type GET
# RoostTestHash=a20bd7e8f1
#
#

# ********RoostGPT********
Feature: AMC List API Tests

Background:
* def baseURL = karate.properties['KUVERA_BASE_URL'] || karate.properties['API_HOST']
* url baseURL
* header Accept = 'application/json'

Scenario: Verify the AMC List API returns a valid response
Given path '/api/v3/funds/amc_list.json'
When method GET
Then status 200
And match response == '#[]'
And match each response[*].AMC_code == '#string'
And match each response[*].available_for_purchase == '#number'
And match each response[*].amc_name == '#string'
And match each response[*].image == '#string'
And match each response[*].short_code == '#string'
And match each response[*].rta_info == '#string'
And match each response[*].address == '#string'
And match each response[*].phone_number == '#string'
And match each response[*].website == '#string'
And match each response[*].login_url == '#string'
And match each response[*].contact_email == '#string'
And match each response[*].description == '#string'
And assert karate.sizeOf(response) >= 1
25 changes: 25 additions & 0 deletions karate-tests/tests/api_v3_funds_index_nav_NIFTY50.json_get.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ********RoostGPT********

# Test generated by RoostGPT for test kuvera_karate_get_api using AI Type Open AI and AI Model gpt-4o
#
# Feature file generated for /api/v3/funds/index_nav/NIFTY50.json_get for http method type GET
# RoostTestHash=32db4f7597
#
#

# ********RoostGPT********
Feature: NIFTY 50 Historical Value API Tests

Background:
* def baseURL = karate.properties['KUVERA_BASE_URL'] || karate.properties['API_HOST']
* url baseURL
* header Accept = 'application/json'

Scenario: Retrieve NIFTY 50 Historical Values
Given path '/api/v3/funds/index_nav/NIFTY50.json'
When method GET
Then status 200
And match response == '#[]'
And match each response[*] == '#[2]'
And match each response[*][0] == '#? _ % 86400 == 0'
And match each response[*][1] == '#? _ >= 2500 && _ <= 88888 && _ % 0.1 == 0'
24 changes: 24 additions & 0 deletions karate-tests/tests/api_v3_funds_tags_top_bought.json_get.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ********RoostGPT********

# Test generated by RoostGPT for test kuvera_karate_get_api using AI Type Open AI and AI Model gpt-4o
#
# Feature file generated for /api/v3/funds/tags/top_bought.json_get for http method type GET
# RoostTestHash=6e5acf6d5f
#
#

# ********RoostGPT********
Feature: Top Bought Funds API

Background:
* def baseURL = karate.properties['KUVERA_BASE_URL'] || karate.properties['API_HOST']
* url baseURL
* header Accept = 'application/json'

Scenario: Verify the response for GET /api/v3/funds/tags/top_bought.json
Given path 'api/v3/funds/tags/top_bought.json'
When method GET
Then status 200
And match response == '#[] string'
And match each response[*] == '#regex ^[A-Z0-9-]+'
And match each response[*].length >= 4
40 changes: 40 additions & 0 deletions karate-tests/tests/api_v3_funds_tags_top_sold.json_get.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ********RoostGPT********

# Test generated by RoostGPT for test kuvera_karate_get_api using AI Type Open AI and AI Model gpt-4o
#
# Feature file generated for /api/v3/funds/tags/top_sold.json_get for http method type GET
# RoostTestHash=f9241cc552
#
#

# ********RoostGPT********
Feature: Top Sold Funds API

Background:
* def baseURL = karate.properties['KUVERA_BASE_URL'] || karate.properties['API_HOST']
* url baseURL
* header Accept = 'application/json'

Scenario: Verify the Top Sold Funds API returns a list of mutual fund codes
Given path '/api/v3/funds/tags/top_sold.json'
When method GET
Then status 200
And match response == '#[]'
And match each response[*] == '#string'
And match each response[*] contains '#regex ^[A-Z0-9-]+'
And match each response[*].length >= 4

Scenario: Verify the Top Sold Funds API with unsupported HTTP method
Given path '/api/v3/funds/tags/top_sold.json'
When method POST
Then assert responseStatus != 200

Scenario: Verify the Top Sold Funds API with unsupported HTTP method
Given path '/api/v3/funds/tags/top_sold.json'
When method PUT
Then assert responseStatus != 200

Scenario: Verify the Top Sold Funds API with unsupported HTTP method
Given path '/api/v3/funds/tags/top_sold.json'
When method DELETE
Then assert responseStatus != 200
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ********RoostGPT********

# Test generated by RoostGPT for test kuvera_karate_get_api using AI Type Open AI and AI Model gpt-4o
#
# Feature file generated for /api/v3/funds/tags/top_watchlist.json_get for http method type GET
# RoostTestHash=bee3a3b3c5
#
#

# ********RoostGPT********
Feature: Top Watched Funds API

Background:
* def baseURL = karate.properties['KUVERA_BASE_URL'] || karate.properties['API_HOST']
* url baseURL
* header Accept = 'application/json'

Scenario: Retrieve top watched mutual funds
Given path '/api/v3/funds/tags/top_watchlist.json'
When method GET
Then status 200
And match response == '#[]'
And match each response[*] == '#string'
And match each response[*] contains '#regex ^[A-Z0-9-]+'
And match each response[*].length >= 4
32 changes: 32 additions & 0 deletions karate-tests/tests/api_v3_gold_current_price.json_get.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ********RoostGPT********

# Test generated by RoostGPT for test kuvera_karate_get_api using AI Type Open AI and AI Model gpt-4o
#
# Feature file generated for /api/v3/gold/current_price.json_get for http method type GET
# RoostTestHash=f3ca0065bd
#
#

# ********RoostGPT********
Feature: Current Gold Price API

Background:
* def baseURL = karate.properties['KUVERA_BASE_URL'] || karate.properties['API_HOST']
* url baseURL
* header Accept = 'application/json'

Scenario: Get current gold price
Given path '/api/v3/gold/current_price.json'
When method GET
Then status 200
And match response == '#object'
And match response.taxes == '#object'
And match response.taxes.cgst == '#number'
And match response.taxes.sgst == '#number'
And match response.taxes.igst == '#number'
And match response.block_id == '#string'
And match response.fetched_at == '#string'
And match response.current_gold_price == '#object'
And match response.current_gold_price.buy == '#number'
And match response.current_gold_price.sell == '#number'
And match response.fetched_at == '#regex ^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$'
27 changes: 27 additions & 0 deletions karate-tests/tests/api_v3_gold_prices.json_get.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ********RoostGPT********

# Test generated by RoostGPT for test kuvera_karate_get_api using AI Type Open AI and AI Model gpt-4o
#
# Feature file generated for /api/v3/gold/prices.json_get for http method type GET
# RoostTestHash=28bb4bb229
#
#

# ********RoostGPT********
Feature: Gold Prices API

Background:
* def baseURL = karate.properties['KUVERA_BASE_URL'] || karate.properties['API_HOST']
* url baseURL
* header Accept = 'application/json'

Scenario: Retrieve Gold Prices with valid request
Given path '/api/v3/gold/prices.json'
When method GET
Then status 200
And match response == '#object'
And match response.gold_prices == '#[]'
And match each response.gold_prices[*].date == '#string'
And match each response.gold_prices[*].price == '#number'
And match each response.gold_prices[*].date == '#regex ^\\d{4}-\\d{2}-\\d{2}$'
And assert karate.sizeOf(response.gold_prices) >= 1
Loading