Top Level Namespace
Defined Under Namespace
Modules: Quintocumber
Classes: AllureCucumberDSLTemp
Constant Summary
collapse
- TEST_BROWSER =
ENV['TEST_BROWSER'] || 'chrome'
- BUILD =
"#{Time.now.utc.iso8601} - #{TEST_BROWSER}"
- PROJECT_NAME =
quintocumber_config['project']['name'] || 'UNNAMED PROJECT'
- ENVIRONMENT =
if File.file?(environments_config_filename)
YAML.safe_load(
File.read(environments_config_filename), [], [], true
).dig(ENV['WHERE'] || 'default').freeze || {}.freeze
else
{}.freeze
end
Instance Method Summary
collapse
-
#generate_report_and_upload_to_s3 ⇒ Object
-
#get_remote_capabilities(test_browser, window_size) ⇒ Object
-
#insert_report_url_on_pagerduty_payload(report_url, payload) ⇒ Object
-
#instanciate_s3_connector ⇒ Object
-
#notify_slack(webhook_url, payload) ⇒ Object
-
#pagerduty_payload(failed_length, reports_list_str) ⇒ Object
-
#report_to_pagerduty(report_url, tests_failed) ⇒ Object
-
#report_to_slack(report_url, tests_failed) ⇒ Object
-
#slack_color(tests_failed) ⇒ Object
-
#slack_payload(report_url, tests_failed) ⇒ Object
-
#slack_pretext(report_url) ⇒ Object
-
#slack_text(report_url, tests_failed) ⇒ Object
-
#upload_report_files_to_s3 ⇒ Object
-
#upload_to_s3(s3, bucket, file) ⇒ Object
Instance Method Details
#generate_report_and_upload_to_s3 ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/plugins/publish_reports.rb', line 28
def generate_report_and_upload_to_s3
bucket = ENV['REPORT_BUCKET']
bucket_region = ENV['REPORT_BUCKET_REGION'] || 'us-east-1'
return unless bucket && system('allure --help >> /dev/null')
puts 'Generating allure report and uploading to s3'
system('allure generate --clean reports')
upload_report_files_to_s3
"http://#{bucket}.s3-website-#{bucket_region}.amazonaws.com/" +
URI.escape(BUILD)
end
|
#get_remote_capabilities(test_browser, window_size) ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/plugins/local_config.rb', line 3
def get_remote_capabilities(test_browser, window_size)
if test_browser.eql? 'chrome_headless'
return Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %W(headless disable-gpu window-size=#{window_size})}
)
end
test_browser.to_sym
end
|
61
62
63
64
65
66
67
|
# File 'lib/plugins/publish_reports.rb', line 61
def (report_url, payload)
payload[:links] = [{
href: report_url,
text: "Report for #{BUILD}"
}]
puts 'Sending s3 report url to PagerDuty'
end
|
#instanciate_s3_connector ⇒ Object
47
48
49
50
|
# File 'lib/plugins/publish_reports.rb', line 47
def instanciate_s3_connector
bucket_region = ENV['REPORT_BUCKET_REGION'] || 'us-east-1'
Aws::S3::Resource.new(region: bucket_region)
end
|
#notify_slack(webhook_url, payload) ⇒ Object
79
80
81
82
83
|
# File 'lib/plugins/publish_reports.rb', line 79
def notify_slack(webhook_url, payload)
HTTParty.post webhook_url.to_s,
headers: { 'Content-Type' => 'application/json' },
body: payload.to_json
end
|
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/plugins/publish_reports.rb', line 9
def (failed_length, reports_list_str)
{
payload: {
summary: failed_length.to_s + " #{PROJECT_NAME} test(s) failed",
source: PROJECT_NAME.to_s,
severity: 'critical',
custom_details: "Failed test(s):\n- #{reports_list_str}"
},
event_action: 'trigger',
routing_key: ENV['PAGERDUTY_ROUTING_KEY']
}
end
|
69
70
71
72
73
74
75
76
77
|
# File 'lib/plugins/publish_reports.rb', line 69
def (report_url, tests_failed)
return unless ENV['PAGERDUTY_ROUTING_KEY'] && !tests_failed.empty?
puts 'Sending test failed alert to PagerDuty'
payload = (tests_failed.length, tests_failed.join('\n- '))
(report_url, payload) if report_url
HTTParty.post 'https://events.pagerduty.com/v2/enqueue',
headers: { 'Content-Type' => 'application/json' },
body: payload.to_json
end
|
#report_to_slack(report_url, tests_failed) ⇒ Object
123
124
125
126
127
128
|
# File 'lib/plugins/publish_reports.rb', line 123
def report_to_slack(report_url, tests_failed)
return unless ENV['SLACK_WEBHOOK_URL']
puts 'Sending test report link to Slack'
payload = slack_payload(report_url, tests_failed)
notify_slack(ENV['SLACK_WEBHOOK_URL'], payload)
end
|
#slack_color(tests_failed) ⇒ Object
104
105
106
107
108
109
110
111
|
# File 'lib/plugins/publish_reports.rb', line 104
def slack_color(tests_failed)
color = if tests_failed.empty?
'good'
else
'danger'
end
color
end
|
#slack_payload(report_url, tests_failed) ⇒ Object
113
114
115
116
117
118
119
120
121
|
# File 'lib/plugins/publish_reports.rb', line 113
def slack_payload(report_url, tests_failed)
{
attachments: [
pretext: slack_pretext(report_url),
text: slack_text(report_url, tests_failed),
color: slack_color(tests_failed)
]
}
end
|
#slack_pretext(report_url) ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'lib/plugins/publish_reports.rb', line 95
def slack_pretext(report_url)
pretext = if report_url
"Full report at #{report_url}"
else
'Report was not published.'
end
pretext
end
|
#slack_text(report_url, tests_failed) ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'lib/plugins/publish_reports.rb', line 85
def slack_text(report_url, tests_failed)
txt = if tests_failed.empty?
'Success! All tests passed.'
else
"Failure! There are #{tests_failed.length} failed tests: "\
"\n\t#{tests_failed.join("\n\t")}"\
end
txt
end
|
#upload_report_files_to_s3 ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/plugins/publish_reports.rb', line 39
def upload_report_files_to_s3
s3 = instanciate_s3_connector
Dir[File.join(Dir.pwd, 'allure-report/**/*')].each do |file|
next if File.directory?(file)
upload_to_s3(s3, ENV['REPORT_BUCKET'], file)
end
end
|
#upload_to_s3(s3, bucket, file) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/plugins/publish_reports.rb', line 52
def upload_to_s3(s3, bucket, file)
file_name = file.clone
file_name.sub! File.join(Dir.pwd, 'allure-report/'), ''
obj = s3.bucket(bucket).object("#{BUILD}/#{file_name}")
obj.upload_file(file)
obj.acl.put(acl: 'public-read')
puts "Sending #{BUILD}/#{file_name} to #{bucket}"
end
|