jmeter之配置元件
jmeter之配置元件
利用Jmeter的http請求的時候,例如登陸操作,我們做普通用戶名和密碼作參數(shù)化,循環(huán)讀取文本里的用戶名和密碼,可以添加CSV
利用Jmeter的CSV
1.新建一個文本文件,里面保存要登錄的用戶名,密碼,文件內(nèi)容如下:
baidu,123456
coolsin,liujuan
sb,123456
說明:這里用英文逗號為分隔符,也可以用其他為分隔符,在CSV
2.右鍵點擊Jmeter中需要參數(shù)化的某個請求,選擇添加——配置原件——CSV
Filename:文件名,,指保存信息的文件目錄,可以相對或者絕對路徑(比如:D:\user.csv)
Variable
說明:這里的username與password為自己定義的名稱,請求中要用這個名稱,例如${參數(shù)名稱}
Delimitet:定義分隔符,這里定義某個分隔符,則在“Variable
Recycle
設置CSV
當文本中參數(shù)運行完成后,再從第一個開始循環(huán)讀取,如果選擇為false,則停止運行
備注說明:這里我用通俗的語言大概講一下Recycle on EOF與Stop thread on EOF結果的關聯(lián)
Recycle on EOF :到了文件尾處,是否循環(huán)讀取參數(shù),選項:true和false
Stop thread on EOF:到了文件尾處,是否停止線程,選項:true和false
當Recycle on EOF 選擇true時,Stop thread on EOF選擇true和false無任何意義,通俗的講,在前面控制了不停的循環(huán)讀取,后面再來讓stop或run沒有任何意義
當Recycle on EOF 選擇flase時,Stop thread on EOF選擇true,線程4個,參數(shù)3個,那么只會請求3次
當Recycle on EOF 選擇flase時,Stop thread on EOF選擇flase,線程4個,參數(shù)3個,那么會請求4次,但第4次沒有參數(shù)可取,不讓循環(huán),所以第4次請求錯誤
3.在需要使用變量的地方,比如在登錄操作中,需要提交的表單字段包含用戶名密碼,我們就可以用${變量名}的形式進行替換,例如${user}和${password}
參數(shù)設置如圖所示:
Allow quoted data? | Should the CSV file allow values to be quoted? If enabled, then values can be enclosed in " - double-quote - allowing values to contain a delimeter. |
4.
備注說明:
1、使用這個元件做參數(shù)時,盡量用CSV格式的表格來做,我試過其它格式的dat和txt,都讀取不到
2、這個元件要在該請求下單獨添加
Attribute | Description | Required |
---|---|---|
Name | Descriptive name for this element that is shown in the tree. | No |
Clear cache each iteration | If selected, then the cache is cleared at the start of the thread. | Yes |
Use Cache Control/Expires header when processing GET requests | See description above. | Yes |
Max Number of elements in cache | See description above. |
HTTP COOKIE Manager管理cookie有兩種方法:現(xiàn)在對于JMeter來說,一個測試計劃只能有一個cookie管理器。因為當多個magager存在時,JMeter目前還沒有方法來指定使用那個manager。同時,一個cookie manager中的存儲的cookie也不能被其他cookie manager所引用,所以同一個計劃中不建議使用多個cookie manager
- 他可以像瀏覽器一樣存儲和發(fā)送cookie,如果你要發(fā)送一個帶cookie的http請求,cookie manager會自動存儲該請求的cookies,并且后面如果發(fā)送同源站點的http請求時,都可以用這個cookies。每個JMeter線程都有自己的“cookie存儲區(qū)域”,
- 打開firebug,如圖


載入剛才導出的cookies.txt文件即可。
名稱 | 描述 | 是否必填 |
Name | 自定義該cookie的描述,例如:tuan.qq.com的cookie | N |
Clear Cookies each Iteration | 每次線程組運行前,都會清楚cookie,但是如果是手動添加的cookie,不會被清除 | N |
Cookie Policy | 選擇cookie的管理策略,建議選擇compatibility,兼容性強 | |
User-Defined Cookies | 用戶自定義cookie | |
Add Button | 。。。略過 |

Attribute | Description | Required |
---|---|---|
Name | Descriptive name for this element that is shown in the tree. | No |
Name (Header) | Name of the request header. Two common request headers you may want to experiment with are "User-Agent" and "Referer". | No (You should have at least one, however) |
Value | Request header value. | No (You should have at least one, however) |
Add Button | Add an entry to the header table. | N/A |
Delete Button | Delete the currently selected table entry. | N/A |
Load Button | Load a previously saved header table and add the entries to the existing header table entries. | N/A |
Save As Button | Save the current header table to a file. |

Attribute | Description | Required | |||||||
---|---|---|---|---|---|---|---|---|---|
Name | Descriptive name for this element that is shown in the tree. | No | |||||||
Clear auth on each iteration ? | Used by Kerberos authentication. If checked, authentication will be done on each iteration of Main Thread Group loop even if it has already been done in a previous one. This is usually useful if each main thread group iteration represents behaviour of one Virtual User. | Yes | |||||||
Base URL | A partial or complete URL that matches one or more HTTP Request URLs. As an example, say you specify a Base URL of "http://jmeter.apache.org/restricted/" with a username of "jmeter" and a password of "jmeter". If you send an HTTP request to the URL "http://jmeter.apache.org/restricted/ant/myPage.html", the Authorization Manager sends the login information for the user named, "jmeter". | Yes | |||||||
Username | The username to authorize. | Yes | |||||||
Password | The password for the user. (N.B. this is stored unencrypted in the test plan) | Yes | |||||||
Domain | The domain to use for NTLM. | No | |||||||
Realm | The realm to use for NTLM. | No | |||||||
Mechanism | Type of authentication to perform. JMeter can perform different types of authentications based on used Http Samplers:
|
http 默認請求
一個HTTP請求有著許多的配置參數(shù),下面將詳細介紹:
名稱:本屬性用于標識一個取樣器,建議使用一個有意義的名稱。
注釋:對于測試沒有任何作用,僅用戶記錄用戶可讀的注釋信息。
服務器名稱或IP :HTTP請求發(fā)送的目標服務器名稱或IP地址。
端口號:目標服務器的端口號,默認值為80 。
協(xié)議:向目標服務器發(fā)送HTTP請求時的協(xié)議,可以是http或者是https ,默認值為http 。
方法:發(fā)送HTTP請求的方法,可用方法包括GET、POST、HEAD、PUT、OPTIONS、TRACE、DELETE等。
Content encoding :內(nèi)容的編碼方式,默認值為iso8859
路徑:目標URL路徑(不包括服務器地址和端口)
自動重定向:如果選中該選項,當發(fā)送HTTP請求后得到的響應是302/301時,JMeter 自動重定向到新的頁面。
Use keep Alive : 當該選項被選中時,jmeter 和目標服務器之間使用 Keep-Alive方式進行HTTP通信,默認選中。
Use multipart/from-data for HTTP POST :當發(fā)送HTTP POST 請求時,使用Use multipart/from-data方法發(fā)送,默認不選中。
同請求一起發(fā)送參數(shù) : 在請求中發(fā)送URL參數(shù),對于帶參數(shù)的URL ,jmeter提供了一個簡單的對參數(shù)化的方法。用戶可以將URL中所有參數(shù)設置在本表中,表中的每一行是一個參數(shù)值對(對應RUL中的 名稱1=值1)。
同請求一起發(fā)送文件:在請求中發(fā)送文件,通常,HTTP文件上傳行為可以通過這種方式模擬。
從HTML文件獲取所有有內(nèi)含的資源:當該選項被選中時,jmeter在發(fā)出HTTP請求并獲得響應的HTML文件內(nèi)容后,還對該HTML進行Parse 并獲取HTML中包含的所有資源(圖片、flash等),默認不選中,如果用戶只希望獲取頁面中的特定資源,可以在下方的Embedded URLs must match 文本框中填入需要下載的特定資源表達式,這樣,只有能匹配指定正則表達式的URL指向資源會被下載。
可以使用該請求執(zhí)行java文件
用jmeter測試java程序
最近在用jmeter進行性能測試,防止被忘記,把步驟寫下。
場景:測試java程序
1、右擊測試計劃-> 添加 -> Threads(Users) -> 線程組
2、設置線程屬性,用于并發(fā)請求。
介紹:
線程數(shù): 5
Ramp-Up Period(in seconds) : 1
循環(huán)次數(shù): 2
含義:1秒種起動5個線程,每個線程循環(huán)調(diào)用2次java請求
3、線程組右擊 -> 添加 -> Sampler -> Java請求
之前建立測試類:
package com.my.test; import java.util.Random; import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient; import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; import org.apache.jmeter.samplers.SampleResult; /** * Hello world! * */ public class App extends AbstractJavaSamplerClient{ public static double computer(double a,double b){ return a * b / a * a; } @Override public SampleResult runTest(JavaSamplerContext arg0) { // TODO Auto-generated method stub SampleResult sr = new SampleResult(); sr.sampleStart(); Random random = new Random(); for(int i=0; i<10000; i++){ computer(random.nextDouble(),random.nextDouble()); } sr.setSuccessful(true); sr.sampleEnd(); return sr; } @Override public void setupTest(JavaSamplerContext context) { // TODO Auto-generated method stub super.setupTest(context); } @Override public void teardownTest(JavaSamplerContext context) { // TODO Auto-generated method stub super.teardownTest(context); } }
使用的jar包有:ApacheJMeter_java.jar ,ApacheJMeter_core.jar
上述jar包在 %JMETER_HOME%/lib/ext/下
將測試程序打成jar包,放在%JMETER_HOME%/lib/ext/下
這里會自動識別出該類,選擇。
4、線程組右擊 -> 添加 -> 監(jiān)聽器 -> 用表格察看結果
Ctrl + R,開始運行,
Ctrl + E,清除歷史結果
JDBC Connection Configuration
Database URL: jdbc:oracle:thin:@192.168.1.168:1521:ptoracl JDBC Driver class: oracle.jdbc.driver.OracleDriver Username: lianggzone Password:lianggzone |

Attribute | Description | Required |
---|---|---|
Name | Descriptive name for the connection configuration that is shown in the tree. | No |
Variable Name | The name of the variable the connection is tied to. Multiple connections can be used, each tied to a different variable, allowing JDBC Samplers to select the appropriate connection. Each name must be different. If there are two configuration elements using the same name, only one will be saved. JMeter versions after 2.3 log a message if a duplicate name is detected. | Yes |
Max Number of Connections | Maximum number of connections allowed in the pool. In most cases, set this to zero (0) . This means that each thread will get its own pool with a single connection in it, i.e. the connections are not shared betweeen threads. If you really want to use shared pooling (why?), then set the max count to the same as the number of threads to ensure threads don't wait on each other. | Yes |
Pool timeout | Pool throws an error if the timeout period is exceeded in the process of trying to retrieve a connection | Yes |
Idle Cleanup Interval (ms) | This is used to specify how long idle connections will be maintained in the pool before being closed. For a complete explanation on how this works, see ResourceLimitingPool.trim() (Defaults to "60000", 1 minute) | Yes |
Auto Commit | Turn auto commit on or off for the connections. | Yes |
Keep-alive | The keep-alive is used enable a mechanism to monitor the health of connections. If a connection has not been used for Max Connection Age (ms) then before returning the connection from a call to getConnection(), the connection is first used to ping the database to make sure that it is still alive. Setting the age allows the 5 second age to be overridden. Validation Query will be used to test it. | Yes |
Max Connection Age (ms) | Controls the age mentionned in "Keep-Alive" property. It means connections not used for more than Max Connection Age will be tested | Yes |
Validation Query | A simple query used to determine if the database is still responding. | Yes |
Database URL | JDBC Connection string for the database. | Yes |
JDBC Driver class | Fully qualified name of driver class. (Must be in JMeter's classpath - easiest to copy .jar file into JMeter's /lib directory). | Yes |
Username | Name of user to connect as. | No |
Password | Password to connect with. (N.B. this is stored unencrypted in the test plan) | No |
Control Panel

Attribute | Description | Required |
---|---|---|
Name | Descriptive name for this element that is shown in the tree. | No |
Preload | Wether or not to preload Keystore. Setting is to true is usually the best option. | Yes |
Variable name holding certificate alias | Variable name that will contain the alias to use for authentication by client certificate. Variable value will be filled from CSV Data Set for example. In the screenshot, "certificat_ssl" will also be a variable in CSV Data Set. | False |
Alias Start Index | The index of the first key to use in Keystore, 0-based. | Yes |
Alias End Index | The index of the last key to use in Keystore, 0-based. When using "Variable name holding certificate alias" ensure it is large enough so that all keys are loaded at startup. | Yes |
可以添加一個config element中的LDAP Request Defaults用于控制一些共享默認值.
There are two ways to create test cases for testing an LDAP Server.
- Inbuilt Test cases.
- User defined Test cases.
There are four test scenarios of testing LDAP. The tests are given below:
- Add Test
- Inbuilt test :
This will add a pre-defined entry in the LDAP Server and calculate the execution time. After execution of the test, the created entry will be deleted from the LDAP Server.
- User defined test :
This will add the entry in the LDAP Server. User has to enter all the attributes in the table.The entries are collected from the table to add. The execution time is calculated. The created entry will not be deleted after the test.
- Modify Test
- Inbuilt test :
This will create a pre-defined entry first, then will modify the created entry in the LDAP Server.And calculate the execution time. After execution of the test, the created entry will be deleted from the LDAP Server.
- User defined test
This will modify the entry in the LDAP Server. User has to enter all the attributes in the table. The entries are collected from the table to modify. The execution time is calculated. The entry will not be deleted from the LDAP Server.
- Search Test
- Inbuilt test :
This will create the entry first, then will search if the attributes are available. It calculates the execution time of the search query. At the end of the execution,created entry will be deleted from the LDAP Server.
- User defined test
This will search the user defined entry(Search filter) in the Search base (again, defined by the user). The entries should be available in the LDAP Server. The execution time is calculated.
- Delete Test
- Inbuilt test :
This will create a pre-defined entry first, then it will be deleted from the LDAP Server. The execution time is calculated.
- User defined test
This will delete the user-defined entry in the LDAP Server. The entries should be available in the LDAP Server. The execution time is calculated.
有兩種方法可以創(chuàng)建測試用例測試LDAP服務器。
內(nèi)置的測試用例。
用戶定義的測試用例。
有四個測試場景的測試LDAP。給出了測試如下:
添加測試
內(nèi)置的測試:
這將添加一個預定義的條目在LDAP服務器和計算執(zhí)行時間。執(zhí)行測試后,創(chuàng)建的條目將被刪除從LDAP服務器。
用戶定義的測試:
這將在LDAP服務器中添加條目。用戶必須輸入表中所有的屬性。從表中收集到的條目添加計算執(zhí)行時間。創(chuàng)建的條目測試后將不會被刪除。
修改測試
內(nèi)置的測試:
這將創(chuàng)建一個預定義的條目,然后將修改在LDAP服務器創(chuàng)建的條目。并計算執(zhí)行時間。執(zhí)行測試后,創(chuàng)建的條目將被刪除從LDAP服務器。
用戶定義的測試
這將修改LDAP服務器中的條目。用戶必須輸入表中所有的屬性。從表中收集修改的條目。計算執(zhí)行時間。條目不會從LDAP服務器中刪除。
搜索測試
內(nèi)置的測試:
這將創(chuàng)建的條目,然后將搜索可用的屬性。它計算搜索查詢的執(zhí)行時間。結束時執(zhí)行,創(chuàng)建條目將被刪除從LDAP服務器。
用戶定義的測試
這將搜索用戶定義的條目(搜索過濾器)在搜索基地(再一次,由用戶定義的)。應該在LDAP服務器中可用的條目。計算執(zhí)行時間。
刪除測試
內(nèi)置的測試:
這將創(chuàng)建一個預定義的條目,然后它將從LDAP服務器中刪除。計算執(zhí)行時間。
用戶定義的測試
這將刪除用戶定義的條目在LDAP服務器。應該在LDAP服務器中可用的條目。計算執(zhí)行時間。
Attribute | Description | Required |
---|---|---|
Name | Descriptive name for this sampler that is shown in the tree. | No |
Server Name or IP | Domain name or IP address of the LDAP server. JMeter assumes the LDAP server is listening on the default port(389). | Yes |
Port | default port(389). | Yes |
root DN | DN for the server to communicate | Yes |
Username | LDAP server username. | Usually |
Password | LDAP server password. (N.B. this is stored unencrypted in the test plan) | Usually |
Entry DN | the name of the context to create or Modify; may not be empty Example: do you want to add cn=apache,ou=test you have to add in table name=cn, value=apache | Yes |
Delete | the name of the context to Delete; may not be empty | Yes |
Search base | the name of the context or object to search | Yes |
Search filter | the filter expression to use for the search; may not be null | Yes |
add test | this name, value pair to added in the given context object | Yes |
modify test | this name, value pair to add or modify in the given context object |


jmeter random variable
Control Panel ![]()
| ||||||||||||||||||||||||
18.4.13 TCP Sampler Config | ||||||||||||||||||||||||||||||||||||||
The TCP Sampler Config provides default data for the TCP Sampler Control Panel ![]()
|
Control Panel ![]()
| ||||||||||
18.4.10 Login Config Element | ||||||||||||
The Login Config Element lets you add or override username and password settings in samplers that use username and password as part of their setup. Control Panel ![]()
|
18.4.17 Simple Config Element | |||||||||||
The Simple Config Element lets you add or override arbitrary values in samplers. You can choose the name of the value and the value itself. Although some adventurous users might find a use for this element, it's here primarily for developers as a basic GUI that they can use while developing new JMeter components. Control Panel ![]()
|
18.4.16 Counter | |||||||||||||||||||||||||||
Allows the user to create a counter that can be referenced anywhere in the Thread Group. The counter config lets the user configure a starting point, a maximum, and the increment. The counter will loop from the start to the max, and then start over with the start, continuing on like that until the test is ended. From version 2.1.2, the counter now uses a long to store the value, so the range is from -2^63 to 2^63-1. Control Panel ![]()
|
posted on 2014-02-28 13:50 順其自然EVO 閱讀(4465) 評論(0) 編輯 收藏 所屬分類: jmeter