5.4.2 使用配置启动firefox

  什么是firefoxprofile?简单的来说就是个人定制,比如你设置自己访问主页,禁用加载图片这些个性化的设置,都可以保存到一个文件夹下,就是firefoxprofile,下次使用时候,加载该firefoxprofile,就可以让自己火狐浏览器设置跟之前配置一样。

  为什么selenium要用firefoxprofile?我们自动化测试的时候,有时不需要图片加载出来,提高浏览器加载速度,从而提高脚本的执行速度。另外在一些网络比较差的环境下,禁用css、图片等加载可以提高访问速度

1.使用firefox的本地配置加载浏览器

使用本地配置加载浏览器,代码如下。

5.4.2 使用配置启动firefox

这样运行后,可以看到firebug等插件都已启动。

练习:假设做性能测试时,需要获取某个状况下的页面网络运行参数。要求完成相应练习,加载浏览器后,自动打开firebug的网络选项卡,并导出har文件到指定文件夹中。

5.4.2 使用配置启动firefox

5.4.2 使用配置启动firefox

1)安装插件netExport(下载),会在firebug面板中生成导出按钮。导出后的har文件,可以使用httpWatch(下载)查看。

2)firebug的网络选项卡自动打开

可在firefox中的about:config页面中,找到allPagesActivation属性为on,进行如下配置。

5.4.2 使用配置启动firefox

3)网络日志自动导出

 --导出地址设置

5.4.2 使用配置启动firefox

--点亮导出绿灯的设置,自动保存har设置

5.4.2 使用配置启动firefox

--在代码最后加上refresh,如下

5.4.2 使用配置启动firefox

2.在机器B上启动机器A上的firefox配置

1)将机器A上的Profiles文件夹拷贝到files文件夹下

路径为“C:\Users\admin\AppData\Roaming\Mozilla\Firefox\Profiles\gehvgmfb.default"。

或者打开firefox浏览器,点击“帮助”并选择“故障排除信息”菜单项,以打开故障排除信息标签页。在“应用程序概要”部分,点击 显示文件夹 按钮,将打开一个窗口显示您的配置文件。

2)使用配置启动浏览器

5.4.2 使用配置启动firefox

3.启动firefox时设置profile

1)在firefox地址栏中输入about:config,可以看到有哪些参数可以设置

2)举例:设置浏览器下载文件的保存地址

5.4.2 使用配置启动firefox

4.启动firefox时加载插件

  首先,要知道我们为什么需要加载插件?原因是webdriver在启动浏览器时,启动的一个干净的没有任务、插件及cookies信息的浏览器(即使你本机的firefox安装了某些插件,webdriver启动firefox也是没有这些插件的),但是有可能被测系统本身需要插件或者需要调试等等,此时可以用如下方法在启动firefox时加载插件,下面示例加载firebug插件:

5.4.2 使用配置启动firefox
 1     public static void StartFireFoxLoadPlugin(){
2 System.out.println("start firefox browser...");
3 System.setProperty("webdriver.firefox.bin",
4 "D:/Program Files/Mozilla Firefox/firefox.exe");
5 File file = new File("files/firebug-2.0.7-fx.xpi");
6 FirefoxProfile profile = new FirefoxProfile();
7 try {
8 profile.addExtension(file);
9 } catch (IOException e) {
10 e.printStackTrace();
11 }
12 profile.setPreference("extensions.firebug.currentVersion", "2.0.7");
13 //active firebug extensions
14 profile.setPreference("extensions.firebug.allPagesActivation", "on");
15 WebDriver driver = new FirefoxDriver(profile);
16 driver.get("http://www.baidu.com");
17 System.out.println("start firefox browser succeed...");
18 }
5.4.2 使用配置启动firefox
上一篇:MySQL创建数据表


下一篇:飘逸的python - 保持命名空间的整洁