Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/integration/selenium/webdriver/spec_helper.rb
1864 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require 'rubygems'
21
require 'time'
22
require 'rspec'
23
24
require 'selenium-webdriver'
25
require_relative 'spec_support'
26
require_relative '../../../rspec_matchers'
27
28
include Selenium # rubocop:disable Style/MixinUsage
29
30
GlobalTestEnv = WebDriver::SpecSupport::TestEnvironment.new
31
32
class SeleniumTestListener
33
def example_finished(notification)
34
exception = notification.example.exception
35
assertion_failed = exception &&
36
(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
39
40
GlobalTestEnv.reset_driver! if (exception && !assertion_failed) || pending_exception
41
end
42
end
43
44
RSpec.configure do |c|
45
c.define_derived_metadata do |meta|
46
meta[:aggregate_failures] = true
47
end
48
49
c.reporter.register_listener(SeleniumTestListener.new, :example_finished)
50
51
c.include(WebDriver::SpecSupport::Helpers)
52
53
c.before(:suite) do
54
GlobalTestEnv.remote_server.start if GlobalTestEnv.driver == :remote && ENV['WD_REMOTE_URL'].nil?
55
GlobalTestEnv.print_env
56
end
57
58
c.after(:suite) do
59
GlobalTestEnv.quit_driver
60
end
61
62
c.filter_run_when_matching :focus
63
c.run_all_when_everything_filtered = true
64
c.default_formatter = c.files_to_run.count > 1 ? 'progress' : 'doc'
65
66
c.before do |example|
67
guards = WebDriver::Support::Guards.new(example, bug_tracker: 'https://github.com/SeleniumHQ/selenium/issues')
68
guards.add_condition(:driver, GlobalTestEnv.driver)
69
guards.add_condition(:browser, GlobalTestEnv.browser)
70
guards.add_condition(:ci, WebDriver::Platform.ci)
71
guards.add_condition(:platform, WebDriver::Platform.os)
72
guards.add_condition(:headless, !ENV['HEADLESS'].nil?)
73
guards.add_condition(:bidi, !ENV['WEBDRIVER_BIDI'].nil?)
74
guards.add_condition(:rbe, GlobalTestEnv.rbe?)
75
guards.add_condition(:version, GlobalTestEnv.browser_version)
76
77
results = guards.disposition
78
send(*results) if results
79
end
80
end
81
82
WebDriver::Platform.exit_hook { GlobalTestEnv.quit }
83
84
$stdout.sync = true
85
86