Class: BrowserMob::CLI::BrowserMobSetup
- Inherits:
-
Object
- Object
- BrowserMob::CLI::BrowserMobSetup
- Defined in:
- lib/browsermob/cli/browsermob.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #browsermob_setting ⇒ Object
- #capture_traffic(url) ⇒ Object
- #capture_traffic_with_click(url, selector) ⇒ Object
- #chrome_profile_setup ⇒ Object
- #convert_to_yml ⇒ Object
- #download_browsermob_proxy ⇒ Object
- #firefox_profile_setup ⇒ Object
-
#initialize ⇒ BrowserMobSetup
constructor
A new instance of BrowserMobSetup.
- #setup ⇒ Object
- #show_har_data_browser ⇒ Object
- #teardown ⇒ Object
- #user_actions(url, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ BrowserMobSetup
Returns a new instance of BrowserMobSetup.
17 18 19 |
# File 'lib/browsermob/cli/browsermob.rb', line 17 def initialize @url = url end |
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
15 16 17 |
# File 'lib/browsermob/cli/browsermob.rb', line 15 def url @url end |
Instance Method Details
#browsermob_setting ⇒ Object
29 30 31 32 33 34 |
# File 'lib/browsermob/cli/browsermob.rb', line 29 def browsermob_setting binary = "/tmp/browsermob-proxy/bin/browsermob-proxy" server = BrowserMob::Proxy::Server.new(binary, port: 7676) server.start server.create_proxy end |
#capture_traffic(url) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/browsermob/cli/browsermob.rb', line 79 def capture_traffic(url) setup @proxy.new_har "google" @driver.get url har = @proxy.har all_requests = Proc.new do har.entries.each do |entry| puts "=====Request URL======\n" puts entry.request.url end end all_requests.call @har_file = File.new("/tmp/traffic.har", "w+") @proxy.new_har.save_to @har_file har.save_to @har_file teardown convert_to_yml show_har_data_browser end |
#capture_traffic_with_click(url, selector) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/browsermob/cli/browsermob.rb', line 99 def capture_traffic_with_click(url, selector) setup @proxy.new_har "google" @driver.get url @driver.find_element(css: selector).click sleep 3 har = @proxy.har all_requests = Proc.new do har.entries.each do |entry| puts "=====Request URL======\n" puts entry.request.url end end all_requests.call @har_file = File.new("/tmp/traffic.har", "w+") @proxy.new_har.save_to @har_file har.save_to @har_file teardown convert_to_yml show_har_data_browser end |
#chrome_profile_setup ⇒ Object
42 43 44 45 46 |
# File 'lib/browsermob/cli/browsermob.rb', line 42 def chrome_profile_setup proxy = Selenium::WebDriver::Proxy.new(:http => @proxy.selenium_proxy.http) @chrome_caps = Selenium::WebDriver::Remote::Capabilities.chrome(:proxy => proxy) @driver = Selenium::WebDriver.for(:chrome, :desired_capabilities => caps) end |
#convert_to_yml ⇒ Object
61 62 63 64 |
# File 'lib/browsermob/cli/browsermob.rb', line 61 def convert_to_yml yml = HarParser.new yml.parse_har_file end |
#download_browsermob_proxy ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/browsermob/cli/browsermob.rb', line 21 def download_browsermob_proxy FileUtils.rm_rf('/tmp/browsermob-proxy') if Dir.exists?("/tmp/browsermob-proxy") system('cd /tmp && wget https://github.com/lightbody/browsermob-proxy/releases/download/browsermob-proxy-2.1.0-beta-4/browsermob-proxy-2.1.0-beta-4-bin.zip') system("cd /tmp && unzip browsermob-proxy-2.1.0-beta-4-bin.zip") system("mv /tmp/browsermob-proxy-2.1.0-beta-4 /tmp/browsermob-proxy/") system("chmod +x /tmp/browsermob-proxy/bin/browsermob-proxy") end |
#firefox_profile_setup ⇒ Object
36 37 38 39 40 |
# File 'lib/browsermob/cli/browsermob.rb', line 36 def firefox_profile_setup firefox_profile_setup = Selenium::WebDriver::Firefox::Profile.new firefox_profile_setup.proxy = @proxy.selenium_proxy firefox_profile_setup end |
#setup ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/browsermob/cli/browsermob.rb', line 48 def setup File.delete("/tmp/traffic.har") if File.exist?("/tmp/traffic.har") File.delete("/tmp/traffic.yml") if File.exist?("/tmp/traffic.yml") @proxy = browsermob_setting @driver = Selenium::WebDriver.for :firefox, profile: firefox_profile_setup # @driver = Selenium::WebDriver.for(:chrome, :desired_capabilities => @chrome_caps) end |
#show_har_data_browser ⇒ Object
75 76 77 |
# File 'lib/browsermob/cli/browsermob.rb', line 75 def show_har_data_browser exec("har /tmp/traffic.har") end |
#teardown ⇒ Object
56 57 58 59 |
# File 'lib/browsermob/cli/browsermob.rb', line 56 def teardown @driver.quit @proxy.close end |
#user_actions(url, options = {}) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/browsermob/cli/browsermob.rb', line 66 def user_actions(url, = {}) if .empty? == true @driver.get url else @driver.find_element(css: [:source]).click sleep 2 end end |