webdriver-user-agent 7.6 → 7.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/device-info/devices.yaml +86 -40
- data/lib/webdriver-user-agent.rb +14 -13
- data/lib/webdriver-user-agent/browser_options.rb +27 -11
- data/spec/webdriver-user-agent_spec.rb +310 -118
- data/webdriver-user-agent.gemspec +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f103f486777f7dffc40b6177cbd52c1ed13826daf41c500f8f69f1869e71c6f
|
4
|
+
data.tar.gz: 4844156cef409e1c77d5e4610b3e51e1c995954edc3e0823fd4651255b5372fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f297ddcf8064c4c6a37c550f0bf2ea57e4d3ca6cc60856315f9656b15426ca36357173ac87b246dde72d8f9d9f05d929f35aa82ee6f72461d47409556bdfa23
|
7
|
+
data.tar.gz: 69368f91ffb7b262a7b45161dc4099fa80230d4bca0792b7d1baf80d130e1876850a970dce3b79b2dbae926eddd257dcf7a2ca0584a8cf329f27966941c1b978
|
@@ -1,9 +1,20 @@
|
|
1
1
|
# Desktop size sources
|
2
|
-
# http://www.hobo-web.co.uk/best-screen-size/
|
3
|
-
# https://en.wikipedia.org/wiki/Display_resolution#Common_display_resolutions
|
4
|
-
# http://www.w3schools.com/browsers/browsers_display.asp
|
2
|
+
# - http://www.hobo-web.co.uk/best-screen-size/
|
3
|
+
# - https://en.wikipedia.org/wiki/Display_resolution#Common_display_resolutions
|
4
|
+
# - http://www.w3schools.com/browsers/browsers_display.asp
|
5
|
+
|
6
|
+
# iPhone and iPad data added by running Simulator on macOS and visiting
|
7
|
+
# https://whatismyviewport.com and
|
8
|
+
# https://www.whatismybrowser.com/detect/what-is-my-user-agent
|
9
|
+
|
10
|
+
# Android user agents and viewports from current android device specs.
|
11
|
+
# Tablet: Samsung Galaxy Tab S6; Phone: Google Pixel 4
|
12
|
+
# Determined without a simulator to account for software chrome,
|
13
|
+
# so these figures are necessarily larger than what will be true
|
14
|
+
# on those devices. Please feel free to submit a pull request
|
15
|
+
# with corrected and/or expanded device values.
|
5
16
|
:desktop:
|
6
|
-
:user_agent:
|
17
|
+
:user_agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15
|
7
18
|
:portrait:
|
8
19
|
:width: 768
|
9
20
|
:height: 1024
|
@@ -11,26 +22,28 @@
|
|
11
22
|
:width: 1366
|
12
23
|
:height: 768
|
13
24
|
:iphone_default: &iphone_default
|
14
|
-
:user_agent:
|
25
|
+
:user_agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1
|
15
26
|
:portrait:
|
16
|
-
:width:
|
17
|
-
:height:
|
27
|
+
:width: 414
|
28
|
+
:height: 719
|
18
29
|
:landscape:
|
19
|
-
:width:
|
20
|
-
:height:
|
30
|
+
:width: 808
|
31
|
+
:height: 414
|
21
32
|
:iphone: &iphone
|
22
|
-
<<: *iphone_default
|
23
|
-
:iphonex:
|
24
33
|
<<: *iphone_default
|
25
|
-
:
|
34
|
+
:iphone11pro:
|
26
35
|
<<: *iphone_default
|
27
36
|
:portrait:
|
28
|
-
:width:
|
29
|
-
:height:
|
37
|
+
:width: 375
|
38
|
+
:height: 635
|
30
39
|
:landscape:
|
31
|
-
:width:
|
32
|
-
:height:
|
33
|
-
:
|
40
|
+
:width: 724
|
41
|
+
:height: 375
|
42
|
+
:iphone11promax:
|
43
|
+
<<: *iphone_default
|
44
|
+
:iphone11:
|
45
|
+
<<: *iphone_default
|
46
|
+
:iphonese: &iphonese
|
34
47
|
<<: *iphone_default
|
35
48
|
:portrait:
|
36
49
|
:width: 375
|
@@ -38,11 +51,34 @@
|
|
38
51
|
:landscape:
|
39
52
|
:width: 667
|
40
53
|
:height: 375
|
54
|
+
:iphonexr: &iphonexr
|
55
|
+
<<: *iphone_default
|
56
|
+
:iphonexsmax:
|
57
|
+
<<: *iphonexr
|
58
|
+
:iphonexs: &iphonexs
|
59
|
+
<<: *iphone_default
|
60
|
+
:portrait:
|
61
|
+
:width: 375
|
62
|
+
:height: 635
|
63
|
+
:landscape:
|
64
|
+
:width: 724
|
65
|
+
:height: 375
|
66
|
+
:iphonex:
|
67
|
+
<<: *iphonexs
|
68
|
+
:iphone8plus: &iphone8plus
|
69
|
+
<<: *iphone_default
|
70
|
+
:portrait:
|
71
|
+
:width: 414
|
72
|
+
:height: 622
|
73
|
+
:landscape:
|
74
|
+
:width: 736
|
75
|
+
:height: 414
|
76
|
+
:iphone8: &iphone8
|
77
|
+
<<: *iphonese
|
41
78
|
:iphone7plus:
|
42
79
|
<<: *iphone8plus
|
43
80
|
:iphone7:
|
44
81
|
<<: *iphone8
|
45
|
-
:portrait:
|
46
82
|
:iphone6splus:
|
47
83
|
<<: *iphone8plus
|
48
84
|
:iphone6s:
|
@@ -59,7 +95,7 @@
|
|
59
95
|
:landscape:
|
60
96
|
:width: 568
|
61
97
|
:height: 320
|
62
|
-
:
|
98
|
+
:iphonese_old:
|
63
99
|
<<: *iphone5s
|
64
100
|
:iphone5:
|
65
101
|
<<: *iphone5s
|
@@ -74,33 +110,33 @@
|
|
74
110
|
:iphone4:
|
75
111
|
<<: *iphone4s
|
76
112
|
:ipad: &ipad
|
77
|
-
:user_agent:
|
113
|
+
:user_agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15
|
78
114
|
:portrait:
|
79
|
-
:width:
|
80
|
-
:height:
|
115
|
+
:width: 810
|
116
|
+
:height: 1010
|
81
117
|
:landscape:
|
82
|
-
:width:
|
83
|
-
:height:
|
118
|
+
:width: 1080
|
119
|
+
:height: 740
|
84
120
|
:ipad_default:
|
85
121
|
<<: *ipad
|
86
122
|
:ipad_pro: &ipad_pro
|
87
123
|
<<: *ipad
|
88
124
|
:portrait:
|
89
125
|
:width: 1024
|
90
|
-
:height:
|
126
|
+
:height: 1292
|
91
127
|
:landscape:
|
92
128
|
:width: 1366
|
93
|
-
:height:
|
129
|
+
:height: 950
|
94
130
|
:ipad_pro_12:
|
95
131
|
<<: *ipad_pro
|
96
|
-
:
|
132
|
+
:ipad_pro_11:
|
97
133
|
<<: *ipad
|
98
134
|
:portrait:
|
99
135
|
:width: 834
|
100
|
-
:height:
|
136
|
+
:height: 1120
|
101
137
|
:landscape:
|
102
|
-
:width:
|
103
|
-
:height:
|
138
|
+
:width: 1194
|
139
|
+
:height: 760
|
104
140
|
:ipad_pro_9:
|
105
141
|
<<: *ipad
|
106
142
|
:portrait:
|
@@ -109,19 +145,29 @@
|
|
109
145
|
:landscape:
|
110
146
|
:width: 1024
|
111
147
|
:height: 698
|
148
|
+
:ipad_air: &ipad_air
|
149
|
+
<<: *ipad
|
150
|
+
:portrait:
|
151
|
+
:width: 834
|
152
|
+
:height: 1038
|
153
|
+
:landscape:
|
154
|
+
:width: 1112
|
155
|
+
:height: 760
|
156
|
+
:ipad_pro_10:
|
157
|
+
<<: *ipad_air
|
112
158
|
:android_phone:
|
113
|
-
:user_agent:
|
159
|
+
:user_agent: Mozilla/5.0 (Linux; Android 10; Pixel) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Mobile Safari/537.36
|
114
160
|
:portrait:
|
115
|
-
:width:
|
116
|
-
:height:
|
161
|
+
:width: 411
|
162
|
+
:height: 869
|
117
163
|
:landscape:
|
118
|
-
:width:
|
119
|
-
:height:
|
164
|
+
:width: 869
|
165
|
+
:height: 411
|
120
166
|
:android_tablet:
|
121
|
-
:user_agent:
|
167
|
+
:user_agent: Mozilla/5.0 (Linux; Android 9; SAMSUNG SM-T865) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/10.1 Chrome/71.0.3578.99 Safari/537.36
|
122
168
|
:portrait:
|
123
|
-
:width:
|
124
|
-
:height:
|
169
|
+
:width: 800
|
170
|
+
:height: 1280
|
125
171
|
:landscape:
|
126
|
-
:width:
|
127
|
-
:height:
|
172
|
+
:width: 1280
|
173
|
+
:height: 800
|
data/lib/webdriver-user-agent.rb
CHANGED
@@ -3,21 +3,22 @@ require 'webdriver-user-agent/driver'
|
|
3
3
|
|
4
4
|
module Webdriver
|
5
5
|
module UserAgent
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
class << self
|
7
|
+
def driver(options = {})
|
8
|
+
Driver.instance.for options
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def devices
|
12
|
+
Driver.instance.devices
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def self.agent_string_for device
|
19
|
-
Driver.instance.agent_string_for device
|
20
|
-
end
|
15
|
+
def resolution_for(device_name, orientation)
|
16
|
+
Driver.instance.resolution_for device_name, orientation
|
17
|
+
end
|
21
18
|
|
19
|
+
def agent_string_for(device)
|
20
|
+
Driver.instance.agent_string_for device
|
21
|
+
end
|
22
|
+
end
|
22
23
|
end
|
23
24
|
end
|
@@ -19,7 +19,7 @@ module Webdriver
|
|
19
19
|
|
20
20
|
options[:viewport_width], options[:viewport_height] = parse_viewport_sizes(options[:viewport_width], options[:viewport_height])
|
21
21
|
|
22
|
-
initialize_for_browser(user_agent_string, opts[:accept_language_string])
|
22
|
+
initialize_for_browser(user_agent_string, opts[:accept_language_string], opts[:options])
|
23
23
|
end
|
24
24
|
|
25
25
|
def method_missing(*args, &block)
|
@@ -44,23 +44,32 @@ module Webdriver
|
|
44
44
|
@stp = false unless @stp.is_a?(TrueClass)
|
45
45
|
end
|
46
46
|
|
47
|
-
def initialize_for_browser(user_agent_string, accept_language_string)
|
47
|
+
def initialize_for_browser(user_agent_string, accept_language_string, driver_options = nil)
|
48
|
+
options[:options] ||= driver_options
|
49
|
+
|
48
50
|
case options[:browser]
|
49
51
|
when :firefox
|
50
|
-
profile ||= Selenium::WebDriver::Firefox::Profile.new
|
51
|
-
profile['general.useragent.override'] = user_agent_string
|
52
|
-
profile['intl.accept_languages'] = accept_language_string if accept_language_string
|
53
|
-
|
54
52
|
options[:options] ||= Selenium::WebDriver::Firefox::Options.new
|
53
|
+
|
54
|
+
profile ||= options[:options].profile || Selenium::WebDriver::Firefox::Profile.new
|
55
|
+
set_keys = profile.instance_variable_get(:@additional_prefs).keys
|
56
|
+
|
57
|
+
profile['general.useragent.override'] = user_agent_string if !set_keys.include?('general.useragent.override')
|
58
|
+
profile['intl.accept_languages'] = accept_language_string if accept_language_string && !set_keys.include?('intl.accept_languages')
|
59
|
+
|
55
60
|
options[:options].profile = profile
|
56
61
|
when :chrome
|
57
62
|
options[:options] ||= Selenium::WebDriver::Chrome::Options.new
|
58
|
-
|
59
|
-
options[:options].
|
63
|
+
|
64
|
+
set_args = options[:options].args.map{|s| "#{s}"}.join(" ")
|
65
|
+
options[:options].add_argument "--user-agent=#{user_agent_string}" if !set_args.include?("--user-agent=")
|
66
|
+
|
67
|
+
set_prefs = options[:options].prefs.keys
|
68
|
+
options[:options].add_preference("intl.accept_languages", accept_language_string) if accept_language_string && !set_prefs.include?("intl.accept_languages")
|
60
69
|
when :safari
|
70
|
+
options[:options] ||= Selenium::WebDriver::Safari::Options.new
|
61
71
|
change_safari_user_agent_string(user_agent_string)
|
62
72
|
change_safari_language(accept_language_string) if accept_language_string
|
63
|
-
options
|
64
73
|
else
|
65
74
|
raise "WebDriver UserAgent currently only supports :chrome, :firefox and :safari."
|
66
75
|
end
|
@@ -88,10 +97,17 @@ module Webdriver
|
|
88
97
|
raise "Safari requires a Mac" unless OS.mac?
|
89
98
|
|
90
99
|
cmd = "defaults write com.apple.#{safari_version} #{pref} #{setting}"
|
91
|
-
|
92
100
|
output = `#{cmd}`
|
93
101
|
|
94
|
-
raise prepare_safari_error_message(cmd, output) unless
|
102
|
+
raise prepare_safari_error_message(cmd, output) unless safari_command_success?(setting, safari_version, pref, $?)
|
103
|
+
end
|
104
|
+
|
105
|
+
def safari_command_success?(setting, safari_version, pref, result)
|
106
|
+
setting_chars = "#{setting}".gsub(/\W/, '')
|
107
|
+
read_chars = `defaults read com.apple.#{safari_version} #{pref}`.gsub(/\W/, '')
|
108
|
+
|
109
|
+
setting_match = (setting_chars == read_chars)
|
110
|
+
setting_match && result.success?
|
95
111
|
end
|
96
112
|
|
97
113
|
def safari_version
|
@@ -9,14 +9,78 @@ require 'webdrivers'
|
|
9
9
|
|
10
10
|
CHROMEBROWSER_UICHROME_HEIGHT = 123
|
11
11
|
CHROMEBROWSER_UICHROME_HEIGHT_TALL = 50
|
12
|
-
CHROMEBROWSER_UI_MINIMUM_HEIGHT =
|
12
|
+
CHROMEBROWSER_UI_MINIMUM_HEIGHT = 289
|
13
13
|
FIREFOXBROWSER_UICHROME_HEIGHT = 74
|
14
|
+
FIREFOXBROWSER_MINIMUM_WIDTH = 450
|
14
15
|
SAFARIBROWSER_UICHROME_HEIGHT = 38
|
15
16
|
|
17
|
+
RSpec.shared_examples "browser driver" do
|
18
|
+
it "creates the browser driver" do
|
19
|
+
expect("#{driver.browser}").to match(/#{Regexp.quote(browser.to_s)}/i)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "matches the agent partial" do
|
23
|
+
expect(driver.execute_script(agent_script)).to include agent_match
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.shared_examples "random browser driver" do
|
28
|
+
it "creates the browser driver" do
|
29
|
+
expect("#{driver.browser}").to match(/#{Regexp.quote(browser.to_s)}/i)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "matches the agent partial" do
|
33
|
+
expect(driver.execute_script(agent_script)).not_to be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
RSpec.shared_examples "firefox size" do
|
38
|
+
it "matches the expected width" do
|
39
|
+
width_expectation = device.dig(orientation, :width)
|
40
|
+
width_expectation = FIREFOXBROWSER_MINIMUM_WIDTH if width_expectation < FIREFOXBROWSER_MINIMUM_WIDTH
|
41
|
+
expect(driver.execute_script(width_script)).to eq(width_expectation)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "matches the expected height" do
|
45
|
+
height_expectation = device.dig(orientation, :height) - FIREFOXBROWSER_UICHROME_HEIGHT
|
46
|
+
expect(driver.execute_script(height_script)).to eq(height_expectation)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
RSpec.shared_examples "safari size" do
|
51
|
+
it "matches the expected width" do
|
52
|
+
width_expectation = device.dig(orientation, :width)
|
53
|
+
expect(driver.execute_script(width_script)).to eq(width_expectation)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "matches the expected height" do
|
57
|
+
height_expectation = device.dig(orientation, :height) - SAFARIBROWSER_UICHROME_HEIGHT
|
58
|
+
expect(driver.execute_script(height_script)).to eq(height_expectation)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
RSpec.shared_examples "chrome size" do
|
63
|
+
it "matches the expected width" do
|
64
|
+
width_expectation = device.dig(orientation, :width)
|
65
|
+
expect(driver.execute_script(width_script)).to eq(width_expectation)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "matches the expected height" do
|
69
|
+
height_expectation = device.dig(orientation, :height) - CHROMEBROWSER_UICHROME_HEIGHT
|
70
|
+
expect(driver.execute_script(height_script)).to eq(height_expectation)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
16
74
|
describe "webdriver user agent" do
|
75
|
+
let(:devices) { Webdriver::UserAgent.devices }
|
76
|
+
let(:agent_script) { 'return navigator.userAgent' }
|
77
|
+
let(:width_script) { 'return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)' }
|
78
|
+
let(:height_script) { 'return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)' }
|
79
|
+
|
17
80
|
after :each do
|
18
|
-
|
19
|
-
|
81
|
+
driver.quit if defined?(driver)
|
82
|
+
browser.close if defined?(browser) && browser&.is_a?(Watir::Browser)
|
83
|
+
sleep(0.5) # Safari needs time to shutdown
|
20
84
|
end
|
21
85
|
|
22
86
|
# window.innerWidth and window.innerHeight
|
@@ -24,37 +88,94 @@ describe "webdriver user agent" do
|
|
24
88
|
# browser widths and heights
|
25
89
|
# http://stackoverflow.com/a/8876069/1651458
|
26
90
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
91
|
+
context "no browser, agent or orientation set" do
|
92
|
+
let(:device) { devices[:iphone] }
|
93
|
+
let(:driver) { Webdriver::UserAgent.driver }
|
94
|
+
let(:browser) { "firefox" }
|
95
|
+
let(:orientation) { :portrait }
|
96
|
+
let(:agent_match) { 'iPhone' }
|
97
|
+
|
98
|
+
it_behaves_like "browser driver"
|
99
|
+
it_behaves_like "firefox size"
|
33
100
|
end
|
34
101
|
|
35
|
-
|
36
|
-
|
37
|
-
|
102
|
+
context "Safari browser, iPhone 11 Pro Max agent, landscape orientation" do
|
103
|
+
let(:device) { devices[:iphone11promax] }
|
104
|
+
let(:orientation) { :landscape }
|
105
|
+
let(:driver) do
|
106
|
+
# Safari is a mess. safari_technology_preview added because
|
107
|
+
# Safari just isn't working in my environment as of 13.1 - Sam
|
108
|
+
|
109
|
+
Webdriver::UserAgent.driver(
|
110
|
+
browser: :safari,
|
111
|
+
agent: :iphone11promax,
|
112
|
+
orientation: orientation,
|
113
|
+
safari_technology_preview: true
|
114
|
+
)
|
115
|
+
end
|
116
|
+
let(:browser) { "safari" }
|
117
|
+
let(:orientation) { :landscape }
|
118
|
+
let(:agent_match) { 'iPhone' }
|
119
|
+
|
120
|
+
it_behaves_like "browser driver"
|
121
|
+
it_behaves_like "safari size"
|
122
|
+
end
|
38
123
|
|
39
|
-
|
40
|
-
|
41
|
-
|
124
|
+
context "Safari browser, iPhone 6 Plus agent, landscape orientation" do
|
125
|
+
let(:device) { devices[:iphone6plus] }
|
126
|
+
let(:orientation) { :landscape }
|
127
|
+
let(:driver) do
|
128
|
+
# Safari is a mess. safari_technology_preview added because
|
129
|
+
# Safari just isn't working in my environment as of 13.1 - Sam
|
130
|
+
|
131
|
+
Webdriver::UserAgent.driver(
|
132
|
+
browser: :safari,
|
133
|
+
agent: :iphone6plus,
|
134
|
+
orientation: orientation,
|
135
|
+
safari_technology_preview: true
|
136
|
+
)
|
137
|
+
end
|
138
|
+
let(:browser) { "safari" }
|
139
|
+
let(:agent_match) { 'iPhone' }
|
140
|
+
|
141
|
+
it_behaves_like "browser driver"
|
142
|
+
it_behaves_like "safari size"
|
42
143
|
end
|
43
144
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
145
|
+
context "Chrome browser, iPhone XS agent, landscape orientation" do
|
146
|
+
let(:device_key) { :iphonexs }
|
147
|
+
let(:device) { devices[device_key] }
|
148
|
+
let(:orientation) { :landscape }
|
149
|
+
let(:driver) do
|
150
|
+
Webdriver::UserAgent.driver(
|
151
|
+
browser: :chrome,
|
152
|
+
agent: device_key,
|
153
|
+
orientation: orientation
|
154
|
+
)
|
155
|
+
end
|
156
|
+
let(:browser) { "chrome" }
|
157
|
+
let(:agent_match) { 'iPhone' }
|
158
|
+
|
159
|
+
it_behaves_like "browser driver"
|
160
|
+
it_behaves_like "chrome size"
|
50
161
|
end
|
51
162
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
163
|
+
context "Chrome browser, iPhone XS agent, landscape orientation" do
|
164
|
+
let(:device_key) { :ipad }
|
165
|
+
let(:device) { devices[device_key] }
|
166
|
+
let(:orientation) { :landscape }
|
167
|
+
let(:driver) do
|
168
|
+
Webdriver::UserAgent.driver(
|
169
|
+
browser: :chrome,
|
170
|
+
agent: device_key,
|
171
|
+
orientation: orientation
|
172
|
+
)
|
173
|
+
end
|
174
|
+
let(:browser) { "chrome" }
|
175
|
+
let(:agent_match) { 'Mac OS' }
|
176
|
+
|
177
|
+
it_behaves_like "browser driver"
|
178
|
+
it_behaves_like "chrome size"
|
58
179
|
end
|
59
180
|
|
60
181
|
it "can create a new webdriver driver using chrome and iPad Pro (portrait)" do
|
@@ -73,124 +194,195 @@ describe "webdriver user agent" do
|
|
73
194
|
|
74
195
|
@driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :ipad_pro, :orientation => :portrait)
|
75
196
|
expect(@driver.browser).to eq(:chrome)
|
76
|
-
expect(@driver.execute_script('return navigator.userAgent')).to include '
|
197
|
+
expect(@driver.execute_script('return navigator.userAgent')).to include 'Mac OS'
|
77
198
|
expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(1024)
|
78
199
|
|
79
200
|
# See above
|
80
201
|
if @you_have_a_tall_monitor
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
it "can create a new webdriver driver using firefox and android phone (landscape)" do
|
86
|
-
@driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :android_phone, :orientation => :landscape)
|
87
|
-
expect(@driver.browser).to eq(:chrome)
|
88
|
-
expect(@driver.execute_script('return navigator.userAgent')).to include 'Android'
|
89
|
-
expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(480)
|
90
|
-
|
91
|
-
# Chrome is apparently setting some kind of minimum height
|
92
|
-
# As seen on Chrome v42 on OS X Yosimite
|
93
|
-
expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(CHROMEBROWSER_UI_MINIMUM_HEIGHT)
|
94
|
-
|
202
|
+
expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(1302 - CHROMEBROWSER_UICHROME_HEIGHT)
|
203
|
+
end
|
95
204
|
end
|
96
205
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
206
|
+
context "Chrome browser, Android tablet agent, landscape orientation" do
|
207
|
+
let(:device_key) { :android_tablet }
|
208
|
+
let(:device) { devices[device_key] }
|
209
|
+
let(:orientation) { :landscape }
|
210
|
+
let(:driver) do
|
211
|
+
Webdriver::UserAgent.driver(
|
212
|
+
browser: :chrome,
|
213
|
+
agent: device_key,
|
214
|
+
orientation: orientation
|
215
|
+
)
|
216
|
+
end
|
217
|
+
let(:browser) { "chrome" }
|
218
|
+
let(:agent_match) { 'Android' }
|
219
|
+
|
220
|
+
it_behaves_like "browser driver"
|
221
|
+
it_behaves_like "chrome size"
|
103
222
|
end
|
104
223
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
224
|
+
context "Firefox browser, desktop agent, landscape orientation" do
|
225
|
+
let(:device_key) { :desktop }
|
226
|
+
let(:device) { devices[device_key] }
|
227
|
+
let(:orientation) { :landscape }
|
228
|
+
let(:driver) do
|
229
|
+
Webdriver::UserAgent.driver(
|
230
|
+
browser: :firefox,
|
231
|
+
agent: device_key,
|
232
|
+
orientation: orientation
|
233
|
+
)
|
234
|
+
end
|
235
|
+
let(:browser) { "firefox" }
|
236
|
+
let(:agent_match) { 'Mac OS' }
|
237
|
+
|
238
|
+
it_behaves_like "browser driver"
|
239
|
+
it_behaves_like "firefox size"
|
111
240
|
end
|
112
241
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).not_to eq(356 - FIREFOXBROWSER_UICHROME_HEIGHT)
|
119
|
-
end
|
242
|
+
context "random agent" do
|
243
|
+
context "no specified browser" do
|
244
|
+
let(:device_key) { :random }
|
245
|
+
let(:driver) { Webdriver::UserAgent.driver(agent: device_key) }
|
246
|
+
let(:browser) { :firefox }
|
120
247
|
|
121
|
-
|
122
|
-
|
123
|
-
expect(@driver.browser).to eq(:chrome)
|
124
|
-
expect(@driver.execute_script('return navigator.userAgent')).not_to be_nil
|
125
|
-
expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).not_to eq(320)
|
126
|
-
expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).not_to eq(356 - CHROMEBROWSER_UICHROME_HEIGHT)
|
127
|
-
end
|
248
|
+
it_behaves_like "random browser driver"
|
249
|
+
end
|
128
250
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
251
|
+
context "chrome browser" do
|
252
|
+
let(:device_key) { :random }
|
253
|
+
let(:browser) { :chrome }
|
254
|
+
let(:driver) do
|
255
|
+
Webdriver::UserAgent.driver(browser: browser, agent: device_key)
|
256
|
+
end
|
135
257
|
|
136
|
-
|
137
|
-
|
138
|
-
expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(375)
|
139
|
-
expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(635 - FIREFOXBROWSER_UICHROME_HEIGHT)
|
258
|
+
it_behaves_like "random browser driver"
|
259
|
+
end
|
140
260
|
end
|
141
261
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
262
|
+
context "existing firefox profile" do
|
263
|
+
let(:device) { devices[:iphone] }
|
264
|
+
let(:profile) do
|
265
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
266
|
+
profile["intl.accept_languages"] = "es-MX"
|
267
|
+
profile
|
268
|
+
end
|
269
|
+
let(:options) { Selenium::WebDriver::Firefox::Options.new(profile: profile) }
|
270
|
+
let(:browser) { :firefox }
|
271
|
+
let(:agent_match) { 'iPhone' }
|
272
|
+
let(:orientation) { :portrait }
|
273
|
+
let(:driver) { Webdriver::UserAgent.driver(browser: browser, options: options) }
|
274
|
+
|
275
|
+
it_behaves_like "browser driver"
|
276
|
+
it_behaves_like "firefox size"
|
277
|
+
|
278
|
+
it "absorbs the options' profile" do
|
279
|
+
expect(driver.execute_script("return (navigator.language || navigator.userLanguage)")).to include("es-MX")
|
280
|
+
end
|
148
281
|
end
|
149
282
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
283
|
+
context "user-provided user agent string for firefox" do
|
284
|
+
let(:browser) { :firefox }
|
285
|
+
let(:user_agent) { "Mozilla/4.0 (compatible; MSIE 5.5b1; Mac_PowerPC)" }
|
286
|
+
let(:driver) { Webdriver::UserAgent.driver(user_agent_string: user_agent) }
|
154
287
|
|
155
|
-
|
156
|
-
|
288
|
+
it "can create a new webdriver driver" do
|
289
|
+
expect("#{driver.browser}").to match(/#{Regexp.quote(browser.to_s)}/i)
|
157
290
|
|
158
|
-
|
159
|
-
|
160
|
-
expect(@driver.browser).to eq(:chrome)
|
161
|
-
expect(@driver.execute_script('return navigator.language')).to include 'es-ES'
|
162
|
-
|
163
|
-
@browser = Watir::Browser.new @driver
|
291
|
+
expect(driver.execute_script("return navigator.userAgent")).to include("Mac_PowerPC")
|
292
|
+
end
|
164
293
|
end
|
165
294
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
295
|
+
context "user-provided accept language string for firefox" do
|
296
|
+
let(:browser) { :firefox }
|
297
|
+
let(:language) { "es-ES, es-MX;q=0.9, es;q=0.5, *;0.4" }
|
298
|
+
let(:driver) { Webdriver::UserAgent.driver(accept_language_string: language) }
|
170
299
|
|
171
|
-
|
172
|
-
|
300
|
+
it "can create a new webdriver driver" do
|
301
|
+
expect("#{driver.browser}").to match(/#{Regexp.quote(browser.to_s)}/i)
|
173
302
|
|
174
|
-
|
175
|
-
|
176
|
-
|
303
|
+
expect(driver.execute_script("return (navigator.language || navigator.userLanguage)")).to include("es-ES")
|
304
|
+
end
|
305
|
+
end
|
177
306
|
|
178
|
-
|
179
|
-
|
180
|
-
|
307
|
+
context "user-provided accept language string for safari" do
|
308
|
+
let(:browser) { :safari }
|
309
|
+
let(:language) { "es-ES, es-MX;q=0.9, es;q=0.5, *;0.4" }
|
310
|
+
let(:driver) {
|
311
|
+
Webdriver::UserAgent.driver(
|
312
|
+
browser: browser,
|
313
|
+
accept_language_string: language,
|
314
|
+
safari_technology_preview: true
|
315
|
+
)
|
316
|
+
}
|
317
|
+
|
318
|
+
it "can create a new webdriver driver" do
|
319
|
+
expect("#{driver.browser}").to match(/#{Regexp.quote(browser.to_s)}/i)
|
320
|
+
|
321
|
+
expect(driver.execute_script("return (navigator.language || navigator.userLanguage)")).to include("es-es")
|
322
|
+
end
|
181
323
|
end
|
182
324
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
325
|
+
context "user-provided viewport size and agent for firefox" do
|
326
|
+
let(:browser) { :firefox }
|
327
|
+
let(:device_key) { :iphone11 }
|
328
|
+
let(:device) { devices[device_key] }
|
329
|
+
let(:width) { 800 }
|
330
|
+
let(:height) { 600 }
|
331
|
+
let(:agent_match) { 'iPhone' }
|
332
|
+
let(:orientation) { :portrait }
|
333
|
+
let(:driver) {
|
334
|
+
Webdriver::UserAgent.driver(
|
335
|
+
viewport_width: "#{width}",
|
336
|
+
viewport_height: height,
|
337
|
+
agent: device_key
|
338
|
+
)
|
339
|
+
}
|
340
|
+
|
341
|
+
it_behaves_like "browser driver"
|
342
|
+
it "uses user-provided dimensions" do
|
343
|
+
expect(driver.execute_script(width_script)).to eq(width)
|
344
|
+
expect(driver.execute_script(height_script)).to eq(height - FIREFOXBROWSER_UICHROME_HEIGHT)
|
345
|
+
end
|
346
|
+
end
|
188
347
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
348
|
+
context "user-provided nonsense viewport size for firefox" do
|
349
|
+
let(:browser) { :firefox }
|
350
|
+
let(:device_key) { :iphone8 }
|
351
|
+
let(:device) { devices[device_key] }
|
352
|
+
let(:width) { "xyz" }
|
353
|
+
let(:agent_match) { 'iPhone' }
|
354
|
+
let(:orientation) { :portrait }
|
355
|
+
let(:driver) {
|
356
|
+
Webdriver::UserAgent.driver(
|
357
|
+
viewport_width: "#{width}",
|
358
|
+
agent: device_key
|
359
|
+
)
|
360
|
+
}
|
361
|
+
|
362
|
+
it_behaves_like "browser driver"
|
363
|
+
it_behaves_like "firefox size"
|
194
364
|
end
|
195
365
|
|
366
|
+
context "portrait firefox iphone" do
|
367
|
+
let(:browser) { :firefox }
|
368
|
+
let(:device_key) { :iphone }
|
369
|
+
let(:device) { devices[device_key] }
|
370
|
+
let(:width) { "xyz" }
|
371
|
+
let(:agent_match) { 'iPhone' }
|
372
|
+
let(:orientation) { :portrait }
|
373
|
+
let(:driver) {
|
374
|
+
Webdriver::UserAgent.driver(
|
375
|
+
agent: device_key,
|
376
|
+
browser: browser,
|
377
|
+
orientation: orientation
|
378
|
+
)
|
379
|
+
}
|
380
|
+
|
381
|
+
it "can create a browser using the driver" do
|
382
|
+
browser = Watir::Browser.new(driver)
|
383
|
+
|
384
|
+
expect(browser).to be_a(Watir::Browser)
|
385
|
+
expect(browser.url).to be_a(String)
|
386
|
+
end
|
387
|
+
end
|
196
388
|
end
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
13
|
gem.name = "webdriver-user-agent"
|
14
14
|
gem.require_paths = ["lib"]
|
15
|
-
gem.version = "7.
|
15
|
+
gem.version = "7.8"
|
16
16
|
gem.requirements << 'chromedriver, v2.20'
|
17
17
|
# chromedriver v2.19 causes
|
18
18
|
# Selenium::WebDriver::Error::NoSuchDriverError: no such session errors
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webdriver-user-agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '7.
|
4
|
+
version: '7.8'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alister Scott
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2020-07-10 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: selenium-webdriver
|
@@ -174,8 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
174
|
version: '0'
|
175
175
|
requirements:
|
176
176
|
- chromedriver, v2.20
|
177
|
-
|
178
|
-
rubygems_version: 2.7.7
|
177
|
+
rubygems_version: 3.1.2
|
179
178
|
signing_key:
|
180
179
|
specification_version: 4
|
181
180
|
summary: A helper gem to emulate populate device user agents and resolutions when
|