|
22 | 22 | module Selenium |
23 | 23 | module WebDriver |
24 | 24 | module Firefox |
25 | | - describe Profile do |
26 | | - let(:profile) { Profile.new } |
27 | | - let(:browser) { GlobalTestEnv.driver == :remote ? :remote : :firefox } |
| 25 | + compliant_on browser: :firefox do |
| 26 | + describe Profile do |
| 27 | + let(:profile) { Profile.new } |
| 28 | + let(:browser) { GlobalTestEnv.driver == :remote ? :remote : :firefox } |
28 | 29 |
|
29 | | - def read_generated_prefs(from = nil) |
30 | | - prof = from || profile |
31 | | - dir = prof.layout_on_disk |
| 30 | + def read_generated_prefs(from = nil) |
| 31 | + prof = from || profile |
| 32 | + dir = prof.layout_on_disk |
32 | 33 |
|
33 | | - File.read(File.join(dir, 'user.js')) |
34 | | - end |
| 34 | + File.read(File.join(dir, 'user.js')) |
| 35 | + end |
35 | 36 |
|
36 | | - def profile_opts |
37 | | - if GlobalTestEnv.driver == :remote |
38 | | - opt = { desired_capabilities: GlobalTestEnv.remote_capabilities.dup } |
39 | | - opt[:desired_capabilities][:firefox_profile] = profile |
40 | | - opt[:url] = GlobalTestEnv.remote_server.webdriver_url if GlobalTestEnv.remote_server? |
41 | | - opt |
42 | | - else |
43 | | - { desired_capabilities: Remote::Capabilities.firefox(marionette: GlobalTestEnv.browser == :firefox), |
44 | | - profile: profile } |
| 37 | + def profile_opts |
| 38 | + if GlobalTestEnv.driver == :remote |
| 39 | + opt = {desired_capabilities: GlobalTestEnv.remote_capabilities.dup} |
| 40 | + opt[:desired_capabilities][:firefox_profile] = profile |
| 41 | + opt[:url] = GlobalTestEnv.remote_server.webdriver_url if GlobalTestEnv.remote_server? |
| 42 | + opt |
| 43 | + else |
| 44 | + {desired_capabilities: Remote::Capabilities.firefox(marionette: GlobalTestEnv.browser == :firefox), |
| 45 | + profile: profile} |
| 46 | + end |
45 | 47 | end |
46 | | - end |
47 | 48 |
|
48 | | - it 'should set additional preferences' do |
49 | | - profile['foo.number'] = 123 |
50 | | - profile['foo.boolean'] = true |
51 | | - profile['foo.string'] = 'bar' |
| 49 | + it 'should set additional preferences' do |
| 50 | + profile['foo.number'] = 123 |
| 51 | + profile['foo.boolean'] = true |
| 52 | + profile['foo.string'] = 'bar' |
52 | 53 |
|
53 | | - string = read_generated_prefs |
54 | | - expect(string).to include('user_pref("foo.number", 123)') |
55 | | - expect(string).to include('user_pref("foo.boolean", true)') |
56 | | - expect(string).to include(%{user_pref("foo.string", "bar")}) |
57 | | - end |
| 54 | + string = read_generated_prefs |
| 55 | + expect(string).to include('user_pref("foo.number", 123)') |
| 56 | + expect(string).to include('user_pref("foo.boolean", true)') |
| 57 | + expect(string).to include(%{user_pref("foo.string", "bar")}) |
| 58 | + end |
58 | 59 |
|
59 | | - it 'should be serializable to JSON' do |
60 | | - profile['foo.boolean'] = true |
| 60 | + it 'should be serializable to JSON' do |
| 61 | + profile['foo.boolean'] = true |
61 | 62 |
|
62 | | - new_profile = Profile.from_json(profile.to_json) |
63 | | - string = read_generated_prefs(new_profile) |
64 | | - expect(string).to include('user_pref("foo.boolean", true)') |
65 | | - end |
| 63 | + new_profile = Profile.from_json(profile.to_json) |
| 64 | + string = read_generated_prefs(new_profile) |
| 65 | + expect(string).to include('user_pref("foo.boolean", true)') |
| 66 | + end |
66 | 67 |
|
67 | | - it 'should not let user override defaults' do |
68 | | - profile['app.update.enabled'] = true |
| 68 | + it 'should not let user override defaults' do |
| 69 | + profile['app.update.enabled'] = true |
69 | 70 |
|
70 | | - string = read_generated_prefs |
71 | | - expect(string).to include('user_pref("app.update.enabled", false)') |
72 | | - end |
73 | | - |
74 | | - it 'should properly handle escaped characters' do |
75 | | - profile['foo'] = 'C:\\r\\n' |
| 71 | + string = read_generated_prefs |
| 72 | + expect(string).to include('user_pref("app.update.enabled", false)') |
| 73 | + end |
76 | 74 |
|
77 | | - string = read_generated_prefs |
78 | | - expect(string).to include('user_pref("foo", "C:\\\\r\\\\n");') |
79 | | - end |
| 75 | + it 'should properly handle escaped characters' do |
| 76 | + profile['foo'] = 'C:\\r\\n' |
80 | 77 |
|
81 | | - it 'should let the user override some specific prefs' do |
82 | | - profile['browser.startup.page'] = 'http://example.com' |
| 78 | + string = read_generated_prefs |
| 79 | + expect(string).to include('user_pref("foo", "C:\\\\r\\\\n");') |
| 80 | + end |
83 | 81 |
|
84 | | - string = read_generated_prefs |
85 | | - expect(string).to include(%{user_pref("browser.startup.page", "http://example.com")}) |
86 | | - end |
| 82 | + it 'should let the user override some specific prefs' do |
| 83 | + profile['browser.startup.page'] = 'http://example.com' |
87 | 84 |
|
88 | | - it 'should raise an error if the value given is not a string, number or boolean' do |
89 | | - expect { profile['foo.bar'] = [] }.to raise_error(TypeError) |
90 | | - end |
| 85 | + string = read_generated_prefs |
| 86 | + expect(string).to include(%{user_pref("browser.startup.page", "http://example.com")}) |
| 87 | + end |
91 | 88 |
|
92 | | - it 'should raise an error if the value is already stringified' do |
93 | | - expect { profile['foo.bar'] = '"stringified"' }.to raise_error(ArgumentError) |
94 | | - end |
| 89 | + it 'should raise an error if the value given is not a string, number or boolean' do |
| 90 | + expect { profile['foo.bar'] = [] }.to raise_error(TypeError) |
| 91 | + end |
95 | 92 |
|
96 | | - it 'should enable secure SSL' do |
97 | | - profile.secure_ssl = true |
| 93 | + it 'should raise an error if the value is already stringified' do |
| 94 | + expect { profile['foo.bar'] = '"stringified"' }.to raise_error(ArgumentError) |
| 95 | + end |
98 | 96 |
|
99 | | - string = read_generated_prefs |
100 | | - expect(string).to include('user_pref("webdriver_accept_untrusted_certs", false)') |
101 | | - end |
| 97 | + it 'should enable secure SSL' do |
| 98 | + profile.secure_ssl = true |
102 | 99 |
|
103 | | - it 'should disable secure SSL' do |
104 | | - profile.secure_ssl = false |
| 100 | + string = read_generated_prefs |
| 101 | + expect(string).to include('user_pref("webdriver_accept_untrusted_certs", false)') |
| 102 | + end |
105 | 103 |
|
106 | | - string = read_generated_prefs |
107 | | - expect(string).to include('user_pref("webdriver_accept_untrusted_certs", true)') |
108 | | - end |
| 104 | + it 'should disable secure SSL' do |
| 105 | + profile.secure_ssl = false |
109 | 106 |
|
110 | | - it 'should change the setting for untrusted certificate issuer' do |
111 | | - profile.assume_untrusted_certificate_issuer = false |
| 107 | + string = read_generated_prefs |
| 108 | + expect(string).to include('user_pref("webdriver_accept_untrusted_certs", true)') |
| 109 | + end |
112 | 110 |
|
113 | | - string = read_generated_prefs |
114 | | - expect(string).to include('user_pref("webdriver_assume_untrusted_issuer", false)') |
115 | | - end |
| 111 | + it 'should change the setting for untrusted certificate issuer' do |
| 112 | + profile.assume_untrusted_certificate_issuer = false |
116 | 113 |
|
117 | | - it 'can configure a manual proxy' do |
118 | | - proxy = Proxy.new( |
119 | | - http: 'foo:123', |
120 | | - ftp: 'bar:234', |
121 | | - ssl: 'baz:345', |
122 | | - no_proxy: 'localhost' |
123 | | - ) |
| 114 | + string = read_generated_prefs |
| 115 | + expect(string).to include('user_pref("webdriver_assume_untrusted_issuer", false)') |
| 116 | + end |
124 | 117 |
|
125 | | - profile.proxy = proxy |
126 | | - string = read_generated_prefs |
| 118 | + it 'can configure a manual proxy' do |
| 119 | + proxy = Proxy.new( |
| 120 | + http: 'foo:123', |
| 121 | + ftp: 'bar:234', |
| 122 | + ssl: 'baz:345', |
| 123 | + no_proxy: 'localhost' |
| 124 | + ) |
127 | 125 |
|
128 | | - expect(string).to include('user_pref("network.proxy.http", "foo")') |
129 | | - expect(string).to include('user_pref("network.proxy.http_port", 123)') |
| 126 | + profile.proxy = proxy |
| 127 | + string = read_generated_prefs |
130 | 128 |
|
131 | | - expect(string).to include('user_pref("network.proxy.ftp", "bar")') |
132 | | - expect(string).to include('user_pref("network.proxy.ftp_port", 234)') |
| 129 | + expect(string).to include('user_pref("network.proxy.http", "foo")') |
| 130 | + expect(string).to include('user_pref("network.proxy.http_port", 123)') |
133 | 131 |
|
134 | | - expect(string).to include('user_pref("network.proxy.ssl", "baz")') |
135 | | - expect(string).to include('user_pref("network.proxy.ssl_port", 345)') |
| 132 | + expect(string).to include('user_pref("network.proxy.ftp", "bar")') |
| 133 | + expect(string).to include('user_pref("network.proxy.ftp_port", 234)') |
136 | 134 |
|
137 | | - expect(string).to include('user_pref("network.proxy.no_proxies_on", "localhost")') |
138 | | - expect(string).to include('user_pref("network.proxy.type", 1)') |
139 | | - end |
| 135 | + expect(string).to include('user_pref("network.proxy.ssl", "baz")') |
| 136 | + expect(string).to include('user_pref("network.proxy.ssl_port", 345)') |
140 | 137 |
|
141 | | - it 'can configure a PAC proxy' do |
142 | | - profile.proxy = Proxy.new(pac: 'http://foo/bar.pac') |
143 | | - string = read_generated_prefs |
| 138 | + expect(string).to include('user_pref("network.proxy.no_proxies_on", "localhost")') |
| 139 | + expect(string).to include('user_pref("network.proxy.type", 1)') |
| 140 | + end |
144 | 141 |
|
145 | | - expect(string).to include('user_pref("network.proxy.autoconfig_url", "http://foo/bar.pac")') |
146 | | - expect(string).to include('user_pref("network.proxy.type", 2)') |
147 | | - end |
| 142 | + it 'can configure a PAC proxy' do |
| 143 | + profile.proxy = Proxy.new(pac: 'http://foo/bar.pac') |
| 144 | + string = read_generated_prefs |
148 | 145 |
|
149 | | - it 'can configure an auto-detected proxy' do |
150 | | - profile.proxy = Proxy.new(auto_detect: true) |
151 | | - string = read_generated_prefs |
| 146 | + expect(string).to include('user_pref("network.proxy.autoconfig_url", "http://foo/bar.pac")') |
| 147 | + expect(string).to include('user_pref("network.proxy.type", 2)') |
| 148 | + end |
152 | 149 |
|
153 | | - expect(string).to include('user_pref("network.proxy.type", 4)') |
154 | | - end |
| 150 | + it 'can configure an auto-detected proxy' do |
| 151 | + profile.proxy = Proxy.new(auto_detect: true) |
| 152 | + string = read_generated_prefs |
155 | 153 |
|
156 | | - describe 'with browser' do |
157 | | - before(:each) do |
158 | | - profile['browser.startup.homepage'] = url_for('simpleTest.html') |
159 | | - profile['browser.startup.page'] = 1 |
| 154 | + expect(string).to include('user_pref("network.proxy.type", 4)') |
160 | 155 | end |
161 | 156 |
|
162 | | - it 'should instantiate the browser with the correct profile' do |
163 | | - begin |
164 | | - driver1 = WebDriver.for(browser, profile_opts.dup) |
165 | | - expect{ wait(5).until { driver1.find_element(id: 'oneline') } }.to_not raise_error |
166 | | - ensure |
167 | | - driver1.quit |
| 157 | + describe 'with browser' do |
| 158 | + before(:each) do |
| 159 | + profile['browser.startup.homepage'] = url_for('simpleTest.html') |
| 160 | + profile['browser.startup.page'] = 1 |
| 161 | + end |
| 162 | + |
| 163 | + it 'should instantiate the browser with the correct profile' do |
| 164 | + begin |
| 165 | + driver1 = WebDriver.for(browser, profile_opts.dup) |
| 166 | + expect { wait(5).until { driver1.find_element(id: 'oneline') } }.to_not raise_error |
| 167 | + ensure |
| 168 | + driver1.quit |
| 169 | + end |
168 | 170 | end |
169 | | - end |
170 | 171 |
|
171 | | - it 'should be able to use the same profile more than once' do |
172 | | - begin |
173 | | - driver1 = WebDriver.for(browser, profile_opts.dup) |
174 | | - expect{ wait(5).until { driver1.find_element(id: 'oneline') } }.to_not raise_error |
175 | | - driver2 = WebDriver.for(browser, profile_opts.dup) |
176 | | - expect{ wait(5).until { driver2.find_element(id: 'oneline') } }.to_not raise_error |
177 | | - ensure |
178 | | - driver1.quit if driver1 |
179 | | - driver2.quit if driver2 |
| 172 | + it 'should be able to use the same profile more than once' do |
| 173 | + begin |
| 174 | + driver1 = WebDriver.for(browser, profile_opts.dup) |
| 175 | + expect { wait(5).until { driver1.find_element(id: 'oneline') } }.to_not raise_error |
| 176 | + driver2 = WebDriver.for(browser, profile_opts.dup) |
| 177 | + expect { wait(5).until { driver2.find_element(id: 'oneline') } }.to_not raise_error |
| 178 | + ensure |
| 179 | + driver1.quit if driver1 |
| 180 | + driver2.quit if driver2 |
| 181 | + end |
180 | 182 | end |
181 | 183 | end |
182 | 184 | end |
|
0 commit comments