Commit 9b7012d8 authored by Andrejs Cunskis's avatar Andrejs Cunskis

Merge branch 'acunskis-save-browser-log' into 'master'

E2E: Attach browser logs to allure test reports

See merge request gitlab-org/gitlab!72761
parents bc8b3aa2 58980ca1
...@@ -76,6 +76,15 @@ module QA ...@@ -76,6 +76,15 @@ module QA
RSpec.configure do |config| RSpec.configure do |config|
config.add_formatter(AllureRspecFormatter) config.add_formatter(AllureRspecFormatter)
config.add_formatter(QA::Support::Formatters::AllureMetadataFormatter) config.add_formatter(QA::Support::Formatters::AllureMetadataFormatter)
config.append_after do |example|
Allure.add_attachment(
name: 'browser.log',
source: Capybara.current_session.driver.browser.logs.get(:browser).map(&:to_s).join("\n\n"),
type: Allure::ContentType::TXT,
test_case: true
)
end
end end
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
describe QA::Runtime::AllureReport do describe QA::Runtime::AllureReport do
include QA::Support::Helpers::StubEnv include QA::Support::Helpers::StubEnv
let(:rspec_config) { double('RSpec::Core::Configuration', 'add_formatter': nil, after: nil) } let(:rspec_config) { double('RSpec::Core::Configuration', 'add_formatter': nil, append_after: nil) }
let(:png_path) { 'png_path' } let(:png_path) { 'png_path' }
let(:html_path) { 'html_path' } let(:html_path) { 'html_path' }
...@@ -46,6 +46,8 @@ describe QA::Runtime::AllureReport do ...@@ -46,6 +46,8 @@ describe QA::Runtime::AllureReport do
let(:html_file) { 'html-file' } let(:html_file) { 'html-file' }
let(:ci_job) { 'ee:relative 5' } let(:ci_job) { 'ee:relative 5' }
let(:versions) { { version: '14', revision: '6ced31db947' } } let(:versions) { { version: '14', revision: '6ced31db947' } }
let(:session) { double('session') }
let(:browser_log) { ['log message 1', 'log message 2'] }
before do before do
stub_env('CI', 'true') stub_env('CI', 'true')
...@@ -58,6 +60,9 @@ describe QA::Runtime::AllureReport do ...@@ -58,6 +60,9 @@ describe QA::Runtime::AllureReport do
allow(RestClient::Request).to receive(:execute) { double('response', code: 200, body: versions.to_json) } allow(RestClient::Request).to receive(:execute) { double('response', code: 200, body: versions.to_json) }
allow(QA::Runtime::Scenario).to receive(:method_missing).with(:gitlab_address).and_return('gitlab.com') allow(QA::Runtime::Scenario).to receive(:method_missing).with(:gitlab_address).and_return('gitlab.com')
allow(Capybara).to receive(:current_session).and_return(session)
allow(session).to receive_message_chain('driver.browser.logs.get').and_return(browser_log)
described_class.configure! described_class.configure!
end end
...@@ -76,7 +81,11 @@ describe QA::Runtime::AllureReport do ...@@ -76,7 +81,11 @@ describe QA::Runtime::AllureReport do
.with(QA::Support::Formatters::AllureMetadataFormatter).ordered .with(QA::Support::Formatters::AllureMetadataFormatter).ordered
end end
it 'configures screenshot saving' do it 'configures attachments saving' do
expect(rspec_config).to have_received(:append_after) do |&arg|
arg.call
end
aggregate_failures do aggregate_failures do
expect(Allure).to have_received(:add_attachment).with( expect(Allure).to have_received(:add_attachment).with(
name: 'screenshot', name: 'screenshot',
...@@ -90,6 +99,12 @@ describe QA::Runtime::AllureReport do ...@@ -90,6 +99,12 @@ describe QA::Runtime::AllureReport do
type: 'text/html', type: 'text/html',
test_case: true test_case: true
) )
expect(Allure).to have_received(:add_attachment).with(
name: 'browser.log',
source: browser_log.join("\n\n"),
type: Allure::ContentType::TXT,
test_case: true
)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment