Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb
4211 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 Firefox
25
describe Driver, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, {browser: :firefox}] do
26
let(:extensions) { '../../../../../../common/extensions/' }
27
28
describe '#print_options' do
29
let(:magic_number) { 'JVBER' }
30
31
before { driver.navigate.to url_for('printPage.html') }
32
33
it 'returns base64 for print command' do
34
expect(driver.print_page).to include(magic_number)
35
end
36
37
it 'prints with orientation' do
38
expect(driver.print_page(orientation: 'landscape')).to include(magic_number)
39
end
40
41
it 'prints with valid params' do
42
expect(driver.print_page(orientation: 'landscape',
43
page_ranges: ['1-2'],
44
page: {width: 30})).to include(magic_number)
45
end
46
47
it 'prints full page', except: [{platform: :macosx,
48
reason: 'showing half resolution of what expected'}] do
49
viewport_width = driver.execute_script('return window.innerWidth;')
50
viewport_height = driver.execute_script('return window.innerHeight;')
51
52
path = "#{Dir.tmpdir}/test#{SecureRandom.urlsafe_base64}.png"
53
screenshot = driver.save_full_page_screenshot(path)
54
width, height = png_size(screenshot)
55
56
expect(width).to be >= viewport_width
57
expect(height).to be > viewport_height
58
ensure
59
FileUtils.rm_rf(path)
60
end
61
end
62
63
describe '#install_addon' do
64
it 'install and uninstall xpi file' do
65
ext = File.expand_path("#{extensions}/webextensions-selenium-example.xpi", __dir__)
66
id = driver.install_addon(ext)
67
68
expect(id).to eq '[email protected]'
69
driver.navigate.to url_for('blank.html')
70
71
injected = driver.find_element(id: 'webextensions-selenium-example')
72
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
73
74
driver.uninstall_addon(id)
75
driver.navigate.refresh
76
expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty
77
end
78
79
it 'install and uninstall signed zip file' do
80
ext = File.expand_path("#{extensions}/webextensions-selenium-example.zip", __dir__)
81
id = driver.install_addon(ext)
82
83
expect(id).to eq '[email protected]'
84
driver.navigate.to url_for('blank.html')
85
86
injected = driver.find_element(id: 'webextensions-selenium-example')
87
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
88
89
driver.uninstall_addon(id)
90
driver.navigate.refresh
91
expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty
92
end
93
94
it 'install and uninstall unsigned zip file' do
95
ext = File.expand_path("#{extensions}/webextensions-selenium-example-unsigned.zip", __dir__)
96
id = driver.install_addon(ext, true)
97
98
expect(id).to eq '[email protected]'
99
driver.navigate.to url_for('blank.html')
100
101
injected = driver.find_element(id: 'webextensions-selenium-example')
102
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
103
104
driver.uninstall_addon(id)
105
driver.navigate.refresh
106
expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty
107
end
108
109
it 'install and uninstall signed directory', except: {browser: :firefox,
110
platform: :windows,
111
reason: 'signature must be different for windows,
112
skipping everywhere until Firefox 127 is released'} do
113
ext = File.expand_path("#{extensions}/webextensions-selenium-example-signed/", __dir__)
114
id = driver.install_addon(ext)
115
116
expect(id).to eq '[email protected]'
117
driver.navigate.to url_for('blank.html')
118
119
injected = driver.find_element(id: 'webextensions-selenium-example')
120
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
121
122
driver.uninstall_addon(id)
123
driver.navigate.refresh
124
expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty
125
end
126
127
it 'install and uninstall unsigned directory' do
128
ext = File.expand_path("#{extensions}/webextensions-selenium-example/", __dir__)
129
id = driver.install_addon(ext, true)
130
131
expect(id).to eq '[email protected]'
132
driver.navigate.to url_for('blank.html')
133
134
injected = driver.find_element(id: 'webextensions-selenium-example')
135
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
136
137
driver.uninstall_addon(id)
138
driver.navigate.refresh
139
expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty
140
end
141
end
142
143
it 'can get and set context' do
144
reset_driver!(args: ['-remote-allow-system-access'],
145
prefs: {'browser.download.dir': 'foo/bar'}) do |driver|
146
expect(driver.context).to eq 'content'
147
148
driver.context = 'chrome'
149
expect(driver.context).to eq 'chrome'
150
151
# This call can not be made when context is set to 'content'
152
dir = driver.execute_script("return Services.prefs.getStringPref('browser.download.dir')")
153
expect(dir).to eq 'foo/bar'
154
end
155
end
156
end
157
end # Firefox
158
end # WebDriver
159
end # Selenium
160
161