Class: AgentQ

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL
Defined in:
lib/agent_q.rb

Instance Method Summary collapse

Constructor Details

#initialize(quepid_case, threshold_score, username, password, quepid_url) ⇒ AgentQ



13
14
15
16
17
18
19
20
21
22
# File 'lib/agent_q.rb', line 13

def initialize(quepid_case, threshold_score, username, password, quepid_url)
  @quepid_case = quepid_case
  @threshold_score = threshold_score
  @username = username
  @password = password
  @quepid_url = quepid_url

  Capybara.default_driver = :cuprite
  Capybara.app_host = @quepid_url
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/agent_q.rb', line 24

def run

  # we go direct to the case, which then prompts the login process.  That way we only
  # score the requested case
  visit("/case/#{@quepid_case}/try/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

  #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 "/api/cases/#{@quepid_case}/scores/all.json"
  html = page.html
  json = html[html.index('{')..html.rindex('}')]
  case_results = JSON.parse(json)
  if case_results['reason'] == 'Unauthorized!'
    puts "API reporting Unauthorized!  Username/Password issue in accessing API."
    exit 1
  end

  visit "/api/cases/#{@quepid_case}.json"
  html = page.html
  json = html[html.index('{')..html.rindex('}')]
  case_details = JSON.parse(json)
  case_name = case_details["case_name"]

  if case_results['message']
    puts "Error checking case #{@quepid_case}: #{case_results['message']}"
    exit 1
  else
    score = case_results['scores'].first['score']
    if score.to_i >= @threshold_score.to_i
      puts "Case #{case_name} (#{@quepid_case}) scored #{score}, \e[32mwhich meets the threshold of #{@threshold_score}\e[0m"
      exit 0
    else
      puts "Case #{case_name} (#{@quepid_case}) scored #{score}, \e[31mwhich is below the threshold of #{@threshold_score}\e[0m"
      exit 1
    end
  end
end