Path: blob/trunk/rb/spec/integration/selenium/webdriver/timeout_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 Timeouts, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do24before do25driver.manage.timeouts.implicit_wait = 626driver.manage.timeouts.page_load = 227driver.manage.timeouts.script = 1.528driver.navigate.to url_for('dynamic.html')29end3031after do32driver.manage.timeouts.implicit_wait = 033driver.manage.timeouts.page_load = 30034driver.manage.timeouts.script = 3035end3637it 'gets all the timeouts' do38expect(driver.manage.timeouts.implicit_wait).to eq(6)39expect(driver.manage.timeouts.page_load).to eq(2)40expect(driver.manage.timeouts.script).to eq(1.5)41end4243describe 'implicit waits' do44it 'implicitlies wait for a single element' do45driver.find_element(id: 'adder').click46expect { driver.find_element(id: 'box0') }.not_to raise_error47end4849it 'stills fail to find an element with implicit waits enabled' do50driver.manage.timeouts.implicit_wait = 0.151expect { driver.find_element(id: 'box0') }.to raise_error(WebDriver::Error::NoSuchElementError)52end5354it 'returns after first attempt to find one after disabling implicit waits' do55driver.manage.timeouts.implicit_wait = 056expect { driver.find_element(id: 'box0') }.to raise_error(WebDriver::Error::NoSuchElementError)57end5859it 'implicitlies wait until at least one element is found when searching for many' do60add = driver.find_element(id: 'adder')6162add.click63add.click6465expect(driver.find_elements(class_name: 'redbox')).not_to be_empty66end6768it 'stills fail to find elements when implicit waits are enabled' do69driver.manage.timeouts.implicit_wait = 0.170expect(driver.find_elements(class_name: 'redbox')).to be_empty71end7273it 'returns after first attempt to find many after disabling implicit waits' do74add = driver.find_element(id: 'adder')7576driver.manage.timeouts.implicit_wait = 077add.click7879expect(driver.find_elements(class_name: 'redbox')).to be_empty80end81end8283describe 'page load' do84it 'times out if page takes too long to load' do85expect { driver.navigate.to url_for('sleep?time=3') }.to raise_error(WebDriver::Error::TimeoutError)86end8788it 'times out if page takes too long to load after click', except: {browser: %i[safari safari_preview]} do89driver.navigate.to url_for('page_with_link_to_slow_loading_page.html')9091expect {92driver.find_element(id: 'link-to-slow-loading-page').click93}.to raise_error(WebDriver::Error::TimeoutError)94end95end96end97end # WebDriver98end # Selenium99100101