启动带有用户配置信息的FireFox浏览器

1)位火狐创建配置文件

      此步骤请参考http://jingyan.baidu.com/article/9f7e7ec079bff46f281554f0.html

2)在启动的浏览器中配置自己需要的配置项,比如加载FireBug之类,配置完成后关闭FireFox浏览器

3)使用Selenium调用配置好的profile文件,其中pi.getProfile("WebDriver")中的WebDriver为创建配置文件名,之后调用起来的firefox是添加了配置项的fireFox 

package com.testng.webdriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.testng.annotations.Test;

public class CreateFireProfile {
	WebDriver driver;
	String baseUrl;
	@Test
	public void testFirefoxProfile()
	{
		  
		//String profile_dir="C:\Users\Administrator\AppData\Roaming\Mozilla\Firefox\Profiles\br4sk518.WebDriver";
		System.out.println("start firefox browser...");
		System.setProperty("webdriver.firefox.bin", "C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
		ProfilesIni pi = new ProfilesIni();
		FirefoxProfile profile = pi.getProfile("WebDriver");
	    WebDriver driver = new FirefoxDriver(profile);
		driver.get("http://localhost:8080/Example1.html");
		System.out.println("start firefox browser succeed...");
		
	}

}

  

原文地址:https://www.cnblogs.com/xmmc/p/7586808.html