diff --git a/Gemfile.lock b/Gemfile.lock index 80fba99..fb29930 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - agent_q (0.0.13) + agent_q (0.0.16) capybara (~> 3.31, >= 3.31) cuprite (~> 0.11, >= 0.11) nokogiri (~> 1.10, >= 1.10.8) @@ -9,38 +9,38 @@ PATH GEM remote: https://rubygems.org/ specs: - addressable (2.8.4) + addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) - capybara (3.39.1) + capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - concurrent-ruby (1.2.2) - cuprite (0.14.3) + concurrent-ruby (1.2.3) + cuprite (0.15) capybara (~> 3.0) - ferrum (~> 0.13.0) - ferrum (0.13) + ferrum (~> 0.14.0) + ferrum (0.14) addressable (~> 2.5) concurrent-ruby (~> 1.1) webrick (~> 1.7) websocket-driver (>= 0.6, < 0.8) matrix (0.4.2) - mini_mime (1.1.2) - nokogiri (1.15.2-x86_64-darwin) + mini_mime (1.1.5) + nokogiri (1.16.2-x86_64-darwin) racc (~> 1.4) - public_suffix (5.0.1) - racc (1.7.0) - rack (3.0.7) + public_suffix (5.0.4) + racc (1.7.3) + rack (3.0.9.1) rack-test (2.1.0) rack (>= 1.3) - regexp_parser (2.8.0) + regexp_parser (2.9.0) webrick (1.8.1) - websocket-driver (0.7.5) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) diff --git a/bin/agent_q b/bin/agent_q index cfde256..32afef7 100755 --- a/bin/agent_q +++ b/bin/agent_q @@ -1,13 +1,25 @@ #!/usr/bin/env ruby require 'rubygems' -require_relative '../lib/agent_q' +require_relative '../lib/check_case' +require_relative '../lib/run_queries' -quepid_case = ARGV[0] -threshold_score = ARGV[1] -username = ARGV[2] -password = ARGV[3] -quepid_url = ARGV[4] +subcommand = ARGV[0] +if subcommand == 'check-case' + quepid_case = ARGV[1] + threshold_score = ARGV[2] + username = ARGV[3] + password = ARGV[4] + quepid_url = ARGV[5] + + CheckCase.new(quepid_case, threshold_score, username, password, quepid_url).run +end - -AgentQ.new(quepid_case, threshold_score, username, password, quepid_url).run +if subcommand == 'run-queries' + quepid_case = ARGV[1] + username = ARGV[2] + password = ARGV[3] + quepid_url = ARGV[4] + + RunQueries.new(quepid_case, username, password, quepid_url).run +end diff --git a/lib/agent_q.rb b/lib/check_case.rb similarity index 78% rename from lib/agent_q.rb rename to lib/check_case.rb index 94b812c..61968c2 100755 --- a/lib/agent_q.rb +++ b/lib/check_case.rb @@ -5,7 +5,7 @@ require 'capybara/cuprite' require 'json' -class AgentQ +class CheckCase include Capybara::DSL @@ -15,8 +15,13 @@ def initialize(quepid_case, threshold_score, username, password, quepid_url) @username = username @password = password @quepid_url = quepid_url + + Capybara.register_driver :cuprite do |app| + Capybara::Cuprite::Driver.new(app, timeout: 30) # Increase timeout to 30 seconds + end Capybara.default_driver = :cuprite + Capybara.default_max_wait_time = 30 # Increase timeout to 30 seconds #Capybara.app_host = @quepid_url end @@ -32,17 +37,17 @@ def run click_button('Sign in') end - - #within(:xpath, "/html/body/div[3]/div/div/div[1]/div[1]/div/form") do - # fill_in('Password', with: @password) - #end #save_screenshot('quepid_login.png') + visit("#{@quepid_url}/case/#{@quepid_case}") + page.has_css?('.search-feedback', visible: true, wait: Capybara.default_max_wait_time) + + #save_screenshot('quepid_case_queries2.png') - sleep(20) - - #save_screenshot('quepid_dashboard.png') + page.has_no_css?('.search-feedback', wait: Capybara.default_max_wait_time) + + #save_screenshot('quepid_case.png') visit "#{@quepid_url}/api/cases/#{@quepid_case}/scores/all.json" html = page.html diff --git a/lib/run_queries.rb b/lib/run_queries.rb new file mode 100755 index 0000000..db7b7e6 --- /dev/null +++ b/lib/run_queries.rb @@ -0,0 +1,64 @@ +# Inspired by http://ngauthier.com/2014/06/scraping-the-web-with-ruby.html + +require 'capybara' +require 'capybara/dsl' +require 'capybara/cuprite' +require 'json' + +class RunQueries + include Capybara::DSL + + + def initialize(quepid_case, username, password, quepid_url) + @quepid_case = quepid_case + @username = username + @password = password + @quepid_url = quepid_url + + Capybara.register_driver :cuprite do |app| + Capybara::Cuprite::Driver.new(app, timeout: 30) # Increase timeout to 30 seconds + end + + Capybara.default_driver = :cuprite + Capybara.default_max_wait_time = 30 # Increase timeout to 30 seconds + # Capybara.app_host = @quepid_url + end + + def run + + # we go direct to the case, which then prompts the login process. That way we only + # score the requested case + visit("#{@quepid_url}/case/#{@quepid_case}/query/0") + save_screenshot('quepid.png') + within('#login') do + fill_in('user_email', with: @username) + fill_in('user_password', with: @password) + + click_button('Sign in') + end + save_screenshot('quepid_login.png') + + + + visit("#{@quepid_url}/case/#{@quepid_case}/query/0") + + + + save_screenshot('quepid_case_queries.png') + + page.has_css?('.search-feedback', visible: true, wait: 60) + + save_screenshot('quepid_case_queries2.png') + + page.has_no_css?('.search-feedback', wait: 60) + + save_screenshot('quepid_case_queries3.png') + + content = find('.snapshot-payload').text + + puts content + + + end + +end