2013-12-11 77 views
0

我使用了以下完美工作的代碼。但har文件不會在指定位置生成。無法在使用ruby的硒webdriver中獲取HAR文件

 profile = Selenium::WebDriver::Firefox::Profile.new 
     profile.add_extension("../resources/[email protected]") 
     profile.add_extension("../resources/[email protected]") 

     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) 

請讓我知道什麼是錯誤的,我code.Or是存在的,我需要安裝任何新的寶石。 在此先感謝。

+0

你嘗試定義完整路徑字符串HAR文件? –

+0

是的,我也試過全路徑,但它不工作。 – testing

回答

2

更換

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

通過

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