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, some pages take forever to load and I want to block them to speed up test execution.
However, I am stuck on implementing that solution via BrowserMob in Robot Framework. Can anyone help?
So far, I have this code:
Start Browser
## Init BrowserMob Proxy
${BMPATH} Join Path ${EXECDIR} browsermob-proxy-2.1.4 bin browsermob-proxy.bat
&{bmphost} Create Dictionary address=127.0.0.1 port=7070
Start Local Server ${BMPATH}
# Create dedicated proxy on BrowserMob Proxy
&{host} Create Dictionary address=127.0.0.1 port=7070
${BrowserMob_Proxy}= Create Proxy ${host}
#Blacklist URLS
Blacklist https://.*\\.google.com/.* 404
## Configure Webdriver to use BrowserMob Proxy
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${options} add_argument --proxy\=127.0.0.1:7070
#${proxy1}= Evaluate sys.modules['selenium.webdriver'].Proxy() sys, selenium.webdriver
#${proxy1.http_proxy}= Set Variable localhost:8888
Create WebDriver Chrome chrome_options=${options} #proxy=${BrowserMob_Proxy}
Go to https://www.google.com
The goal was to translate this selenium/java code:
private WebDriver initializeDriver() throws Exception {
// Start the server and get the selenium proxy object
ProxyServer server = new ProxyServer(proxy_port); // package net.lightbody.bmp.proxy
server.start();
server.setCaptureHeaders(true);
// Blacklist google analytics
server.blacklistRequests("https?://.*\\.google-analytics\\.com/.*", 410);
// Or whitelist what you need
server.whitelistRequests("https?://*.*.yoursite.com/.*. https://*.*.someOtherYourSite.*".split(","), 200);
Proxy proxy = server.seleniumProxy(); // Proxy is package org.openqa.selenium.Proxy
// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
// start the driver ;
Webdriver driver = new FirefoxDriver(capabilities);
return driver;
The code I have now, creates the server, the proxy and opens the chrome browser but fails to blacklist google.com and opens the page anyway. Tried multiple regexp expressions, all failed but I think that the error is made somewhere before that, either in the way of creating the proxy/server or the way to blacklist URL is not right.
Has anyone had success implementing this solution in RF? Can someone tell me what I'm missing?
Thanks