-
Notifications
You must be signed in to change notification settings - Fork 0
1. DSL Documentation
The jmeter_perf
Ruby Gem provides a DSL (Domain Specific Language) for performance testing with Apache JMeter.
Here you'll find the counterpart of JMeter Elements as methods within the library.
The convention is:
JmeterElementName -> JmeterPerf::DSL#jmeter_element_name
Method: counter
- Description: Creates a counter that can be incremented.
-
Parameters:
-
name
: The name of the counter. -
start
: The starting value. -
end
: The ending value. -
increment
: The increment value for each thread. -
per_user
: Whether the counter is per user. -
reset_on_tg_iteration
: Whether to reset on thread group iteration.
-
Example:
counter name: 'My Counter', start: 1, end: 10, increment: 1, per_user: true do
http_sampler name: 'Counter Request', url: 'http://example.com/counter'
end
Method: csv_data_set_config
- Description: Configures a CSV Data Set for parameterization.
-
Parameters:
-
filename
: Path to the CSV file. -
variable_names
: Comma-separated variable names to use. -
delimiter
: The delimiter (default is comma). -
recycle
: Recycle data after the end of the file. -
stopThread
: Stop thread if no data is available. -
ignoreFirstLine
: Ignore the first line of the CSV.
-
Example:
csv_data_set_config filename: 'data.csv', variable_names: 'user,email', delimiter: ',', recycle: true, ignoreFirstLine: true do
http_sampler name: 'CSV Request', url: 'http://example.com/user'
end
Method: ftp_request_defaults
- Description: Configures default settings for FTP requests.
-
Parameters:
-
server
: The FTP server address. -
port
: The port for FTP (default is 21). -
username
: Username for FTP authentication. -
password
: Password for FTP authentication.
-
Example:
ftp_request_defaults server: 'ftp.example.com', port: 21, username: 'user', password: 'pass' do
ftp_sampler name: 'FTP Sample Request', filename: 'sample.txt'
end
Method: http_authorization_manager
- Description: Manages HTTP authorization settings.
-
Parameters:
-
domain
: The domain requiring authentication. -
username
: Username for authentication. -
password
: Password for authentication. -
realm
: The realm for authentication.
-
Example:
http_authorization_manager domain: 'example.com', username: 'user', password: 'pass', realm: 'exampleRealm' do
http_sampler name: 'Authorized Request', url: 'http://example.com/protected'
end
Method: http_cache_manager
- Description: Configures caching behavior for HTTP requests.
-
Parameters:
-
clearEachIteration
: Clear the cache before each iteration. -
useExpires
: Use expiration headers.
-
Example:
http_cache_manager clearEachIteration: true, useExpires: false do
http_sampler name: 'Cached Request', url: 'http://example.com/cache'
end
Method: http_cookie_manager
- Description: Manages cookies for HTTP requests.
-
Parameters:
-
clearEachIteration
: Clear cookies before each iteration. -
policy
: Cookie policy to use.
-
Example:
http_cookie_manager clearEachIteration: true, policy: 'default' do
http_sampler name: 'Cookie Request', url: 'http://example.com/cookie'
end
Method: http_header_manager
- Description: Configures HTTP headers for requests.
-
Parameters:
-
headers
: A hash of headers (name => value).
-
Example:
http_header_manager headers: { 'Content-Type' => 'application/json', 'Authorization' => 'Bearer token' } do
http_sampler name: 'Header Request', url: 'http://example.com/header'
end
Method: http_request_defaults
- Description: Sets default values for HTTP requests.
-
Parameters:
-
domain
: Default domain for requests. -
port
: Default port for requests. -
protocol
: Default protocol (http or https). -
content_encoding
: Optional content encoding.
-
Example:
http_request_defaults domain: 'example.com', port: 80, protocol: 'http', content_encoding: 'UTF-8' do
http_sampler name: 'Default Request', path: '/default'
end
Method: java_request_defaults
- Description: Configures default settings for Java requests.
-
Parameters:
-
classname
: The fully qualified name of the Java class to be used. -
arguments
: Arguments to pass to the Java class.
-
Example:
java_request_defaults classname: 'org.example.MyJavaClass', arguments: { 'arg1' => 'value1', 'arg2' => 'value2' } do
java_sampler name: 'Java Request Sample', method: 'testMethod'
end
Method: jdbc_connection_configuration
- Description: Configures JDBC connection settings.
-
Parameters:
-
driver
: JDBC driver class. -
url
: Database connection URL. -
username
: Username for database authentication. -
password
: Password for database authentication.
-
Example:
jdbc_connection_configuration driver: 'com.mysql.jdbc.Driver', url: 'jdbc:mysql://localhost:3306/mydb', username: 'user', password: 'pass' do
jdbc_sampler name: 'JDBC Sample Request', query: 'SELECT * FROM users'
end
Method: keystore_configuration
- Description: Configures SSL/TLS settings using a keystore.
-
Parameters:
-
keystore_file
: Path to the keystore file. -
password
: Password for the keystore.
-
Example:
keystore_configuration keystore_file: '/path/to/keystore.jks', password: 'keystore_password' do
http_sampler name: 'Secure Request', url: 'https://example.com/secure'
end
Method: ldap_extended_request_defaults
- Description: Sets defaults for LDAP extended requests.
-
Parameters:
-
servername
: The LDAP server name. -
port
: The LDAP server port. -
rootdn
: The root distinguished name.
-
Example:
ldap_extended_request_defaults servername: 'ldap.example.com', port: 389, rootdn: 'cn=admin,dc=example,dc=com' do
ldap_sampler name: 'LDAP Request Sample', search_base: 'dc=example,dc=com'
end
Method: ldap_request_defaults
- Description: Configures default settings for LDAP requests.
-
Parameters:
-
servername
: LDAP server address. -
port
: LDAP server port (default is 389). -
base_dn
: Base distinguished name for the LDAP search.
-
Example:
ldap_request_defaults servername: 'ldap.example.com', port: 389, base_dn: 'dc=example,dc=com' do
ldap_sampler name: 'LDAP Request', search_filter: '(objectClass=person)'
end
Method: login_config_element
- Description: Configures login settings for web applications.
-
Parameters:
-
username
: The username for login. -
password
: The password for login.
-
Example:
login_config_element username: 'user', password: 'pass' do
http_sampler name: 'Login Request', url: 'http://example.com/login'
end
Method: random_variable
- Description: Generates a random variable during the test.
-
Parameters:
-
name
: The name of the random variable. -
min
: Minimum value for the random variable. -
max
: Maximum value for the random variable.
-
Example:
random_variable name: 'randomId', min: 1, max: 1000 do
http_sampler name: 'Random ID Request', url: 'http://example.com/random/${randomId}'
end
Method: simple_config_element
- Description: Adds a simple configuration element to the test plan.
-
Parameters:
-
name
: The name of the configuration element. -
value
: The value to be set.
-
Example:
simple_config_element name: 'My Config Element', value: 'Some Value' do
http_sampler name: 'Config Element Request', url: 'http://example.com/config'
end
Method: test_plan
- Description: Defines the main test plan structure in JMeter.
-
Parameters:
-
name
: The name of the test plan. -
comments
: Comments about the test plan. -
functional_mode
: Whether to run in functional mode. -
serialize_threadgroups
: Serialize thread groups.
-
Example:
JmeterPerf.test_plan name: 'My Test Plan', comments: 'This is a test plan for performance testing' do
thread_group name: 'Example Thread Group', num_threads: 5, ramp_time: 10 do
http_sampler name: 'Sample Request', url: 'http://example.com'
end
end