From 5ccace25111e549a894f08aadf6aa2ad7812ffd3 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Wed, 6 Mar 2024 17:02:47 -0500 Subject: [PATCH 1/3] set up for extending this --- bin/agent_q | 22 +++++++++++++--------- lib/{agent_q.rb => check_case.rb} | 22 ++++++++++++++-------- 2 files changed, 27 insertions(+), 17 deletions(-) rename lib/{agent_q.rb => check_case.rb} (82%) diff --git a/bin/agent_q b/bin/agent_q index cfde256..b3b50b6 100755 --- a/bin/agent_q +++ b/bin/agent_q @@ -1,13 +1,17 @@ #!/usr/bin/env ruby require 'rubygems' -require_relative '../lib/agent_q' +require_relative '../lib/check_case' -quepid_case = ARGV[0] -threshold_score = ARGV[1] -username = ARGV[2] -password = ARGV[3] -quepid_url = ARGV[4] +subcommand = ARGV[0] - - -AgentQ.new(quepid_case, threshold_score, username, password, quepid_url).run +if subcommand == 'checkcase' + 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 diff --git a/lib/agent_q.rb b/lib/check_case.rb similarity index 82% rename from lib/agent_q.rb rename to lib/check_case.rb index 94b812c..d13751a 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 @@ -25,24 +30,25 @@ 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}/try/0") - #save_screenshot('quepid.png') + 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') + - #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') + #sleep(20) + #save_screenshot('quepid_dashboard.png') + visit("#{@quepid_url}/case/#{@quepid_case}") - sleep(20) + #sleep(1) - #save_screenshot('quepid_dashboard.png') + save_screenshot('quepid_case.png') visit "#{@quepid_url}/api/cases/#{@quepid_case}/scores/all.json" html = page.html From c2efffd82cc152f01b290fdb481b657937193240 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Wed, 6 Mar 2024 17:30:51 -0500 Subject: [PATCH 2/3] bump version --- Gemfile.lock | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) 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) From f4ec863f22b2ccc62ecff1f13d8364ba8442950c Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Wed, 6 Mar 2024 18:45:37 -0500 Subject: [PATCH 3/3] new command --- bin/agent_q | 14 +++++++--- lib/check_case.rb | 17 ++++++------ lib/run_queries.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 12 deletions(-) create mode 100755 lib/run_queries.rb diff --git a/bin/agent_q b/bin/agent_q index b3b50b6..32afef7 100755 --- a/bin/agent_q +++ b/bin/agent_q @@ -1,17 +1,25 @@ #!/usr/bin/env ruby require 'rubygems' require_relative '../lib/check_case' +require_relative '../lib/run_queries' subcommand = ARGV[0] -if subcommand == 'checkcase' +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 + +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/check_case.rb b/lib/check_case.rb index d13751a..61968c2 100755 --- a/lib/check_case.rb +++ b/lib/check_case.rb @@ -30,25 +30,24 @@ 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}/try/0") - save_screenshot('quepid.png') + #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') - - - - #sleep(20) - #save_screenshot('quepid_dashboard.png') + #save_screenshot('quepid_login.png') visit("#{@quepid_url}/case/#{@quepid_case}") - #sleep(1) + page.has_css?('.search-feedback', visible: true, wait: Capybara.default_max_wait_time) + + #save_screenshot('quepid_case_queries2.png') - save_screenshot('quepid_case.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