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
visit("/case/#{@quepid_case}/try/0")
within('#login') do
fill_in('user_email', with: @username)
fill_in('user_password', with: @password)
click_button('Sign in')
end
sleep(20)
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
|