使用ruby无法在selenium webdriver中获取HAR文件

时间:2013-12-11 13:07:36

标签: ruby rubygems selenium-webdriver

我使用了以下完美运行的代码。但是在指定位置没有生成har文件。

        profile = Selenium::WebDriver::Firefox::Profile.new
        profile.add_extension("../resources/firebug@software.joehewitt.com.xpi")
        profile.add_extension("../resources/netexport@getfirebug.com.xpi")

        profile['app.update.enabled']= false
        #Setting Firebug preferences
        profile['extensions.firebug.currentVersion'] = "1.12.5"
        profile['extensions.firebug.addonBarOpened'] =true
        profile['extensions.firebug.console.enableSites'] = true
        profile['extensions.firebug.script.enableSites'] =true
        profile['extensions.firebug.net.enableSites'] =true
        profile['extensions.firebug.previousPlacement'] =
        profile['extensions.firebug.allPagesActivation'] ="on"
        profile['extensions.firebug.onByDefault'] =true
        profile['extensions.firebug.defaultPanelName'] ="net"
        #Setting netExport preferences
        profile['extensions.firebug.netexport.alwaysEnableAutoExport']= true
        profile['extensions.firebug.netexport.autoExportToFile']= true
        profile['extensions.firebug.netexport.Automation']= true
        profile['extensions.firebug.netexport.showPreview']= false
        profile['extensions.firebug.netexport.defaultLogDir']= "../har_file"
        profile['update_preferences']= true
        $driver = Selenium::WebDriver.for :firefox, :profile => profile
        sleep 15
        $driver.get "https://www.google.com"
        sleep 15

这是我的本地宝石列表

*** LOCAL GEMS ***

addressable (2.3.5)
bigdecimal (1.1.0)
bundler (1.3.5)
childprocess (0.3.9)
diff-lcs (1.2.5)
ffi (1.9.3 x86-mingw32)
har (0.0.9)
io-console (0.3)
jschematic (0.1.0)
json (1.8.1, 1.6.8, 1.5.5)
launchy (2.4.2)
mime-types (2.0)
minitest (2.5.1)
multi_json (1.8.2)
net-http-persistent (2.9)
pathological (0.3.0)
rake (0.9.2.2)
rdoc (3.9.5)
rest-client (1.6.7)
rr (1.0.5)
rspec (2.14.1)
rspec-core (2.14.7)
rspec-expectations (2.14.4)
rspec-mocks (2.14.4)
rubyzip (1.0.0)
selenium-webdriver (2.37.0)
simplecov (0.6.4)
simplecov-html (0.5.3)
websocket (1.0.7)

请让我知道我的代码中有什么错误。或者我是否需要安装任何新宝石。 提前谢谢。

1 个答案:

答案 0 :(得分:2)

替换

profile['extensions.firebug.netexport.defaultLogDir']= "../har_file"

通过

profile['extensions.firebug.netexport.defaultLogDir']= (File.join(Dir.pwd, '../har_file')).gsub('/', '\\')