WebDriver driver = new FirefoxDriver(),其Selenium webDriver启动的FF是一个空的FF,和全新安装的浏览器一样

如果希望WebDriver启动的浏览器带有某些配置信息,如:代理,证书,cookies等,需要手动创建个带有希望信息的FF profile,然后初始化的时候作为参数传进来,方法如下:

开始-->运行(注意FF要全部关掉),输入: firefox -ProfileManager,会启动如下界面的对话框 --> 创建配置文件,假设名字是‘test2’--> 启动Fireofx, 然后在打开的浏览器里面设置代理,添加证书,等等操作。 

Web UI自动化测试框架搭建之十二: 启动自定义profile的WebDriver浏览器

ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffProfile = profile.getProfile("test2");

//test2是profile的名字,也可以传参,profile磁盘文件的file

如果用到DesiredCapabilities, 可以把profile加进capabilities中

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(FirefoxDriver.PROFILE, ffProfile);

wBrowserDriver = new FirefoxDriver(capabilities)

相关文章: