|
29 | 29 |
|
30 | 30 | GlobalTestEnv = WebDriver::SpecSupport::TestEnvironment.new |
31 | 31 |
|
| 32 | +class SeleniumTestListener |
| 33 | + # formatter complains if there is a return in this method |
| 34 | + # rubocop:disable Style/GuardClause |
| 35 | + def example_finished(notification) |
| 36 | + if notification.exception |
| 37 | + if WebDriver.logger.debug? |
| 38 | + driver = GlobalTestEnv.driver_instance |
| 39 | + session_id = driver.instance_variable_get(:@bridge).session_id |
| 40 | + |
| 41 | + FileUtils.mkdir_p('bazel-logs') |
| 42 | + driver.save_screenshot("bazel-logs/#{session_id}.png") |
| 43 | + WebDriver.logger.info("Page Source: #{driver.page_source}") |
| 44 | + end |
| 45 | + |
| 46 | + GlobalTestEnv.reset_driver! unless notification.exception.is_a?(RSpec::Expectations::ExpectationNotMetError) |
| 47 | + end |
| 48 | + end |
| 49 | + # rubocop:enable Style/GuardClause |
| 50 | +end |
| 51 | + |
32 | 52 | RSpec.configure do |c| |
33 | 53 | c.define_derived_metadata do |meta| |
34 | 54 | meta[:aggregate_failures] = true |
35 | 55 | end |
36 | 56 |
|
| 57 | + c.reporter.register_listener(SeleniumTestListener.new, :example_finished) |
| 58 | + |
37 | 59 | c.include(WebDriver::SpecSupport::Helpers) |
38 | 60 |
|
39 | 61 | c.before(:suite) do |
|
62 | 84 | results = guards.disposition |
63 | 85 | send(*results) if results |
64 | 86 | end |
65 | | - |
66 | | - c.after do |example| |
67 | | - if example.exception && WebDriver.logger.debug? |
68 | | - driver.save_screenshot("bazel-logs/#{driver.session_id}.png") |
69 | | - WebDriver.logger.info("Page Source: #{driver.page_source}") |
70 | | - end |
71 | | - |
72 | | - reset_driver! if example.exception || example.execution_result.pending_exception |
73 | | - end |
74 | 87 | end |
75 | 88 |
|
76 | 89 | WebDriver::Platform.exit_hook { GlobalTestEnv.quit } |
|
0 commit comments