"Fossies" - the Fresh Open Source Software Archive

Member "selenium-selenium-4.8.1/rb/lib/selenium/webdriver/support/guards.rb" (17 Feb 2023, 3141 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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_relative 'guards/guard_condition'
   21 require_relative 'guards/guard'
   22 
   23 module Selenium
   24   module WebDriver
   25     module Support
   26       class Guards
   27         GUARD_TYPES = %i[except only exclude exclusive].freeze
   28 
   29         attr_reader :messages
   30         attr_accessor :bug_tracker
   31 
   32         def initialize(example, bug_tracker: '', conditions: nil)
   33           @example = example
   34           @bug_tracker = bug_tracker
   35           @guard_conditions = conditions || []
   36           @guards = collect_example_guards
   37           @messages = {}
   38         end
   39 
   40         def add_condition(name, condition = nil, &blk)
   41           @guard_conditions << GuardCondition.new(name, condition, &blk)
   42         end
   43 
   44         def add_message(name, message)
   45           @messages[name] = message
   46         end
   47 
   48         def disposition
   49           if !skipping_guard.nil?
   50             [:skip, skipping_guard.message]
   51           elsif !pending_guard.nil? && ENV.fetch('SKIP_PENDING', nil)
   52             [:skip, pending_guard.message]
   53           elsif !pending_guard.nil?
   54             [:pending, pending_guard.message]
   55           end
   56         end
   57 
   58         def satisfied?(guard)
   59           @guard_conditions.all? { |condition| condition.satisfied?(guard) }
   60         end
   61 
   62         private
   63 
   64         def collect_example_guards
   65           guards = []
   66 
   67           GUARD_TYPES.each do |guard_type|
   68             example_group = @example.metadata[:example_group]
   69             example_guards = [@example.metadata[guard_type], example_group[guard_type]]
   70             while example_group[:parent_example_group]
   71               example_group = example_group[:parent_example_group]
   72               example_guards << example_group[guard_type]
   73             end
   74 
   75             example_guards.flatten.uniq.compact.each do |example_guard|
   76               guards << Guard.new(example_guard, guard_type, self)
   77             end
   78           end
   79 
   80           guards
   81         end
   82 
   83         def skipping_guard
   84           @guards.select(&:exclusive?).find { |guard| !satisfied?(guard) } ||
   85             @guards.select(&:exclude?).find { |guard| satisfied?(guard) }
   86         end
   87 
   88         def pending_guard
   89           @guards.select(&:except?).find { |guard| satisfied?(guard) } ||
   90             @guards.select(&:only?).find { |guard| !satisfied?(guard) }
   91         end
   92       end # Guards
   93     end # Support
   94   end # WebDriver
   95 end # Selenium