In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to send parameters in the GET request in nGrinder. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
There are two ways to add information headers, cookies, and custom parameters to the GET request script:
One is to generate the script automatically after the UI interface is added, and the other is to add it directly to the script.
Add through the UI interface
Set up through UI: script-> New script-> Show Advanced configuration
The generated code is as follows:
@ RunWith (GrinderRunner)
@ FixMethodOrder (MethodSorters.NAME_ASCENDING)
Class TestRunner {
Public static GTest test
Public static HTTPRequest request
Public static NVPair [] headers = []
Public static NVPair [] params = []
Public static Cookie [] cookies = []
@ BeforeProcess
Public static void beforeProcess () {
HTTPPluginControl.getConnectionDefaults () .timeout = 6000
Test = new GTest (1, "www.baidu.com")
Request = new HTTPRequest ()
/ / the following is the parameter I just added =
/ / Set header datas
List headerList = new ArrayList ()
HeaderList.add (new NVPair ("Connection", "keep-alive"))
HeaderList.add (new NVPair ("User-Agent", "Mozilla/5.0 (X11; Linux x8634; rv:12.0) Gecko/20100101 Firefox/21.0"))
Headers = headerList.toArray ()
/ / Set param datas
List paramList = new ArrayList ()
ParamList.add (new NVPair ("name", "jing"))
ParamList.add (new NVPair ("age", "18"))
ParamList.add (new NVPair ("sex", "beauty"))
Params = paramList.toArray ()
/ / Set cookie datas
List cookieList = new ArrayList ()
CookieList.add (new Cookie ("myToken", "xxxxxxxx", "www.baidu.com", "", new Date (32503647599000L), false))
Cookies = cookieList.toArray ()
/ / the above is the parameter I just added =
Grinder.logger.info ("before process.")
}
@ BeforeThread
Public void beforeThread () {
Test.record (this, "test")
Grinder.statistics.delayReports=true
Grinder.logger.info ("before thread.")
}
@ Before
Public void before () {
Request.setHeaders (headers)
Cookies.each {CookieModule.addCookie (it, HTTPPluginControl.getThreadHTTPClientContext ())}
Grinder.logger.info ("before thread. Init headers and cookies")
}
@ Test
Public void test () {
HTTPResponse result = request.GET ("https://www.baidu.com", params)
AssertThat (result.statusCode, is)
/ / this is the assertion I added manually through the boot page
AssertThat (result.getText (), containsString ("jing"))
}
}
You can see that this way is to add heads, params, and cookies to @ beforeProcess.
Add it directly to the script
(only the way to add headers and params is demonstrated here. Adding cookies is similar, so I won't repeat it.)
Depending on the location you add to the script, it can be divided into the following ways:
1. Add headers and params to the @ BeforeProcess annotation method
This method has the same effect as the first method.
/ / add headers
List headerList = new ArrayList ()
HeaderList.add (new NVPair ("Accept-Language", "en-US,zh-CN;"))
/ /... You can add multiple header
Headers = headerList.toArray ()
/ / add params
List paramList = new ArrayList ()
ParamList.add (new NVPair ("accessToken", "xxxxxxxxx"))
/ /... You can add multiple param
Params = paramList.toArray ()
2. Add headers and params directly to the static variables of the TestRunner class
Assign a value to the variable directly where the static variable is defined at the beginning of the entire class:
/ / add headers
Public static NVPair [] headers = [
New NVPair ("Accept-Language", "en-US,zh-CN;")
]
/ / add params
Public static NVPair [] params = [
New NVPair ("accessToken", "xxxxxxxxxx")
]
3. Add headers and params to the @ Test annotation method
Add parameters to the method that sends the request request:
/ / HTTPResponse result = request.GET ("https://www.baidu.com", params)
/ / add headers
HTTPResponse result = request1.GET ("https://www.baidu.com", [new NVPair (" Accept-Language "," en-US,zh-CN; ")] as NVPair [])
/ / add params
HTTPResponse result = request.GET ("https://www.baidu.com", [new NVPair (" accessToken "," xxxxxx ")] as NVPair [])
Which method to choose depends on the specific parameter type and business scenario.
The above is how to send parameters in a GET request in nGrinder. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.