Interface test-record har file

Source: Internet
Author: User

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.

    • Web Proxy [HTTP]

    • Secure Web Proxy (HTTPS)

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

SwitchySharpPlug-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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.