使用ruby-jmeter编写网站表单提交压测脚本报404错误如何解决
负载测试提交表单返回404问题咨询
我正在为我的应用编写负载测试,期望模拟以下操作流程:
- 登录系统
- 访问多个页面
- 提交网站内表单
我已完成登录、多页面访问模块的代码开发,运行无报错。但添加表单提交代码后,执行Submit Abstract事务时返回404/Not Found错误,恳请各位提供解决思路。
我使用ruby编写测试脚本,执行后转换为.jmx文件,在命令行运行无头测试。
登录及多页面访问代码
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
添加表单提交后的完整测试代码
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
调试情况
按照@DMITRI T的建议修改测试后,我分别对比了浏览器端和JMeter端的请求头、请求体内容,修改后的测试运行后Submit Abstract事务仍然返回404错误。
内容的提问来源于stack exchange,提问作者sa0irxe
相关产品推荐
相关产品推荐

