Robot framework - chromedriver - set throtlling

Hi,

i tried create TC where i need set download speed for expected result. In developers tools i can switch to “Slow 3G”, but i dont no how same set from code.

can it be set? and if yes, can i set after open browser?

or if must set before open browser, how i can add to my code:

${chrome_options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
Call Method  ${chrome_options}  add_argument  --disable-infobars
Call Method  ${chrome_options}  add_argument  --allow-running-insecure-content
Call Method  ${chrome_options}  add_argument  --disable-useautomationextension
Call Method  ${chrome_options}  add_argument  --verbose
Call Method  ${chrome_options}  add_experimental_option  useAutomationExtension  ${FALSE}

${excluded}    Create List      enable-automation  
Call Method  ${chrome_options}  add_experimental_option  excludeSwitches  ${excluded}

${prefs}    Create Dictionary   credentials_enable_service=${false}
set to dictionary       ${prefs}        download.default_directory=${download_folder}
Call Method  ${chrome_options}    add_experimental_option    prefs    ${prefs}

Create WebDriver      Chrome       chrome_options=${chrome_options}

robotframework 5.0
selenium 4.1.3
chromedriver 101

Hi, @pilny.tomas! It’s quite a long time passed from your question. Have you had a chance to get proper fix outside?

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