Skip to content

Commit 346d6ec

Browse files
committed
[rb] take screenshots and log page source on test failures when debug enabled
1 parent b3c8719 commit 346d6ec

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

rb/spec/integration/selenium/webdriver/spec_helper.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,32 @@
3131

3232
class SeleniumTestListener
3333
def example_finished(notification)
34-
exception = notification.example.exception
34+
if investigate?(notification.example) && WebDriver.logger.debug?
35+
driver = GlobalTestEnv.driver_instance
36+
session_id = driver.instance_variable_get(:@bridge).session_id
37+
38+
FileUtils.mkdir_p('bazel-logs')
39+
driver.save_screenshot("bazel-logs/#{session_id}.png")
40+
WebDriver.logger.info("Page Source: #{driver.page_source}")
41+
end
42+
43+
GlobalTestEnv.reset_driver! if reset_driver?(notification.example)
44+
end
45+
46+
private
47+
48+
def investigate?(example)
49+
example.exception && !example.pending
50+
end
51+
52+
def reset_driver?(example)
53+
exception = example.exception
3554
assertion_failed = exception &&
3655
(exception.is_a?(RSpec::Expectations::ExpectationNotMetError) ||
37-
exception.is_a?(RSpec::Core::Pending::PendingExampleFixedError))
38-
pending_exception = exception.nil? && notification.example.pending && !notification.example.skip
56+
exception.is_a?(RSpec::Core::Pending::PendingExampleFixedError))
57+
pending_exception = exception.nil? && example.pending && !example.skip
3958

40-
GlobalTestEnv.reset_driver! if (exception && !assertion_failed) || pending_exception
59+
(exception && !assertion_failed) || pending_exception
4160
end
4261
end
4362

0 commit comments

Comments
 (0)