`

Webdriver使用自定义Firefox Profile运行测试

阅读更多

一般我们使用如下代码启动Firefox:

WebDriver driver = new FirefoxDriver()

 这样Selenium Server启动的Firefox将是一个全新的,不安装任何Add-On的Firefox.

 

如果有需要,我们可以使用我们自己指定的,带有特定配置的Firefox.步骤如下

  1. 运行CMD,打开Firefox的 Profile manager
  2. 点击"Create Profile...",完成步骤,包括输入Profile名字
  3. 点击"Start Firefox"
  4. 在新启动的Firefox中安装自己所需要的Add-On或者做其他配置


 

最后,在代码中使用如下方式启动FirefoxDriver:

ProfilesIni allProfiles = new ProfilesIni();
// "Selenium" is the new profile just created
FirefoxProfile profile = allProfiles.getProfile("Selenium");
WebDriver driver = new FirefoxDriver(profile);

 

我在Selenium profile中安装了Firebug,然后使用脚本启动这个Profile,就能看到安装的Firebug了.

另外我们可以看到Manager里面有个default,这个就是我们自己平时使用的Firefox Profile,也是可以在代码中使用的.

 

本文出自"lijingshou"博客,转载请务必保留此出处http://lijingshou.iteye.com/blog/2085276

  • 大小: 24.8 KB
分享到:
评论

相关推荐

    为firefox创建其他的配置文件

    在自动化测试领域,特别是使用Selenium进行Web应用测试时,有时需要为Firefox浏览器创建不同的配置文件(profile)。这通常是为了隔离测试环境,确保每次测试都在一个干净的环境中运行,避免测试之间的相互干扰。此外...

    selenium2.44 java + Firefox 33

    2. Firefox Profile:可以自定义Firefox配置,比如设置代理、禁用插件,以适应不同的测试需求。 3. 元素定位策略:如XPath、CSS选择器、ID、Name等,用于在网页上找到特定的HTML元素。 4. 断言和验证:用于检查预期...

    selenium设置proxy、headers的方法(phantomjs、Chrome、Firefox)

    from selenium.webdriver.firefox.firefox_profile import FirefoxProfile profile = FirefoxProfile() profile.set_preference('network.proxy.type', 1) profile.set_preference('network.proxy.http', '1.9.171....

    Selenium-server-2.0

    3. **Firefox Profile支持**:此版本支持自定义Firefox配置文件,这意味着你可以设置特定的浏览器插件、首选项,以模拟不同用户的浏览环境。 4. **HTML TestRunner增强**:HTML TestRunner是Selenium的一种测试结果...

    Selenium Python Bindings 2017年 新版 原版

    虽然不是必需的,但如果你计划使用远程 WebDriver 运行测试,就需要下载并启动 Selenium 服务器。这通常用于跨平台测试或者在没有图形界面的服务器上运行测试。 #### 二、入门指南 **2.1 简单用法** Selenium 的 ...

    selenium2.0

    - **配置 Firefox Profile**:通过 `FirefoxProfile` 类自定义 Firefox 的配置。 #### 第5章 封装与重用 - **封装**:将常用的 WebDriver 操作封装成函数或类,提高代码的可维护性和重用性。 - **重用**:利用已有...

Global site tag (gtag.js) - Google Analytics