Gatling:环境搭建、脚本录制、脚本回放、报告查看

一、环境搭建

Gatling环境通过IntelliJ IDEA 工具整合Gatling插件,IntelliJ IDEA安装这里就不赘述了
PS:我这里使用的IDEA版本是ideaIC-2018.2.8、需要MAVEN环境以及JDK1.8环境

1.启动Intellij IEDA后创建maven工程
File->new->project,选择Maven,勾选Create from archetype,点击Add Archetype
在这里插入图片描述
点击Project SDK右边的new按钮指定JDK 1.8,选中添加后的archetype点击next
在这里插入图片描述
输入GroupId、ArtifactId点击Next
在这里插入图片描述
选择maven以及setting.xml,点击Next
在这里插入图片描述
点击Finish
在这里插入图片描述
此时会进入项目页面,点击Import Changes自动导入变化,此时需要等待Import Changes运行完成。
2.修改pom.xml文件加入Gatling运行插件,完整的pom.xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>GatlingTestDemo</groupId>
  <artifactId>GatlingTest</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <encoding>UTF-8</encoding>

    <gatling.version>3.1.2</gatling.version>
    <gatling-maven-plugin.version>3.0.1</gatling-maven-plugin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.gatling.highcharts</groupId>
      <artifactId>gatling-charts-highcharts</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-app</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-recorder</artifactId>
      <version>${gatling.version}</version>
    </dependency>
  </dependencies>

  <build>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-maven-plugin</artifactId>
        <version>${gatling-maven-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <!-- the name of the single Simulation class to run -->
          <simulationClass>gatlingTestScripts.RecordedSimulation</simulationClass>
          <!-- if the plugin should run multiple simulations sequentially -->
          <runMultipleSimulations>true</runMultipleSimulations>
          <!-- include filters, see dedicated section below -->
          <includes>
            <include>gatlingTestScripts.RecordedSimulation</include>
          </includes>
          <!-- exclude filters, see dedicated section below -->
          <excludes>
            <exclude></exclude>
          </excludes>
          <!-- to disable generating HTML reports -->
          <noReports>false</noReports>
          <!-- to only trigger generating HTML reports from the log file contained in folder parameter -->
          <reportsOnly></reportsOnly>
          <!-- short text that will be displayed in the HTML reports -->
          <runDescription>design level training demo</runDescription>
          <!-- skip executing this plugin -->
          <skip>false</skip>
          <!-- report failure in case of assertion failure, typically to fail CI pipeline -->
          <failOnError>true</failOnError>
          <!-- keep on executing multiple simulations even if one fails -->
          <continueOnAssertionFailure>false</continueOnAssertionFailure>
          <!-- report results to Jenkins JUnit support -->
          <useOldJenkinsJUnitSupport>false</useOldJenkinsJUnitSupport>
          <jvmArgs>
            <!-- pass extra parameters to the Gatling JVM -->
            <jvmArg>-Dfile.encoding=UTF-8</jvmArg>
          </jvmArgs>
          <!-- if above option should override the defaults instead of replacing them -->
          <overrideJvmArgs>false</overrideJvmArgs>
          <!-- if System properties from the maven JVM should be propagated to the Gatling forked one -->
          <propagateSystemProperties>true</propagateSystemProperties>
          <compilerJvmArgs>
            <!-- pass extra parameters to the Compiler JVM -->
            <compilerJvmArg></compilerJvmArg>
          </compilerJvmArgs>
          <!-- if above option should override the defaults instead of replacing them -->
          <overrideCompilerJvmArgs>false</overrideCompilerJvmArgs>
          <!-- extra options to be passed to scalac -->
          <extraScalacOptions>
            <extraScalacOption></extraScalacOption>
          </extraScalacOptions>
          <!-- if compiler should be disabled, typically another plugin has already compiled sources -->
          <disableCompiler>false</disableCompiler>
          <!-- where the simulations to be compiled are located -->
          <simulationsFolder>${project.basedir}/src/test/scala</simulationsFolder>
          <!-- where the test resources are located -->
          <resourcesFolder>${project.basedir}/src/test/resources</resourcesFolder>
          <!-- where the simulation log and the HTML reports will be generated -->
          <resultsFolder>${project.basedir}/target/gatling/results</resultsFolder>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

然后再Import Changes.
3.配置Run Configurations
点击Add Configuration,点击+号,选择maven,输入name:gatling:test,Command Line:gatling:test然后OK
在这里插入图片描述
注意:这里的Command line,输入gatling后会自动提示,并且这里的test和pom.xml中test一致。
4.运行Run Configuration
菜单栏Run->gatling:test,构建后ERROR信息:No simulations to run,就说明环境配置已成功,这是因为没有指定需要构建的测试脚本,录制脚本并在pom.xml中配置后执行就不会报错了。
二、脚本录制以及回放
1.安装Scala插件
录制前需要安装scala插件,安装过程如下:
从IDE菜单:Files->Settings->Plugins进入插件安装界面
点击:Install JetBrains Plugin…
选择Scala插件,点击Install按钮安装
我这里已安装,界面显示如下:
在这里插入图片描述
安装完成后重启IDEA,项目显示如下:
在这里插入图片描述
注意图中红框内部分,当scala安装成功后,显示如上图。
2.录制脚本
选择Recorder,右键,选择Run ‘Recorder’,填写package和ClassName,Package首字母要小写,localhost HTTP/HTTPS这里需要保证和浏览器代理的端口保持一致,不然录制时采集不到数据,
在这里插入图片描述
点击start
在这里插入图片描述
操作浏览器后,在配置的package下会生成对应的脚本。
我们录制一个登陆百度的脚本如下图:
在这里插入图片描述
3.回放脚本
在pom.xml中配置刚刚录制的脚本,Run->gatling:test,即可回放,回访后console显示Build Success。
三.报告查看
执行成功后,报告会展示在如下目录(在pom.xml中配置):
在这里插入图片描述
打开index.html
在这里插入图片描述
报告部分术语解释:
total:总请求次数
OK:成功数
KO:失败数
Req/s:每秒请求次数即吞吐量
Response Time Distribution:响应时间分布
Response Time Percentiles over Time: 百分比响应时间分布
Number of responses per second: 每秒的响应数
Number of requests per second: 每秒的请求数
总结:本文主要讲述Gatling环境搭建,脚本录制、回放以及报告查看,后续会深入学习更新,敬请期待。

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要搭建Gatling脚本开发环境,首先需要安装IntelliJ IDEA工具并安装Gatling插件。可以根据个人喜好选择IDEA的版本,同时需要确保安装了MAVEN环境和JDK1.8环境。 接下来,在IDEA中打开一个工程,并安装scala插件。首次使用时,可以在IDEA界面上点击"File > Settings > Plugins",然后搜索Scala插件,点击"install"进行安装。如果安装成功,插件状态将显示为绿色。安装完成后,需要重启IDEA。 通过以上步骤,就成功搭建了Gatling环境。现在可以开始编写Gatling脚本了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [性能工具之 Gatling 开发环境搭建](https://blog.csdn.net/zuozewei/article/details/119549040)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Gatling:环境搭建脚本录制脚本回放报告查看](https://blog.csdn.net/u014612889/article/details/102699957)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值