Skip to content

Instantly share code, notes, and snippets.

@davidcharlesweber
Last active April 28, 2020 05:56
Show Gist options
  • Save davidcharlesweber/059c72d5149560b8355d83bd405f5299 to your computer and use it in GitHub Desktop.
Save davidcharlesweber/059c72d5149560b8355d83bd405f5299 to your computer and use it in GitHub Desktop.
Gist for ruby-jmeter that will happily down a production rails app for you. Assumes that the application is using devise. Change thread count, duration and rampup to your needs. This will sign in as two different types of uses as a sample. Modify for your needs.
desc 'Generate and execute jmeter test plan'
task :generate_jmeter_plan do |t, args|
require 'ruby-jmeter'
generate_report
end
def generate_report
uri = URI('https://yourapp.com')
domain = uri.host
test do
threads count: 1, duration: 60 do # rampup: 30
cookies policy: 'rfc2109', clear_each_iteration: true
transaction 'Load Tests User Type 1' do
user_defined_variables [{name: 'email', value: 'put a login email here'}, {name: 'password', value: 'some password'}]
visit name: 'Visit Signin', url: '/users/sign_in', domain: domain, protocol: 'https', port: 443 do
extract name: 'csrf-token', xpath: "//meta[@name='csrf-token']/@content", tolerant: true
extract name: 'csrf-param', xpath: "//meta[@name='csrf-param']/@content", tolerant: true
extract name: 'authenticity_token', regex: 'name="authenticity_token" value="(.+?)"'
end
http_header_manager name: 'X-CSRF-Token', value: '${csrf-token}'
submit name: 'Submit signin', url: '/users/sign_in', domain: domain, protocol: 'https', port: 443, fill_in: {
'authenticity_token' => '${authenticity_token}',
'user[email]' => '${email}',
'user[password]' => '${password}',
'${csrf-param}' => '${csrf-token}'
}
visit name: 'Some Path 1', url: '/path/organization/active', domain: domain, protocol: 'https', port: 443
visit name: 'Some Path 2', url: '/path/users', domain: domain, protocol: 'https', port: 443
end
transaction 'Load Tests User Type 2' do
user_defined_variables [{name: 'email', value: 'another user type'}, {name: 'password', value: 'some other password'}]
visit name: 'Visit Signin', url: '/users/sign_in', domain: domain, protocol: 'https', port: 443 do
extract name: 'csrf-token', xpath: "//meta[@name='csrf-token']/@content", tolerant: true
extract name: 'csrf-param', xpath: "//meta[@name='csrf-param']/@content", tolerant: true
extract name: 'authenticity_token', regex: 'name="authenticity_token" value="(.+?)"'
end
http_header_manager name: 'X-CSRF-Token', value: '${csrf-token}'
submit name: 'Submit signin', url: '/users/sign_in', domain: domain, protocol: 'https', port: 443, fill_in: {
'authenticity_token' => '${authenticity_token}',
'user[email]' => '${email}',
'user[password]' => '${password}',
'${csrf-param}' => '${csrf-token}'
}
visit name: 'Dashboard', url: '/my_dashboard', domain: domain, protocol: 'https', port: 443
end
view_results_in_table
view_results_tree
graph_results
aggregate_graph
end
end.run(
file: 'jmeter.jmx',
log: 'jmeter.log',
jtl: 'results.jtl'
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment