I am writing a load test for my application.
I would like to simulate the following steps:
- login
- visit several pages
- submit a form within the website
I first wrote the login and visit several pages and run them successfully (no errors). When I added the code to submit form, I was getting '404/Not Found error' for the Submit Abstract transaction.
I am grateful to anyone who can provide me direction on how to solve this.
I wrote this test script using ruby then execute to convert it to .jmx file which I use to run headless test in cli.
code for login and visit several pages:
require 'ruby-jmeter'
test do
threads count: 100, rampup: 60, loops: 10, duration: 120 do
defaults domain: 'myapp.herokuapp.com', protocol: 'https'
cookies policy: 'rfc2109', clear_each_iteration: true
transaction 'Page Load Tests' do
user_defined_variables [{name: 'email', value: 'example@example.com'}, {name: 'password', value: 'Pass_w0rd'}]
visit name: 'Visit Login', url: '/users/sign_in' 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
end
http_header_manager name: 'X-CSRF-Token', value: '${csrf-token}'
submit name: 'Submit login', url: '/users/sign_in',
fill_in: {
'${csrf-param}' => '${csrf-token}',
'user[email]' => '${email}',
'user[password]' => '${password}',
'authenticity_token' => '${authenticity_token}'
}
visit name: 'Welcome Page', url: '/static_pages/welcome'
visit name: 'New Abstract Page', url: '/users/2/abstracts/new'
visit name: 'My Profile Page', url:'/users/2/participations/1/profile'
visit name: 'My Own Abstract Page', url:'/users/2/participations/1/abstracts/1'
view_results_in_table
aggregate_report
end.jmx
code for login, visit pages and submit form:
require 'ruby-jmeter'
test do
threads count: 100, rampup: 60, loops: 10, duration: 120 do
defaults domain: 'myapp.herokuapp.com', protocol: 'https'
cookies policy: 'rfc2109', clear_each_iteration: true
transaction 'Page Load Tests' do
user_defined_variables [{name: 'email', value: 'example@example.com'}, {name: 'password', value: 'Pass_w0rd'}]
visit name: 'Visit Login', url: '/users/sign_in' 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
end
http_header_manager name: 'X-CSRF-Token', value: '${csrf-token}'
submit name: 'Submit login', url: '/users/sign_in',
fill_in: {
'${csrf-param}' => '${csrf-token}',
'user[email]' => '${email}',
'user[password]' => '${password}',
'authenticity_token' => '${authenticity_token}'
}
visit name: 'Welcome Page', url: '/static_pages/welcome'
visit name: 'New Abstract Page', url: '/users/2/abstracts/new'
visit name: 'My Profile Page', url:'/users/2/participations/1/profile'
visit name: 'My Own Abstract Page', url:'/users/2/participations/1/abstracts/1'
transaction 'Submit Abstract' do
visit name: 'New Abstract Page', url: '/users/2/abstracts/new' 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 Abstract', url: '/users/2/abstracts/new',
fill_in: {
'${csrf-param}' => '${csrf-token}',
'abstract[title]' => 'Lorem Ipsum',
'abstract[main_author]' => '2',
'abstract[co_authors][]' => ["", "1", "3"],
'abstract[corresponding_author_email]' => '${email}',
'abstract[keywords]' => 'word, words',
'abstract[body]' => 'The test directive is a root point, where all the magic starts. Then, using threads method we are telling JMeter what number of users we want to use. The defaults command allows us to specify default options for all our http requests. And, finally,cookies indicates that we need to store cookies and send them with each request.',
'abstract[references]' => '1\r\n2\r\n3',
'authenticity_token' => '${authenticity_token}'
} do
assert 'contains' => 'Abstract submission completed.'
assert 'contains' => 'Lorem Ipsum'
end
end
end
view_results_in_table
aggregate_report
end.jmx
UPDATE PER @DMITRI T SUGGESTION:
REQUEST HEADER:
Browser:
Jmeter:
REQUEST BODY:
Browser:
Jmeter:
RESULT: STILL 404 error for the Submit Abstract Transaction