当前位置:网站首页>Interface automation test postman+newman+jenkins
Interface automation test postman+newman+jenkins
2022-07-25 17:11:00 【wangmcn】
Interface automation testing Postman+Newman+Jenkins
Catalog
- 1、 brief introduction
- 2、 Installation and deployment
- 2.1、Postman
- 2.2、Newman
- 2.2.1、 install Node.js
- 2.2.2、 install Newman
- 2.3、Jenkins
- 2.3.1、 install JDK
- 2.3.2、 install Tomcat
- 2.3.3、 install Jenkins
- 3、Postman Create script
- 3.1、 Create test set
- 3.2、 Create environment variables
- 3.3、 Create test cases
- 3.4、 Export script
- 4、Newman Execute the script
- 5、Jenkins Continuous integration
- 5.1、 Create project
- 5.2、 Perform project
- 5.3、 solve HTML The report says it's not OK
1、 brief introduction
Postman Can do interface testing , Easy to use, easy to use . However, due to the increasing number of interfaces in the project , Click manually every time you execute , It makes the implementation not very flexible .
Newman yes Postman Command line tools for , Executable Postman Derived .json Script files . Although the script can be executed with commands , However, it is impossible to specify a certain time period for automatic execution , You still have to knock the order manually , Still not flexible enough .
Jenkins It can realize automatic continuous integration and other operations .
So this explanation adopts Postman+Newman+Jenkins To realize interface automated testing .
2、 Installation and deployment
stay Windows Environmental Science (64 position ) Next, install and deploy .
This interface request link uses moco Generate .
As shown in the figure : Need to use moco Bao He Json The configuration file ( Configuration complete ).
start-up moco service :
open moco In the directory , Double click the mouse to start moco service .bat File can .
As shown in the figure :moco Service is open , You can use the interface to request links .
2.1、Postman
Postman Is a powerful web debugging and sending pages HTTP Requested tools .
Postman Can send any type of HTTP request (GET、HEAD、POST、PUT etc. ), With any number of parameters and HTTP headers. Support different authentication mechanisms (basic、digest、OAuth), The received response syntax is highlighted (HTML、JSON or XML).
Postman You can use Chrome Browser plug-ins exist in the form of , It can also be a stand-alone application .
Official website :https://www.getpostman.com/
This article uses Postman For client version , Will download completed Postman The default installation is enough .
2.2、Newman
Newman yes Postman Command line tools for . It allows you to easily run and test directly from the command line Postman aggregate . It is built with scalability in mind , So you can easily integrate it with the continuous integration server and build system .
Official website :https://www.npmjs.com/package/newman
2.2.1、 install Node.js
To run Newman, You need to install Node.js.
Double click execute node-v10.13.0-x64.msi The application can be installed by default .
After installation , Environment variables are automatically added to the system , Open the command line directly , Input node -v, Prompt the following information indicates Node.js Installation successful .
Thanks to the new edition of Node.js It's integrated npm, Also type... On the command line npm -v, To test whether the installation was successful .
2.2.2、 install Newman
Open the command line , Enter the installation command npm install -g newman
After input npm view newman version perhaps newman -v, You can check the installed version number .
2.3、Jenkins
Jenkins It's a use. Java Write open source continuous integration tool . With the Oracle After a dispute , The project from Hudson Project reproduction .
Jenkins Provides continuous integration services for software development . It runs in Servlet In the container ( for example Apache Tomcat). It supports software configuration management (SCM) Tools ( Include AccuRev SCM、CVS、Subversion、Git、Perforce、Clearcase and RTC), Can be executed based on Apache Ant and Apache Maven Project , And whatever Shell Scripts and Windows Batch command .Jenkins The main developers are Kawaguchi .Jenkins Is in MIT Free software released under license .
There are various ways to trigger a build . For example, it is triggered when it is submitted to version control system , It can also be done through a similar Cron Mechanism scheduling , Or when other builds have been completed , You can also pass a specific URL For the request .
Official website :https://jenkins.io/
2.3.1、 install JDK
Jenkins The required environment is Java, So you need to install the configuration first JDK.
2.3.1.1、 install
Execute jdk-8u171-windows-x64.exe.
JDK The installation path can be installed by default , Install here to D:\Java\jdk1.8.0_171 Under the table of contents ;
JRE The installation path can be installed by default , Install here to D:\Java\jre1.8.0_171 Under the table of contents ;
Then wait until the installation is completed .
2.3.1.2、 Configure environment variables
Right click my computer with the mouse , Click properties ---> Advanced system setup ---> senior ---> environment variable .
Click environment variable , In the system variable :
(1) Click New
Variable name filling CLASSPATH
Variable value filling .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar(2) Click New
Variable name filling JAVA_HOME
Variable value filling D:\Java\jdk1.8.0_171(3) modify Path, Click edit
Add... At the end of the variable value ;%JAVA_HOME%\bin;%JAVA_HOME%\jre\binafter , Open the command line , Input java -version, Prompt the following information indicates JDK Environment variable configuration succeeded .
2.3.2、 install Tomcat
Because of the download Jenkins The format is .war, So you need to install the configuration Web The server (Tomcat).
2.3.2.1、 install
Download the downloaded apache-tomcat-8.5.32-windows-x64.zip Extract the file , for example : Unzip to D Under the root directory .
2.3.2.2、 Configure environment variables
Right click my computer with the mouse , Click properties ---> Advanced system configuration ---> senior ---> environment variable .
Click environment variable , In the system variable :
(1) Click New
Variable name filling CATALINA_BASE
Variable value filling D:\apache-tomcat-8.5.32(2) Click New
Variable name filling CATALINA_HOME
Variable value filling D:\apache-tomcat-8.5.32(3) modify Path, Click edit
Add... At the end of the variable value ;%CATALINA_HOME%\lib;%CATALINA_HOME%\binafter , Open the command line , Input version, Prompt the following information indicates Tomcat Environment variable configuration succeeded .
2.3.2.3、 Modify service port
By default ,Tomcat The port of is 8080, But sometimes the port will be occupied , So at this time, we need to modify the port .
open Tomcat Install under directory conf Folder , There's a server.xml file , Modify the port value . As shown in the figure : take port Value is modified to 8081, Then the access port is 8081.
2.3.2.4、 Solve the memory overflow
When Jenkins Deployed in Tomcat In time , Use Jenkins It takes a lot of resources , May make Tomcat Memory overflow occurs .
terms of settlement :
open Tomcat Install under directory bin Folder , There's a catalina.bat file , Modify this file .
Modify the setting parameters :
-Xms: Initial heap memory size ;
-Xmx: Maximum heap memory size , General Settings -Xms And -Xmx The same size , Determine the size of both according to the application type and physical memory size ;
-Xmn perhaps -XX:NewSize: The size of the younger generation of heap memory ;
-XX:PermSize: Initial size of permanent generation memory ;
-XX:MaxPermSize: Maximum value of permanent generation memory .for example : according to Jenkins The memory of the server is 8G For example , stay catalina.bat Add parameters in the first line of the file :
set JAVA_OPTS=-Xmx2560m -Xms2560m -Xmn1024m -XX:PermSize=1024m -XX:MaxNewSize=512m -XX:MaxPermSize=1024mAs shown in the figure : The modified catalina.bat file .
2.3.2.5、 Create a startup service file
open Tomcat Install under directory bin Folder , There's a startup.bat file , Double click directly to run ,Tomcat The service starts .
But every time it starts Tomcat You need to enter the installation directory to execute files , It's a bit of a hassle , So creating a shortcut to start the service can solve this troublesome operation .
stay Tomcat Create in the installation directory “ start-up Tomcat.bat” file .
start-up Tomcat.bat The contents of the document :
start cmd /c "cd %cd%&&cd bin&&startup.batSelect Start Tomcat.bat Right click on the file , Create a desktop shortcut .
As shown in the figure : start-up Tomcat.bat Shortcut creation completed .
Double click this shortcut on the desktop , Automatically open the command window , start-up Tomcat Service complete .
Access address :
http://localhost:8081/ perhaps http://10.53.29.69:8081/(IP by 10.53.29.69)
2.3.3、 install Jenkins
2.3.3.1、 install
Download the downloaded jenkins.war File copy to Tomcat Install under directory webapps Directory .
Double click Run to start Tomcat.bat file .
Access address :
http://localhost:8081/jenkins
perhaps http://10.53.29.69:8081/jenkins(IP by 10.53.29.69)
Unlock first Jenkins, Conduct password input verification .
visit C:\Users\admin\.jenkins\secrets Under the table of contents , open initialAdminPassword file , Enter the password into the administrator password input box , Then click continue .
Click to install the recommended plug-ins .
Plug in installation ( Because of the domestic network problems , Some plug-ins may fail to install , First of all FANQIANG, Then install the plug-in ).
It is recommended that after the plug-in installation , Create administrator information , Then click save and finish .
Set up Jenkins URL, As shown in the figure :
http://10.53.29.69:8081/jenkins(IP by 10.53.29.69), Then click save and finish .
Jenkins Installation is complete , Click to start using Jenkins.
Jenkins Start up . As shown in the figure : The interface after login .
2.3.3.2、 Solve the Chinese garbled code
When Jenkins Deployed in Tomcat In time , perform Jenkins,Jenkins The console will display garbled code when outputting Chinese .
terms of settlement :
(1) The local system adds environment variables .
Right click my computer with the mouse , Click properties ---> Advanced system configuration ---> senior ---> environment variable .
Click environment variable , In the system variable :
Click New
Variable name filling JAVA_TOOL_OPTIONS
Variable value filling -Dfile.encoding=UTF-8(2) open Tomcat Install under directory bin Folder , There's a catalina.bat file , Modify this file .
Search for :
set "JAVA_OPTS=%JAVA_OPTS% -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
add to :
-Dfile.encoding=UTF-8
After modification :
set "JAVA_OPTS=%JAVA_OPTS% -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dfile.encoding=UTF-8"As shown in the figure : The modified catalina.bat file .
(3)Jenkins Configure environment variables .
System management ---> System settings ---> Global properties , Select the environment variable , Add the corresponding key value pair .
key JAVA_TOOL_OPTIONS value -Dfile.encoding=UTF-8
key LANG value zh.CH.UTF-8As shown in the figure :
2.3.3.3、 Installing a plug-in
plug-in unit (HTML Publisher) Release HTML The report . Search for HTML Publisher, Select and install directly .
3、Postman Create script
Interface to be tested :
Interface 1:
http://localhost:8083/getdemo?username=admin&password=123456
GET request ,2 Parameters username、password
The returned data is admin,123456
Interface 2:
http://localhost:8083/postdemo
POST request ,2 Form parameters username、password
The returned data is admin,123456
3.1、 Create test set
open Postman, Click on File--->New--->Collection, Create test set (Demo).
As shown in the figure : Test set Demo The creation is complete .
3.2、 Create environment variables
Set test URL Is a public variable , Click on Manage Environments.
Create environment variables (Test), Add a variable named Url, Variable value is http://localhost:8083, Click on Add add to .
3.3、 Create test cases
Interface 1(Get request )
Interface 2(Post request )
3.4、 Export script
1、 Export test set .
Select the use case set (Demo), Click on Export.
Default choice , Click on Export.
As shown in the figure : Export succeeded , The test set is .json file .
2、 Export environment variables .
Click on Manage Environments.
Choose environment variables (Test), Click on Download Environment.
As shown in the figure : Export succeeded , The environment variable is .json file .
4、Newman Execute the script
The command line window switches to the exported script directory , Enter the execution command :
newman run Demo.postman_collection.json -e Test.postman_environment.json --reporters cli,html --reporter-html-export TestReport.htmlParameters :
run function newman The order of ;
-e Load data of environment variables ;
--reporters cli,html Specify the type of report generated ;
TestReport.html Generated html Report name .As shown in the figure : The result of command line execution .
The script is finished , Generated html The report (TestReport.html).
Click on the open TestReport.html The report , Display report content .
Be careful : Enter the execute script command to generate html The report , If prompt html Report could not be loaded .
As shown in the figure :
You need to install html Report module , Enter the command npm install -g newman-reporter-html Can be installed .
5、Jenkins Continuous integration
5.1、 Create project
Click new task .
Enter a task name ( for example Test_Demo), Choose to build a free style software project , Click ok .
structure , Add build steps ( perform Windows Batch command ).
Enter the execution command ( Report output to test-report Directory ):
newman run D:\test\Demo.postman_collection.json -e D:\test\Test.postman_environment.json --reporters cli,html --reporter-html-export .\test-report\TestReport.htmlPost-build operation , Add post build steps (Publish HTML reports). Release HTML The report .
Save it at last .
You can also set source code management (Git、svn), Add scheduled build 、 polling SCM, Send email and other settings .
5.2、 Perform project
Click the build button , Perform project .
Then the execution progress status bar appears in the lower left corner .
Entry project , You can view the historical construction .
Click the console output to view the log during the construction execution .
You can view the test report (HTML).
As shown in the figure : Open test report , Display report content .
5.3、 solve HTML The report says it's not OK
1、 problem :
(1) As shown in the figure : Test report of the project (HTML Report) by .html Format .
(2) Open and find that the report display format is incorrect .
2、 solve :
(1) System management ---> Script command line .
(2) Enter the following parameters , Click on the run .
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")(3) Execute the script again , View the newly generated test report , As shown in the figure : According to the normal .
边栏推荐
- 01.两数之和
- 生成扩散模型漫谈:DDPM = 贝叶斯 + 去噪
- [book club issue 13] +ffmpeg video capture function
- Mindoc makes mind map
- 气数已尽!运营 23 年,昔日“国内第一大电商网站”黄了。。。
- 2022 latest Beijing Construction welder (construction special operation) simulation question bank and answer analysis
- 如何使用 4EVERLAND CLI 在 IPFS 上部署应用程序
- Getting started with easyUI
- 基于SqlSugar的开发框架循序渐进介绍(13)-- 基于ElementPlus的上传组件进行封装,便于项目使用
- Rebudget汇报PPT
猜你喜欢

