Skip to content

Commit

Permalink
Merge pull request #23 from o19s/api_key
Browse files Browse the repository at this point in the history
Api key
  • Loading branch information
epugh authored Mar 6, 2024
2 parents 3a6cfdd + f4ec863 commit cf449a4
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 31 deletions.
30 changes: 15 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
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)

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)
Expand Down
28 changes: 20 additions & 8 deletions bin/agent_q
Original file line number Diff line number Diff line change
@@ -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
21 changes: 13 additions & 8 deletions lib/agent_q.rb → lib/check_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'capybara/cuprite'
require 'json'

class AgentQ
class CheckCase
include Capybara::DSL


Expand All @@ -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

Expand All @@ -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
Expand Down
64 changes: 64 additions & 0 deletions lib/run_queries.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cf449a4

Please sign in to comment.