Weak network test? Fiddler captures packets to simulate a weak network test, a thorough...


foreword

1. Download the packet capture software fiddler

Official website: http://www.telerik.com/fiddler

This is software on the PC side. The process of simulating a weak network environment is roughly: the mobile APP uses a network proxy to proxy to our PC, and then all network requests will pass through the PC. At this time, we can restrict the network through fiddler to achieve The purpose of simulating a weak network environment.

Fiddler's main interface:

D1

2. Set up fiddler

Fiddler also needs to be set up, find the Tools function in the head, and then click the first function Options, and an interface will pop up:

D2

Find Connections and change the port to 8888. At this time, we can use our mobile phone to proxy to the computer.

D3

3. Set the Android device agent

Turn on our mobile phone and enter the wifi settings. It should be noted here that the wifi connected to the Android device must be the same network as our PC to set up successfully.

Most Android devices can set the proxy in the wifi settings, but it is not ruled out that there are a small number of devices that are limited by the system. Before setting the proxy, we need to know the ip address of the PC, which can be obtained through the system cmd command, and then ipconfig, as follows:

D4

Then you can set the proxy in the mobile phone, this is the interface of my mobile phone's wifi setting proxy:

D5

After setting, all network requests on the phone will be proxied to Fiddler and can be viewed:

D6

4. Set network restrictions

Go back to our fiddler and find Rules in the toolbar. It is obvious from the name what this function is used for. Then find Customize Rules in the Rules list, and something similar to a text editor will pop up at this time:

D7

In this text editor, use Ctrl+F to use the search function to search for keywords: simulate, and you can find the following code snippet:

if (m_SimulateModem) {
    
    
    // Delay sends by 300ms per KB uploaded.
    oSession["request-trickle-delay"] = "300"; 
    // Delay receives by 150ms per KB downloaded.
    oSession["response-trickle-delay"] = "150"; 
}

D8

Don’t worry about the rest of this code, you just need to know that request-trickle-delay represents the delay time of your network request, and response-trickle-delay represents the delay time of network response, in milliseconds.

The defaults here are 300 milliseconds and 150 milliseconds, so you only need to modify these two values ​​to simulate network delay and weak network environment. For example, you can modify the above two values: 2000 and 2000, which represent a network request delay of 2 seconds , the network response is delayed by 2 seconds:

if (m_SimulateModem) {
    
    
    // Delay sends by 300ms per KB uploaded.
    oSession["request-trickle-delay"] = "2000"; 
    // Delay receives by 150ms per KB downloaded.
    oSession["response-trickle-delay"] = "2000"; 
}

Remember to press Ctrl+S to save after making changes.

5. Turn on network delay

Then you can turn on the network delay, or in our Rules function, find Performance, and then you can see a Simulate Modems Speeds in the sub-options, select it, you're done, the network delay has been turned on, if you need to turn off the network delay, click again That's it.

6. Expand weak network rules

Maybe we don't want a weak network environment all the time in the test, but a random strong and weak network, which is more appropriate for our real situation, then we can modify the above code as follows:

static function randInt(min, max) {
    
    
    return Math.round(Math.random()*(max-min)+min);
}
if (m_SimulateModem) {
    
    
    // Delay sends by 300ms per KB uploaded.
    oSession["request-trickle-delay"] = ""+randInt(1,2000);
    // Delay receives by 150ms per KB downloaded.
    oSession["response-trickle-delay"] = ""+randInt(1,2000);
}

The randInt(1,2000) here should be well understood, representing a random integer from 1-2000, so that there will be occasional delays and occasionally good network conditions.

The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled

1. From entry to mastery of Python programming

Please add a picture description

2. Interface automation project actual combat

Please add a picture description

3. Actual Combat of Web Automation Project

Please add a picture description

4. Actual Combat of App Automation Project

Please add a picture description

5. Resume of first-tier manufacturers

Please add a picture description

6. Test and develop DevOps system

Please add a picture description

7. Commonly used automated testing tools

Please add a picture description

Eight, JMeter performance test

Please add a picture description

9. Summary (little surprise at the end)

Every effort is the strength to forge ahead, and every struggle is an opportunity to win the future. Believe in your own potential and bravely pursue your dreams. Only by constantly surpassing yourself can you bloom your own brilliance. Persevere and create your wonderful life!

Struggle is the melody of life, and the drum beats in the heart. Go forward bravely, go beyond the limit, and water the flowers of dreams with sweat. Not afraid of setbacks, not afraid of failure, believe in yourself, and pursue excellence. Stick to the original intention, overcome difficulties, and finally start the journey to glory!

The meaning of life lies in pursuit, and struggle is the power that gives it brilliance. Regardless of the starting point, firm belief and unremitting efforts will ignite the fire of hope and bloom brilliant flowers.

Guess you like

Origin blog.csdn.net/csdnchengxi/article/details/131918662