一、使用自定义Firefox Profile运行测试
1. 运行cmd,输入指令"C:\Program Files\Mozilla Firefox\firefox.exe" –ProfileManager,打开Firefox的Profile manager
2. 单击CreateProfile,创建一个新的Profile,名称为Test
3. 选择Test,点击Start Firefox
4. 在代码中启动Firefox浏览器时,使用以下方式:
ProfilesIni profilesIni = new ProfilesIni();
FirefoxProfile profile = profilesIni.getProfile("Test");
WebDriver driver = new FirefoxDriver(profile);
二、修改Firefox的config
打开浏览器,在Firefox地址栏中输入about:config,回车,修改以下参数:
network.automatic-ntlm-auth.trusted-uris
network.negotiate-auth.delegation-uris
network.negotiate-auth.trusted-uris
在其中输入需要进行Authentication验证的网址,多个网址用逗号分隔。这样firefox就可以像IE浏览器一样自动获取域用户信息了,不必再输入密码。
三、打开需要访问的页面
需要使用以下方式打开需要访问的页面:
String url = http://username:password@url
driver.get(url);
备注:以上方案是针对访问一个页面需要多个Authentication验证的情况。对于只需要一个验证的情况只使用步骤三即可。