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
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 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: :windows,
48
reason: 'Some issues with resolution?'},
49
{platform: :macosx,
50
reason: 'showing half resolution of what expected'}] do
51
viewport_width = driver.execute_script('return window.innerWidth;')
52
viewport_height = driver.execute_script('return window.innerHeight;')
53
54
path = "#{Dir.tmpdir}/test#{SecureRandom.urlsafe_base64}.png"
55
screenshot = driver.save_full_page_screenshot(path)
56
width, height = png_size(screenshot)
57
58
expect(width).to be >= viewport_width
59
expect(height).to be > viewport_height
60
ensure
61
FileUtils.rm_rf(path)
62
end
63
end
64
65
describe '#install_addon' do
66
it 'install and uninstall xpi file' do
67
ext = File.expand_path("#{extensions}/webextensions-selenium-example.xpi", __dir__)
68
id = driver.install_addon(ext)
69
70
expect(id).to eq '[email protected]'
71
driver.navigate.to url_for('blank.html')
72
73
injected = driver.find_element(id: 'webextensions-selenium-example')
74
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
75
76
driver.uninstall_addon(id)
77
driver.navigate.refresh
78
expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty
79
end
80
81
it 'install and uninstall signed zip file' do
82
ext = File.expand_path("#{extensions}/webextensions-selenium-example.zip", __dir__)
83
id = driver.install_addon(ext)
84
85
expect(id).to eq '[email protected]'
86
driver.navigate.to url_for('blank.html')
87
88
injected = driver.find_element(id: 'webextensions-selenium-example')
89
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
90
91
driver.uninstall_addon(id)
92
driver.navigate.refresh
93
expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty
94
end
95
96
it 'install and uninstall unsigned zip file' do
97
ext = File.expand_path("#{extensions}/webextensions-selenium-example-unsigned.zip", __dir__)
98
id = driver.install_addon(ext, true)
99
100
expect(id).to eq '[email protected]'
101
driver.navigate.to url_for('blank.html')
102
103
injected = driver.find_element(id: 'webextensions-selenium-example')
104
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
105
106
driver.uninstall_addon(id)
107
driver.navigate.refresh
108
expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty
109
end
110
111
it 'install and uninstall signed directory', except: {browser: :firefox,
112
platform: :windows,
113
reason: 'signature must be different for windows,
114
skipping everywhere until Firefox 127 is released'} do
115
ext = File.expand_path("#{extensions}/webextensions-selenium-example-signed/", __dir__)
116
id = driver.install_addon(ext)
117
118
expect(id).to eq '[email protected]'
119
driver.navigate.to url_for('blank.html')
120
121
injected = driver.find_element(id: 'webextensions-selenium-example')
122
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
123
124
driver.uninstall_addon(id)
125
driver.navigate.refresh
126
expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty
127
end
128
129
it 'install and uninstall unsigned directory' do
130
ext = File.expand_path("#{extensions}/webextensions-selenium-example/", __dir__)
131
id = driver.install_addon(ext, true)
132
133
expect(id).to eq '[email protected]'
134
driver.navigate.to url_for('blank.html')
135
136
injected = driver.find_element(id: 'webextensions-selenium-example')
137
expect(injected.text).to eq 'Content injected by webextensions-selenium-example'
138
139
driver.uninstall_addon(id)
140
driver.navigate.refresh
141
expect(driver.find_elements(id: 'webextensions-selenium-example')).to be_empty
142
end
143
end
144
145
it 'can get and set context' do
146
reset_driver!(args: ['-remote-allow-system-access'],
147
prefs: {'browser.download.dir': 'foo/bar'}) do |driver|
148
expect(driver.context).to eq 'content'
149
150
driver.context = 'chrome'
151
expect(driver.context).to eq 'chrome'
152
153
# This call can not be made when context is set to 'content'
154
dir = driver.execute_script("return Services.prefs.getStringPref('browser.download.dir')")
155
expect(dir).to eq 'foo/bar'
156
end
157
end
158
end
159
end # Firefox
160
end # WebDriver
161
end # Selenium
162
163