我知道您可以加载现有的 Firefox 配置文件,或者使用 selenium-webdriver gem 中的 Ruby Bindings 创建一个配置文件,如下所述:
http://code.google.com/p/selenium/wiki/RubyBindings
然后使用add_extension
将任意数量的 Firefox 扩展添加到实例中,但是然后呢?测试期间不会出现我正在使用的扩展程序的窗口。我如何使用扩展程序?
有没有办法让驱动程序打开 Firefox 时默认打开扩展程序?
这是我正在使用的代码:
#!/usr/bin/env ruby
require "rubygems"
require "selenium-webdriver"
default_profile = Selenium::WebDriver::Firefox::Profile.from_name "default"
default_profile.add_extension("/Users/******/Library/Application Support/Firef\
ox/Profiles/wvon3h99.default/extensions/{9c51bd27-6ed8-4000-a2bf-36cb95c0c947}.\
xpi")
driver = Selenium::WebDriver.for(:firefox, :profile => default_profile)
driver.navigate.to "http://google.com"
element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit
puts driver.title
driver.quit
这取决于扩展。通常,在创建 FF 配置文件时,可以通过设置适当的属性(可以在 about:config 中找到的属性)在某种程度上控制扩展的行为。例如,要在 FF 启动后默认打开 Firebug 窗口,我将在代码中包含以下行:
default_profile["extensions.firebug.allPagesActivation"] = true
我使用的扩展通常具有某种自动导出功能,可以自动将数据发送到服务器或将其保存在磁盘上。恐怕无法使用 WebDriver 控制扩展,因此并非所有扩展都可用于自动化测试。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)