2018-10-02 18:31:39 +00:00
# frozen_string_literal: true
require 'capybara/dsl'
2019-01-24 18:11:52 +00:00
require 'logger'
2018-10-02 18:31:39 +00:00
describe QA :: Support :: Page :: Logging do
2019-01-24 13:43:02 +00:00
let ( :page ) { double . as_null_object }
2018-10-02 18:31:39 +00:00
before do
2019-01-24 18:11:52 +00:00
logger = :: Logger . new $stdout
2018-10-25 15:49:33 +00:00
logger . level = :: Logger :: DEBUG
QA :: Runtime :: Logger . logger = logger
2018-10-02 18:31:39 +00:00
allow ( Capybara ) . to receive ( :current_session ) . and_return ( page )
allow ( page ) . to receive ( :current_url ) . and_return ( 'http://current-url' )
allow ( page ) . to receive ( :has_css? ) . with ( any_args ) . and_return ( true )
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 wait' do
2019-02-11 09:04:59 +00:00
expect { subject . wait ( max : 0 ) { } }
. to output ( / next wait uses reload: true / ) . to_stdout_from_any_process
2018-10-02 18:31:39 +00:00
expect { subject . wait ( max : 0 ) { } }
2020-01-09 09:07:51 +00:00
. to output ( / with wait_until / ) . to_stdout_from_any_process
2018-10-02 18:31:39 +00:00
expect { subject . wait ( max : 0 ) { } }
2020-01-09 09:07:51 +00:00
. to output ( / ended wait_until$ / ) . to_stdout_from_any_process
2018-10-02 18:31:39 +00:00
end
2019-02-11 09:04:59 +00:00
it 'logs wait with reload false' do
expect { subject . wait ( max : 0 , reload : false ) { } }
. to output ( / next wait uses reload: false / ) . to_stdout_from_any_process
expect { subject . wait ( max : 0 , reload : false ) { } }
2020-01-09 09:07:51 +00:00
. to output ( / with wait_until / ) . to_stdout_from_any_process
2019-02-11 09:04:59 +00:00
expect { subject . wait ( max : 0 , reload : false ) { } }
2020-01-09 09:07:51 +00:00
. to output ( / ended wait_until$ / ) . to_stdout_from_any_process
2019-02-11 09:04:59 +00:00
end
2018-10-02 18:31:39 +00:00
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 ) }
2018-12-28 17:39:07 +00:00
. 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-02-25 13:37:27 +00:00
it 'logs find_element with text' do
expect { subject . find_element ( :element , text : 'foo' ) }
2019-06-05 08:46:30 +00:00
. to output ( / finding :element with args {:text=>"foo"} / ) . to_stdout_from_any_process
2019-02-25 13:37:27 +00:00
expect { subject . find_element ( :element , text : 'foo' ) }
2018-10-02 18:31:39 +00:00
. to output ( / found :element / ) . to_stdout_from_any_process
end
2019-06-05 08:46:30 +00:00
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' ) }
. to output ( / finding :element with args {:class=> \ "active \ "} / ) . to_stdout_from_any_process
end
2018-10-02 18:31:39 +00:00
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
expect { subject . has_element? ( :element ) }
2019-07-09 15:40:46 +00:00
. to output ( / has_element \ ? :element \ (wait: #{ QA :: Runtime :: Browser :: CAPYBARA_MAX_WAIT_TIME } \ ) returned: true / ) . to_stdout_from_any_process
2019-02-25 13:37:27 +00:00
end
it 'logs has_element? with text' do
expect { subject . has_element? ( :element , text : " some text " ) }
2019-07-09 15:40:46 +00:00
. to output ( / has_element \ ? :element with text \ "some text \ " \ (wait: #{ QA :: Runtime :: Browser :: CAPYBARA_MAX_WAIT_TIME } \ ) returned: true / ) . to_stdout_from_any_process
2018-12-20 13:27:08 +00:00
end
2019-01-07 18:57:05 +00:00
it 'logs has_no_element?' do
allow ( page ) . to receive ( :has_no_css? ) . and_return ( true )
expect { subject . has_no_element? ( :element ) }
2019-07-09 15:40:46 +00:00
. to output ( / has_no_element \ ? :element \ (wait: #{ QA :: Runtime :: Browser :: CAPYBARA_MAX_WAIT_TIME } \ ) returned: true / ) . to_stdout_from_any_process
2019-05-07 02:43:10 +00:00
end
it 'logs has_no_element? with text' do
allow ( page ) . to receive ( :has_no_css? ) . and_return ( true )
expect { subject . has_no_element? ( :element , text : " more text " ) }
2019-07-09 15:40:46 +00:00
. to output ( / has_no_element \ ? :element with text \ "more text \ " \ (wait: #{ QA :: Runtime :: Browser :: CAPYBARA_MAX_WAIT_TIME } \ ) returned: true / ) . to_stdout_from_any_process
2019-01-07 18:57:05 +00:00
end
it 'logs has_text?' do
allow ( page ) . to receive ( :has_text? ) . and_return ( true )
expect { subject . has_text? 'foo' }
2019-11-20 00:06:22 +00:00
. to output ( / has_text \ ? \ ('foo', wait: #{ QA :: Runtime :: Browser :: CAPYBARA_MAX_WAIT_TIME } \ ) returned true / ) . to_stdout_from_any_process
2019-01-07 18:57:05 +00:00
end
2018-12-20 13:27:08 +00:00
it 'logs has_no_text?' do
allow ( page ) . to receive ( :has_no_text? ) . with ( 'foo' ) . and_return ( true )
expect { subject . has_no_text? 'foo' }
. to output ( / has_no_text \ ? \ ('foo' \ ) returned true / ) . to_stdout_from_any_process
2019-01-24 18:11:52 +00:00
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-10-02 18:31:39 +00:00
end
it 'logs within_element' do
2019-06-14 05:07:29 +00:00
expect { subject . within_element ( :element , text : nil ) }
2018-10-02 18:31:39 +00:00
. to output ( / within element :element / ) . to_stdout_from_any_process
2019-06-14 05:07:29 +00:00
expect { subject . within_element ( :element , text : nil ) }
2018-10-02 18:31:39 +00:00
. to output ( / end within element :element / ) . to_stdout_from_any_process
end
context 'all_elements' do
it 'logs the number of elements found' do
allow ( page ) . to receive ( :all ) . and_return ( [ 1 , 2 ] )
2020-01-10 00:07:56 +00:00
expect { subject . all_elements ( :element , count : 2 ) }
2018-10-02 18:31:39 +00:00
. to output ( / finding all :element / ) . to_stdout_from_any_process
2020-01-10 00:07:56 +00:00
expect { subject . all_elements ( :element , count : 2 ) }
2018-10-02 18:31:39 +00:00
. 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-01-10 00:07:56 +00:00
expect { subject . all_elements ( :element , count : 1 ) }
2018-10-02 18:31:39 +00:00
. to output ( / finding all :element / ) . to_stdout_from_any_process
2020-01-10 00:07:56 +00:00
expect { subject . all_elements ( :element , count : 1 ) }
2018-10-02 18:31:39 +00:00
. not_to output ( / found 0 :elements / ) . to_stdout_from_any_process
end
end
end