URL blacklisting with BrowserMobProxy in Robot Framework/Selenium?

前端 未结 1 1868
别那么骄傲
别那么骄傲 2021-01-27 03:42

I\'m using RobotFramework with Selenium library for writing automated test cases for various websites. I\'ve encountered an issue where due to slow loading from third-party URLs

相关标签:
1条回答
  • 2021-01-27 04:10

    For anyone who might need this, the solution is below:

    Start Browser
        [Documentation]    Start browser
        Set Selenium Implicit Wait    10
        ${BMPATH}    Join Path    ${EXECDIR}    browsermob-proxy-2.1.4    bin    browsermob-proxy.bat
        Start Local Server    ${BMPATH}
        ## Create dedicated proxy on BrowserMob Proxy
        &{host}    Create Dictionary    port=7070  
        ${BrowserMob_Proxy}=    Create Proxy    ${host}
        Blacklist    .*\/\/.*google.*    200
        ## Configure Webdriver to use BrowserMob Proxy
        ${options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
        Call Method    ${options}    add_argument    --start-maximized
        Call Method    ${options}    add_argument    --proxy-server\=localhost:7070
        Create WebDriver    Chrome    chrome_options=${options}

    This will start the chrome browser maximized and route traffic via BMP. The regex in the Blacklist line means it will block all URL containing 'google' and return status 200 (this can be changed at your will).

    0 讨论(0)
提交回复
热议问题