2013-03-08 41 views
5

外部URL我开始Seleniumlibrary测试玩(与robotframework运行),并为我们的网站有广告和指标等,我每次运行测试,这些网址得到加载。如何禁止装载上seleniumlibrary/robotframework

有没有办法告诉硒/ robotframework不加载的URL的特定类型或防止它加载外部资源(即不是从本地主机的一切)。

回答

8

你可以用browsermob-proxy来做到这一点。安装完成后,只需设置代理并设置黑名单即可。

ProxyServer server = new ProxyServer(9000) 
server.start(); 
final DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setCapability(CapabilityType.PROXY, server.seleniumProxy()); 
//Send a 200 for all requests to the facebook cdn 
server.blacklistRequests("http://.*\\.fbcdn.net/.*", 200); 
//Finish setting up your driver 
WebDriver driver = new SomeDriverImpl(capabilities); 

我相信以下将与this python wrapper工作(正则表达式可能会略有不同):

from browsermobproxy import Server 
server = Server("path/to/browsermob-proxy") 
server.start() 
proxy = server.create_proxy() 
proxy.blacklist('http://.*\\.fbcdn.net/.*', 200) 
from selenium import webdriver 
profile = webdriver.FirefoxProfile() 
profile.set_proxy(proxy.selenium_proxy()) 
driver = webdriver.Firefox(firefox_profile=profile) 
... 
proxy.stop() 
driver.quit() 
+0

你没有说明你正在使用哪种语言,所以我认为Java的。这是不正确的?快速搜索显示该库有很多用于python的包装器。 – Scott 2013-03-12 13:24:10

+0

对不起,是的,我正在使用python。感谢您的回应,一旦我尝试了它,标记就会有效! – gforcada 2013-03-13 14:32:37

+1

你不应该逃避fbcdn.net点,例如: 'server.blacklistRequests( “HTTPS://.* \\ \\ .fbcdn .NET /.*”,200);' – Lordalcol 2015-12-14 11:54:01