Add batch delete

Wu Enda logistic regression 2
![[mathematical modeling and drawing series tutorial] II. Drawing and optimization of line chart](/img/73/2b6fe0cf69fa013894abce331e1386.png)
[mathematical modeling and drawing series tutorial] II. Drawing and optimization of line chart

ACL 2022 | 基于最优传输的对比学习实现可解释的语义文本相似性
![[OBS] Reprint: what about the serious delay of OBS live broadcast and Caton?](/img/fd/54fcae2bc3f4313e9401c735ef74b8.png)
[OBS] Reprint: what about the serious delay of OBS live broadcast and Caton?

win10如何删除微软拼音输入法

【目标检测】YOLOv5跑通VisDrone数据集

Rebudget汇报PPT

QT listview list display component notes

Budget report ppt
随机推荐
【目标检测】YOLOv5跑通VisDrone数据集
[Nanjing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
How to install govendor and open a project
Postdoctoral recruitment | West Lake University Machine Intelligence Laboratory recruitment postdoctoral / Assistant Researcher / scientific research assistant
stm32F407------SPI
WPF implements user avatar selector
Why 4everland is the best cloud computing platform for Web 3.0
From digitalization to intelligent operation and maintenance: what are the values and challenges?
超越 ConvNeXt、RepLKNet | 看 51×51 卷积核如何破万卷!
01.两数之和
Sogou batch push software - Sogou batch push tool [2022 latest]
【知识图谱】实践篇——基于医疗知识图谱的问答系统实践(Part4):结合问题分类的问题解析与检索语句生成
在华为昇腾Ascend910上复现swin_transformer
Page table cache of Linux kernel source code analysis
02. Add two numbers
Outlook tutorial, how to search for calendar items in outlook?
理财有保本产品吗?
动态规划题目记录
04.寻找两个正序数组的中位数
Hcip notes 12 days