本文介绍了硒与Firefox离线模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使selenium(网络自动化测试框架)在离线模式下与firefox一起使用.

I am trying to make selenium (web automation test framework) work with firefox in offline mode.

我在这里发现了这一点,其中提到了使用火狐素轮廓开始硒.

I found this here, which mentions starting selenium with a firefox profile.

在Firefox中以脱机模式运行Selenium RC测试

这正是我所追求的,但是我缺少的部分是如何使Firefox配置文件以离线模式启动?

This is exactly what I am after, but the part I am missing is how to make a firefox profile start in offline mode?

我要这样做的原因是我正在使用新的HTML5功能,以允许我的应用程序脱机运行.

The reason I am wanting to do this is I am using the new HTML5 functionality to allow my application to run offline.

或者可以用Watin来完成这种事情吗?

Alternative can this kind of thing be done with Watin?

推荐答案

有点难看,但是可行的解决方法是在配置文件中设置一个不存在的代理.代码:

A bit ugly, but working workaround is to set a non existing proxy in profile. Code:

String surelyNotExistingProxyAddress="192.168.100.100:7777";
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(surelyNotExistingProxyAddress)
     .setFtpProxy(surelyNotExistingProxyAddress)
     .setSslProxy(surelyNotExistingProxyAddress);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);

WebDriver webDriver = new FirefoxDriver(cap);

然后,这个Firefox肯定不会从互联网上加载任何内容.

Then this firefox will load surely nothing from the internet.

这篇关于硒与Firefox离线模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 12:17