Network throttling with chrome and selenium

后端 未结 7 1816
生来不讨喜
生来不讨喜 2020-12-08 09:40

Google Chrome 38 introduced the new \"Device Mode & Mobile Emulation\" functionality in devtools. In addition to choosing a device for emulation, it is also possible to

相关标签:
7条回答
  • 2020-12-08 10:36

    The API to control network emulation were added to ChromeDriver. And should be available for quite a while now. According to comment in the linked issue you should use version at least 2.26 because of some bugfix.

    According to Selenium changelog bindings are available for these languages:

    • JavaScript as of version 3.4.0 (commit)
    • Python as of version 3.5.0 (commit)
    • Ruby as of version 3.11.0 (commit)
    • C# as of version 4 (commit)

    If you need these binding in other languages you should probably open issue/contribute implementation similar to one of the above.

    Example usage from Python is below:

    driver.set_network_conditions(
        offline=False,
        latency=5,  # additional latency (ms)
        download_throughput=500 * 1024,  # maximal throughput
        upload_throughput=500 * 1024)  # maximal throughput
    
    0 讨论(0)
提交回复
热议问题