Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/integration/selenium/webdriver/remote/driver_spec.rb
1865 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
module Remote
25
describe Driver, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, {driver: :remote}] do
26
let(:tempfile) { create_tempfile }
27
28
it 'exposes session_id' do
29
expect(driver.session_id).to be_a(String)
30
end
31
32
it 'exposes remote status' do
33
expect(driver.status).to be_a(Hash)
34
end
35
36
it 'uses a default file detector',
37
flaky: {browser: :safari, ci: :github, reason: 'unreliable with downloads'} do
38
driver.navigate.to url_for('upload.html')
39
40
driver.find_element(id: 'upload').send_keys(tempfile.path)
41
driver.find_element(id: 'go').submit
42
wait.until { driver.find_element(id: 'upload_label').displayed? }
43
44
driver.switch_to.frame('upload_target')
45
wait.until { driver.find_element(xpath: '//body') }
46
47
body = driver.find_element(xpath: '//body')
48
expect(body.text.scan('This is a dummy test file').count).to eq(1)
49
end
50
51
it 'lists downloads', exclude: {browser: :safari, reason: 'grid hangs'} do
52
reset_driver!(enable_downloads: true) do |driver|
53
browser_downloads(driver)
54
55
file_names = %w[file_1.txt file_2.jpg]
56
57
expect(driver.downloadable_files).to match_array(file_names)
58
end
59
end
60
61
it 'downloads a file', exclude: {browser: :safari, reason: 'grid hangs'} do
62
target_directory = File.join(Dir.tmpdir.to_s, SecureRandom.uuid)
63
at_exit { FileUtils.rm_f(target_directory) }
64
65
reset_driver!(enable_downloads: true) do |driver|
66
browser_downloads(driver)
67
68
file_name = 'file_1.txt'
69
driver.download_file(file_name, target_directory)
70
71
file_content = File.read("#{target_directory}/#{file_name}").strip
72
expect(file_content).to eq('Hello, World!')
73
end
74
end
75
76
it 'deletes downloadable files', exclude: {browser: :safari, reason: 'grid hangs'} do
77
reset_driver!(enable_downloads: true) do |driver|
78
browser_downloads(driver)
79
80
driver.delete_downloadable_files
81
82
expect(driver.downloadable_files).to be_empty
83
end
84
end
85
86
it 'errors when not set', {except: {browser: :firefox, reason: 'grid always sets true and firefox returns it'},
87
exclude: {browser: :safari, reason: 'grid hangs'}} do
88
reset_driver!(enable_downloads: false) do |driver|
89
expect {
90
driver.downloadable_files
91
}.to raise_exception(Error::WebDriverError,
92
'You must enable downloads in order to work with downloadable files.')
93
end
94
end
95
96
private
97
98
def browser_downloads(driver)
99
driver.navigate.to url_for('downloads/download.html')
100
driver.find_element(id: 'file-1').click
101
driver.find_element(id: 'file-2').click
102
103
wait.until { driver.downloadable_files.include? 'file_2.jpg' }
104
end
105
end
106
end # Remote
107
end # WebDriver
108
end # Selenium
109
110