Path: blob/trunk/rb/spec/unit/selenium/webdriver/wait_spec.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_relative 'spec_helper'2021module Selenium22module WebDriver23describe Wait do24def wait(*args)25Wait.new(*args)26end2728it 'waits until the returned value is true' do29returned = true30expect(wait.until { returned = !returned }).to be true31end3233it 'raises a TimeoutError if the the timer runs out' do34expect {35wait(timeout: 0.1).until { false }36}.to raise_error(Error::TimeoutError)37end3839it 'silentlies capture NoSuchElementErrors' do40called = false41block = lambda do42if called43true44else45called = true46raise Error::NoSuchElementError47end48end4950expect(wait.until(&block)).to be true51end5253it 'uses the message from any NoSuchElementError raised while waiting' do54block = -> { raise Error::NoSuchElementError, 'foo' }5556expect {57wait(timeout: 0.5).until(&block)58}.to raise_error(Error::TimeoutError, /foo/)59end6061it 'lets users configure what exceptions to ignore' do62expect {63wait(ignore: NoMethodError, timeout: 0.5).until { raise NoMethodError }64}.to raise_error(Error::TimeoutError, /NoMethodError/)65end66end67end # WebDriver68end # Selenium697071