If reproduced, please indicate the source and testerhome.com
Yesterday we used selenium automated way to obtain the Har file, today we find a common, do not understand the code of business testing can also record case of the way
Principle
The principle is to use the browsermob-proxy
executable as the local agent, listen to a port, and then set the proxy URL of the Web server in the system, so that every time the Web request to go to our local agent, so that the data will first save data on the proxy server, We get these har data through Restapi to local
Steps to start the agent service
At the end of the previous article, I explained how to install the boot browsermob-proxy
server, by default you have read that article, and now we start the Service, command for sh browsermob-proxy -port 9090
, after startup
If so, the information indicates that our service has been started, and remember the ports we have started, which will be used later.
Create an agent
After the agent service starts, the instance of the agent has not been created successfully, we need to create one ourselves, created by REST api
the way, the command for curl -X POST -d ‘port=9099‘ http://localhost:9090/proxy
, where the red box labeled as we just started the Proxy service port number, -d
the parameter is the 9099
port number of our agent, This must be understood clearly, after the command executes successfully returns a json
string containing the port
field that you set as the proxy port number.
After a successful creation, the following information is output on the server side:
Set up System Agent
Using Chrome
the browser to open proxy settings, I use mac
, will pop up the proxy settings
The web
two settings will be changed as follows, the information inside the server to install the display host
and port number to fill.
Remember to save after setting up, if you do not want to set up the system agent, see another plug-in proxy
Browser plugin Settings Agent
SwitchySharp
Plug-ins, adding to the chrome
configuration after
So when we tick, we can get the browser to go proxy.
Now when we visit the browser, we will find that the server is responding.
It is recommended to use the browser plugin to set up the proxy, which does not affect other Internet needs.
Create har for data logging
Now we open our proxy server, as well as open the 9099
port agent, and the browser proxy set to this 9099
port agent, now our network access will go 9099
this agent.
Turn on recording
Command: The curl -X PUT -d ‘initialPageRef=Doctorq‘ http://localhost:9090/proxy/9099/har
above command will be the name of the recorded case
page Doctorq
, so that I case
can find out, this Doctorq
command after the execution of our recording function has been opened, this time your request on the Web page, will be captured by our agent, The data will also be saved.
Get har Info
Command: curl http://localhost:9090/proxy/9099/har
, this time the command line output har
information:
If you feel that you are not seeing clearly, you can save it to a local file by:
This allows us to view information about the file in the Har view tool:
Ssl
For https
the request, you need to install the ssl
certificate yourself.
Interface test-record har file