Path: blob/trunk/rb/spec/integration/selenium/webdriver/spec_helper.rb
1864 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require 'rubygems'20require 'time'21require 'rspec'2223require 'selenium-webdriver'24require_relative 'spec_support'25require_relative '../../../rspec_matchers'2627include Selenium # rubocop:disable Style/MixinUsage2829GlobalTestEnv = WebDriver::SpecSupport::TestEnvironment.new3031class SeleniumTestListener32def example_finished(notification)33exception = notification.example.exception34assertion_failed = exception &&35(exception.is_a?(RSpec::Expectations::ExpectationNotMetError) ||36exception.is_a?(RSpec::Core::Pending::PendingExampleFixedError))37pending_exception = exception.nil? && notification.example.pending && !notification.example.skip3839GlobalTestEnv.reset_driver! if (exception && !assertion_failed) || pending_exception40end41end4243RSpec.configure do |c|44c.define_derived_metadata do |meta|45meta[:aggregate_failures] = true46end4748c.reporter.register_listener(SeleniumTestListener.new, :example_finished)4950c.include(WebDriver::SpecSupport::Helpers)5152c.before(:suite) do53GlobalTestEnv.remote_server.start if GlobalTestEnv.driver == :remote && ENV['WD_REMOTE_URL'].nil?54GlobalTestEnv.print_env55end5657c.after(:suite) do58GlobalTestEnv.quit_driver59end6061c.filter_run_when_matching :focus62c.run_all_when_everything_filtered = true63c.default_formatter = c.files_to_run.count > 1 ? 'progress' : 'doc'6465c.before do |example|66guards = WebDriver::Support::Guards.new(example, bug_tracker: 'https://github.com/SeleniumHQ/selenium/issues')67guards.add_condition(:driver, GlobalTestEnv.driver)68guards.add_condition(:browser, GlobalTestEnv.browser)69guards.add_condition(:ci, WebDriver::Platform.ci)70guards.add_condition(:platform, WebDriver::Platform.os)71guards.add_condition(:headless, !ENV['HEADLESS'].nil?)72guards.add_condition(:bidi, !ENV['WEBDRIVER_BIDI'].nil?)73guards.add_condition(:rbe, GlobalTestEnv.rbe?)74guards.add_condition(:version, GlobalTestEnv.browser_version)7576results = guards.disposition77send(*results) if results78end79end8081WebDriver::Platform.exit_hook { GlobalTestEnv.quit }8283$stdout.sync = true848586