debian-mirror-gitlab/qa/spec/page/logging_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

152 lines
5.4 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
require 'capybara/dsl'
2021-01-03 14:25:43 +05:30
RSpec.describe QA::Support::Page::Logging do
2019-03-02 22:35:43 +05:30
let(:page) { double.as_null_object }
2022-05-07 20:08:51 +05:30
let(:logger) { Gitlab::QA::TestLogger.logger(level: ::Logger::DEBUG, source: 'QA Tests') }
2018-12-13 13:39:08 +05:30
before do
2022-05-07 20:08:51 +05:30
allow(QA::Runtime::Logger).to receive(:logger).and_return(logger)
2018-12-13 13:39:08 +05:30
allow(Capybara).to receive(:current_session).and_return(page)
2021-10-27 15:23:28 +05:30
allow(page).to receive(:find).and_return(page)
2018-12-13 13:39:08 +05:30
allow(page).to receive(:current_url).and_return('http://current-url')
allow(page).to receive(:has_css?).with(any_args).and_return(true)
2022-03-02 08:16:31 +05:30
allow(QA::Support::PageErrorChecker).to receive(:check_page_for_error_code).and_return(0)
2018-12-13 13:39:08 +05:30
end
subject do
Class.new(QA::Page::Base) do
prepend QA::Support::Page::Logging
end.new
end
it 'logs refresh' do
expect { subject.refresh }
.to output(%r{refreshing http://current-url}).to_stdout_from_any_process
end
it 'logs scroll_to' do
expect { subject.scroll_to(:element) }
.to output(/scrolling to :element/).to_stdout_from_any_process
end
it 'logs asset_exists?' do
expect { subject.asset_exists?('http://asset-url') }
.to output(%r{asset_exists\? http://asset-url returned false}).to_stdout_from_any_process
end
it 'logs find_element' do
expect { subject.find_element(:element) }
2019-02-15 15:39:39 +05:30
.to output(/finding :element/).to_stdout_from_any_process
expect { subject.find_element(:element) }
.to output(/found :element/).to_stdout_from_any_process
end
2019-07-07 11:18:12 +05:30
it 'logs find_element with text' do
expect { subject.find_element(:element, text: 'foo') }
2019-09-04 21:01:54 +05:30
.to output(/finding :element with args {:text=>"foo"}/).to_stdout_from_any_process
2019-07-07 11:18:12 +05:30
expect { subject.find_element(:element, text: 'foo') }
2018-12-13 13:39:08 +05:30
.to output(/found :element/).to_stdout_from_any_process
end
2019-09-04 21:01:54 +05:30
it 'logs find_element with wait' do
expect { subject.find_element(:element, wait: 0) }
.to output(/finding :element with args {:wait=>0}/).to_stdout_from_any_process
end
it 'logs find_element with class' do
expect { subject.find_element(:element, class: 'active') }
2022-05-07 20:08:51 +05:30
.to output(/finding :element with args {:class=>"active"}/).to_stdout_from_any_process
2019-09-04 21:01:54 +05:30
end
2018-12-13 13:39:08 +05:30
it 'logs click_element' do
expect { subject.click_element(:element) }
.to output(/clicking :element/).to_stdout_from_any_process
end
it 'logs fill_element' do
expect { subject.fill_element(:element, 'foo') }
.to output(/filling :element with "foo"/).to_stdout_from_any_process
end
it 'logs has_element?' do
2022-06-21 17:19:12 +05:30
expect { subject.has_element?(:element) }.to output(
/has_element\? :element \(wait: #{Capybara.default_max_wait_time}\) returned: true/o
).to_stdout_from_any_process
2019-07-07 11:18:12 +05:30
end
it 'logs has_element? with text' do
2022-06-21 17:19:12 +05:30
expect { subject.has_element?(:element, text: "some text") }.to output(
/has_element\? :element with text "some text" \(wait: #{Capybara.default_max_wait_time}\) returned: true/o
).to_stdout_from_any_process
2019-02-15 15:39:39 +05:30
end
2019-03-02 22:35:43 +05:30
it 'logs has_no_element?' do
allow(page).to receive(:has_no_css?).and_return(true)
2022-06-21 17:19:12 +05:30
expect { subject.has_no_element?(:element) }.to output(
/has_no_element\? :element \(wait: #{Capybara.default_max_wait_time}\) returned: true/o
).to_stdout_from_any_process
2019-07-31 22:56:46 +05:30
end
it 'logs has_no_element? with text' do
allow(page).to receive(:has_no_css?).and_return(true)
2022-06-21 17:19:12 +05:30
expect { subject.has_no_element?(:element, text: "more text") }.to output(
/has_no_element\? :element with text "more text" \(wait: #{Capybara.default_max_wait_time}\) returned: true/o
).to_stdout_from_any_process
2019-03-02 22:35:43 +05:30
end
it 'logs has_text?' do
allow(page).to receive(:has_text?).and_return(true)
2022-06-21 17:19:12 +05:30
expect { subject.has_text? 'foo' }.to output(
/has_text\?\('foo', wait: #{Capybara.default_max_wait_time}\) returned true/o
).to_stdout_from_any_process
2019-03-02 22:35:43 +05:30
end
2019-02-15 15:39:39 +05:30
it 'logs has_no_text?' do
2020-03-13 15:44:24 +05:30
allow(page).to receive(:has_no_text?).with('foo', any_args).and_return(true)
2019-02-15 15:39:39 +05:30
2022-06-21 17:19:12 +05:30
expect { subject.has_no_text? 'foo' }.to output(
/has_no_text\?\('foo', wait: #{Capybara.default_max_wait_time}\) returned true/o
).to_stdout_from_any_process
2019-03-02 22:35:43 +05:30
end
it 'logs finished_loading?' do
expect { subject.finished_loading? }
.to output(/waiting for loading to complete\.\.\./).to_stdout_from_any_process
expect { subject.finished_loading? }
.to output(/loading complete after .* seconds$/).to_stdout_from_any_process
2018-12-13 13:39:08 +05:30
end
it 'logs within_element' do
2019-09-04 21:01:54 +05:30
expect { subject.within_element(:element, text: nil) }
2018-12-13 13:39:08 +05:30
.to output(/within element :element/).to_stdout_from_any_process
2019-09-04 21:01:54 +05:30
expect { subject.within_element(:element, text: nil) }
2018-12-13 13:39:08 +05:30
.to output(/end within element :element/).to_stdout_from_any_process
end
2022-06-21 17:19:12 +05:30
context 'with all_elements' do
2018-12-13 13:39:08 +05:30
it 'logs the number of elements found' do
allow(page).to receive(:all).and_return([1, 2])
2020-03-13 15:44:24 +05:30
expect { subject.all_elements(:element, count: 2) }
2018-12-13 13:39:08 +05:30
.to output(/finding all :element/).to_stdout_from_any_process
2020-03-13 15:44:24 +05:30
expect { subject.all_elements(:element, count: 2) }
2018-12-13 13:39:08 +05:30
.to output(/found 2 :element/).to_stdout_from_any_process
end
it 'logs 0 if no elements are found' do
allow(page).to receive(:all).and_return([])
2020-03-13 15:44:24 +05:30
expect { subject.all_elements(:element, count: 1) }
2018-12-13 13:39:08 +05:30
.to output(/finding all :element/).to_stdout_from_any_process
2020-03-13 15:44:24 +05:30
expect { subject.all_elements(:element, count: 1) }
2018-12-13 13:39:08 +05:30
.not_to output(/found 0 :elements/).to_stdout_from_any_process
end
end
end