Jmeter- achieve identification verification code identification verification code implemented Jmeter-

 

Jmeter- achieve identification verification code

 

 

 

In doing automated testing or stress testing, verification code is always a problem. , Testing is generally performed in the past experience of stress tests in separate test environment, you can rest assured disable validation code or use a universal code, this is the most practical. However, these two days I tried to use a third-party graphic image recognition tools to identify and complete the verification code through Jmeter complete the login process, the limited recognition success rate identification tool, so Benpian estimated that only applies within the scope of the theory.

In this part of most of the content from the article: http: //blog.csdn.net/xreztento/article/details/48682923

The overall purpose : Jmeter to write a post-processor, in response to a request for the return of a picture identification codes into text, and stored as a parameter Jmeter identifying the content of the request parameter for the post login login verification, thereby automate the login process.

 

tool

 (1) third-party graphics image recognition tools: tesseract-ocr Download: http: //code.google.com/p/tesseract-ocr/downloads/list basically can not download, uploaded to my Baidu network disk

 After installation, you can try if the installation was successful in cmd:

 Entering commands cmd: tesseract d: \ 123.jpg result -l eng means is placed after the D drive 123.jpg identified under result.txt

 

 (2) the need to use the jar package:

 Jmeter plug-in development-related jar package: ApacheJmeter_core.jar jorphon.jar logkit-2.0.jar these have a direct import Jmeter's lib in the project to

 Graphics-related jar package: jai-imageio-1.1.jar next clip swingx-1.6.1.jar from the Internet, uploaded to Baidu cloud disk jar file

Plug-in Development

Java IDE with a new project, to achieve two parts, one is to identify the picture, a UI is part Jmeter plug-ins. Completion of the project directory:

ImageIOHelper.java
OCR.java
TestOCR.java
VodeExtractor.java
VcodeExtractorGUI.java

 

Plug-in generates

After the plug-in development is complete, Eclipse, export-Runnable jar file, the necessary dependencies added, will eventually generate a .jar file

Note: will complain (Jmeter will report a error: java.lang.IllegalArgumentException: vendorName == null) graphic jar packets directly related to the use of the Internet to find a final solution

After generating jar package, with the decompression tool to open the MANIFEST.MF file in / META-INF directory using an editor (I use Sublime) open, copy into the following piece of code, stored archive:

Copy the code
Specification-Title: Java Advanced Imaging Image I/O Tools
Specification-Version: 1.1
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: com.sun.media.imageio
Implementation-Version: 1.1
Implementation-Vendor: Sun Microsystems, Inc.
Copy the code

 

Plug insert Jmeter

The .jar file into the lib Jmeter installation path / ext / directory, restart Jmeter

It can be seen postprocessor VcodeExtractor our newly developed 

Look at roughly the login process test plan:

 

登录的post请求参数中,可以使用Vcode,Vcode是我们开发的后置处理器 VcodeExtrator 返回的从图片验证码中识别出来的字符串

 

插件效果验证

把测试计划跑一次  根据察看结果树  看下效果

 

登录请求成功啦,但是图片识别也不是百分百成功,部分失败情况下,登录请求肯定会失败。Tesseract-OCR也有训练识别的功能,但是不再继续研究了。

 

 

在做自动化测试或压力测试时,验证码总是一个问题。在以往的压力测试经历中,测试一般在独立的测试环境中进行,可以放心禁用验证码或使用万能验证码,这个是最实用的。但是,这两天我尝试了一个使用第三方的图形图像识别工具来完成验证码识别并通过Jmeter完成登录的过程,识别工具的识别成功率有限,因此本篇估计仅能在理论范围内适用。

本篇内容大部分内容来自于该作者的文章:http://blog.csdn.net/xreztento/article/details/48682923

总体目的:给Jmeter写一个后置处理器,用来将上一个请求响应返回的验证码图片识别成文字,并将识别内容保存为Jmeter的一个参数,这个参数供登录post请求进行登录验证,从而完成登录的自动化过程。

 

工具

 (1)第三方图形图像识别工具:tesseract-ocr  下载地址:http://code.google.com/p/tesseract-ocr/downloads/list  基本无法下载,已上传到我的百度网盘

 安装后,可以在cmd下试一试是否安装成功:

 在cmd下输入命令:tesseract d:\123.jpg result -l eng   意思是将D盘下的123.jpg 识别后放在result.txt下

 

 (2)需要用到的jar包:

 Jmeter插件开发相关的jar包: ApacheJmeter_core.jar jorphon.jar logkit-2.0.jar  这些在Jmeter的lib中都有 直接导入工程项目即可

 图形处理相关的jar包:jai-imageio-1.1.jar  swingx-1.6.1.jar  从网上下的,已上传到百度云盘 jar 文件夹下

插件开发

用java IDE新建一个工程项目,实现两个部分,一个是识别图片,一个是Jmeter插件的UI部分。工程项目完成目录为:

ImageIOHelper.java
OCR.java
TestOCR.java
VodeExtractor.java
VcodeExtractorGUI.java

 

插件生成

插件开发完成后,在Eclipse中 export-Runnable jar file ,将必要的依赖库加进去,最后会生成一个 .jar 文件

注意:图形相关的jar包  直接使用时会报错(Jmeter会报一个错:java.lang.IllegalArgumentException: vendorName == null) 最终在网上找到了解决方案

生成jar包后,用解压工具打开,将 /META-INF 目录下的 MANIFEST.MF 文件用编辑器(我用的是sublime)打开,拷贝进去下面一段代码,保存压缩包:

Copy the code
Specification-Title: Java Advanced Imaging Image I/O Tools
Specification-Version: 1.1
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: com.sun.media.imageio
Implementation-Version: 1.1
Implementation-Vendor: Sun Microsystems, Inc.
Copy the code

 

插件插入Jmeter

将 .jar 文件放入Jmeter 安装路径下 lib/ext/ 目录下,重启Jmeter

It can be seen postprocessor VcodeExtractor our newly developed 

Look at roughly the login process test plan:

 

post login request parameters may be used Vcode, Vcode we have developed is post-processor VcodeExtrator code string returned from the identified image verification

 

Verify plug-in effects

The test plan to run a tree facie effect according to the results View

 

Login successful request it, but the picture identification is not a hundred percent success, under partial failure, the login request will certainly fail. Tesseract-OCR are also trained to recognize features, but no further studied.

 

Guess you like

Origin www.cnblogs.com/wang001/p/10943402.html