Sha256: 1172bd79d53b7166566ff6334ff04afc330b268a0783a6ef1b4e70d0cc5154c6
Contents?: true
Size: 1.41 KB
Versions: 5
Compression:
Stored size: 1.41 KB
Contents
require 'selenium/webdriver/support' module BrowserMob module Proxy # # WebDriver event listener that assumes the following: # # driver.get - new HAR # driver.click - new page # driver.navigate.back - new page # driver.navigate.forward - new page # class WebDriverListener < Selenium::WebDriver::Support::AbstractEventListener attr_reader :hars def initialize(client) @client = client @hars = [] end def reset @hars.clear end def before_navigate_to(url, driver) save_har unless @hars.empty? # first request @client.new_har("navigate-to-#{url}") end def before_navigate_back(driver = nil) name = "navigate-back" name << "-from-#{driver.current_url}" if driver @client.new_page name end def before_navigate_forward(driver = nil) name = "navigate-forward" name << "-from-#{driver.current_url}" if driver @client.new_page name end def before_click(element, driver) name = "click-element-#{identifier_for element}" @client.new_page name end def before_quit(driver) save_har end private def save_har @hars << @client.har end def identifier_for(element) # can be ovverriden to provide more meaningful info element.ref end end end end
Version data entries
5 entries across 5 versions & 1 rubygems