Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/integration/selenium/webdriver/error_spec.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_relative 'spec_helper'
21
22
module Selenium
23
module WebDriver
24
describe Error, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do
25
it 'raises an appropriate error' do
26
driver.navigate.to url_for('xhtmlTest.html')
27
28
expect {
29
driver.find_element(id: 'nonexistent')
30
}.to raise_error(WebDriver::Error::NoSuchElementError, /#no-such-element-exception/)
31
end
32
33
it 'has backtrace locations' do
34
driver.find_element(id: 'nonexistent')
35
rescue WebDriver::Error::NoSuchElementError => e
36
expect(e.backtrace_locations).not_to be_empty
37
end
38
39
it 'has cause' do
40
driver.find_element(id: 'nonexistent')
41
rescue WebDriver::Error::NoSuchElementError => e
42
expect(e.cause).to be_a(WebDriver::Error::WebDriverError)
43
end
44
45
it 'has backtrace' do
46
driver.find_element(id: 'nonexistent')
47
rescue WebDriver::Error::NoSuchElementError => e
48
expect(e.backtrace).not_to be_empty
49
end
50
51
it 'has backtrace when using a remote server', only: {driver: :remote,
52
reason: 'This test should only apply to remote drivers'} do
53
unless driver.is_a?(WebDriver::Remote::Driver)
54
raise 'This error needs to be risen for the pending test not to fail on local drivers'
55
end
56
57
driver.send(:bridge).instance_variable_set(:@session_id, 'fake_session_id')
58
driver.window_handle
59
rescue WebDriver::Error::InvalidSessionIdError => e
60
expect(e.backtrace).not_to be_empty
61
end
62
end
63
end # WebDriver
64
end # Selenium
65
66