On Windows:
%GATLING_HOME% \ Bin \ gatling. bat
4.2 all the running scenarios (simulation) will be listed during running, and you can select the one you want to run.
5 test results
The Gatling Test Report is based on HTML and has been generated during the test, so it is very fast to open. In addition, when you move the mouse over different data axes, the detailed test data information is displayed in the pop-up box. This dynamic data display method makes it easy to view and analyze data. Considering the inconvenience caused by real project data, I will explain it through the sample report provided on the official Gatling website.
Gatling reports are classified into two types: GLOBAL and DETAILS. GLOBAL mainly includes request-related statistics, such as the number of requests per second, and the number of successful and failed requests; among them, DETAILS is mainly the statistics related to the request time, such as the request response time and request response delay time.
Figure 4 Number of requests per second,
When you move the cursor to any point in the graph, the detailed data requested at the corresponding time point will be displayed in the white pop-up box in the image. The same function is available in the following request response latency diagram.
Figure 5 request response latency,
6. Advanced
Script Parsing:
PackageComputerdatabase // 1 package name
ImportIo. gatling. core. Predef. _ // 2 must be imported
ImportIo. gatling. http. Predef ._
ImportScala. concurrent. duration ._
Class BasicSimulation Extends Simulation{// Class 3 Declaration, must inherit the Simulation
ValHttpConf=Http // 4 common configuration of all Http requests
. BaseURL ("http://computer-database.gatling.io") // 5 base URL
. AcceptHeader ("text/html, application/xhtml + xml, application/xml; q = 0.9, */*; q = 0.8") // 6 request headers
. DoNotTrackHeader ("1 ")
. AcceptLanguageHeader ("en-US, en; q = 0.5 ")
. AcceptEncodingHeader ("gzip, deflate ")
. UserAgentHeader ("Mozilla/5.0 (Windows NT 5.1; rv: 31.0) Gecko/20100101 Firefox/31.0 ")
ValScn=Scenario ("BasicSimulation") // 7 define a scenario
. Exec (http ("request_1") // 8 the name of the http request request_1, which is finally displayed in the report.
. Get ("/") // 9 get Request Method
. Pause (5) // 10 pause/think time 5S
SetUp (// 11 create a scenario
Scn. inject (atOnceUsers (1) // 12 declare to inject a user
). Protocols (httpConf) // Http request configuration declared earlier than 13
}
6.1 separation scenario: separation operations: such as browsing, searching, and editing operations
ObjectSearch{ValSearch=Exec (http ("Home") // let's give proper names, as they are displayed in the reports
. Get ("/" zookeeper .pause(72.16.exe c (http ("Search"). get ("/computers? F = macbook "paipai.pause(22.16.exe c (http (" Select "). get ("/computers/6 "). pause (3 )}ObjectBrowse{ValBrowse=???}ObjectEdit{ValEdit=???}
We can now rewrite our scenario using these reusable business processes:
ValScn=Scenario ("Scenario Name" cmd.exe c (Search. Search,Browse. Browse,Edit. Edit)
6.2 Set regular users and administrator accounts
ValUsers=Scenario ("Users" cmd.exe c (Search. Search,Browse. Browse)
ValAdmins=Scenario ("Admins" cmd.exe c (Search. Search,Browse. Browse,Edit. Edit)
6.3 set virtual users
SetUp (users. inject (atOnceUsers (10). protocols (httpConf ))
6.4 set the pressure to rise, that is, the number of users started at intervals
SetUp (users. inject (rampUsers (10) over (10 seconds), admins. inject (rampUsers (2) over (10 seconds). protocols (httpConf)
Start 10 users and 2 administrators within 10 s
6.5 parameterization or dynamic data
6.5.1 create a file: Create a cvs file in the user-files/data folder, for example:Search.csv, The content is as follows:
SearchCriterion, searchComputerName
Macbook and MacBook Pro
Eee, ASUS Eee PC 1005PE
6.5.2 files used:
ObjectSearch{
ValFeeder=Csv ("search.csv"). random // 1, 2
ValSearch=Exec (http ("Home"). get ("/"). pause (1). feed (feeder) // 3
. Exec (http ("Search"). get ("/computers? F =$ {searchCriterion} ") // 4
. Check (css ("a: contains ('$ {searchComputerName}')", "href"). saveAs ("computerURL") // 5
.Pause(1).exe c (http ("Select"). get ("$ {computerURL}") // 6
. Pause (1 )}
6.5.3 explanation:
Explanations: