Robot framework - chromedriver - set throtlling

Hi,

If you’re mentioning modify DevTools parameters as if you were in inspector, you can use execute_cdp_cmd (ChromeDevToolsProtocol) to set and modify options.
You have the commands here:

And here is an example I use to set my browser offline:

Offline Simulation
    ${seleniumlib}    Get Library Instance    SeleniumLibrary
    VAR    ${webdriver}    ${seleniumlib.driver}
    # Network tracking activation 
    ${network_init}    Create Dictionary
    Call Method    ${webdriver}    execute_cdp_cmd    Network.enable    ${network_init}
    # SetOffline
    VAR    ${novalue}    0
    ${novalue}    Convert to Integer    ${novalue}
    ${conditions}    Create Dictionary    offline=${True}    latency=${novalue}    downloadThroughput=${novalue}    uploadThroughput=${novalue}
    Call Method    ${webdriver}    execute_cdp_cmd    Network.emulateNetworkConditions    ${conditions}

The values are mainly built as dictionaries passed to the Call Method keyword, as I didn’t find out at the moment why passing them directly doesn’t work.
But the code above works.

Note you have to reactivate/disable what you set in the same instance then (for example here, set Offline False and usually disable tracking)

Regards
Charlie

3 Likes