CORE SYNTAX
Project Structure
Organize your Karate project for maintainability and team collaboration using proven folder structures, naming conventions, and build configurations.
Recommended Folder Structure
Maven Project Layout
my-karate-project/
├── pom.xml # Maven configuration
├── src/test/java/ # All test files (recommended)
│ ├── karate-config.js # Global configuration
│ ├── logback-test.xml # Logging configuration
│ ├── TestRunner.java # Main test suite runner
│ │
│ ├── users/ # Domain-specific tests
│ │ ├── users.feature # Feature tests
│ │ ├── user-data.json # Test data
│ │ └── UsersRunner.java # Individual runner
│ ├── products/
│ │ ├── products.feature
│ │ └── product-data.csv
│ │
│ ├── auth/ # Reusable components
│ │ ├── login.feature
│ │ └── oauth-flow.feature
│ │
│ └── common/ # Shared utilities
│ ├── api-helpers.feature
│ ├── validators.js
│ └── test-data.json
│
└── target/ # Generated files
├── karate-reports/ # HTML test reports
└── surefire-reports/ # JUnit XML reports
Key Design Principles
- Co-location: Keep tests and test data together
- Domain organization: Group by business functionality
- Shared resources: Common utilities accessible via
classpath: - Standard conventions: Follow Maven/Gradle patterns
Configuration Files
Global Configuration (karate-config.js)
Must be placed in the classpath root (src/test/java/):
JavaScript
function fn() {
var env = karate.env || 'dev';
var config = {
baseUrl: 'https://api.dev.example.com',
authUrl: 'https://auth.dev.example.com',
timeout: 30000
};
// Environment-specific overrides
if (env == 'staging') {
config.baseUrl = 'https://api.staging.example.com';
} else if (env == 'prod') {
config.baseUrl = 'https://api.example.com';
config.timeout = 60000;
}
return config;
}
Logging Configuration (logback-test.xml)
Place in src/test/java/ for proper classpath access:
logback-test.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/karate.log</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level - %msg%n</pattern>
</encoder>
</appender>
<logger name="com.intuit.karate" level="DEBUG"/>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</configuration>