webdriver-user-agent 7.5 → 7.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9589c34ef3fbb25e386f2c5b654f21564afe66a47c89dec46f78dff7cadb70e2
|
4
|
+
data.tar.gz: 44f41c6fabde58f65d1598813fe63ed659b5b430972b23fd9f08349251780f0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c07dacc751fdb9793a8d932d3fa11e468d2c10b940f52d0b3c9569fc3dec97b827012ae515ffc7c0c90b3b5d45ec76630cdd7464c14c3e7e8fde3d7fe921c1be
|
7
|
+
data.tar.gz: 8045ac3e0b908bb49609aa31ae7d00c7c98c5d8f8c59edfb8cfa92a1171df4906749255726c36446ab3e2e3f3e01013c10d1e9624968baab503ea917c610ef11
|
@@ -4,6 +4,9 @@ module Webdriver
|
|
4
4
|
module UserAgent
|
5
5
|
|
6
6
|
MINIMUM_MACOS_VERSION_NUMBER = 12
|
7
|
+
DEFAULT_BROWSER = :firefox
|
8
|
+
DEFAULT_AGENT = :iphone
|
9
|
+
DEFAULT_ORIENTATION = :portrait
|
7
10
|
|
8
11
|
class BrowserOptions
|
9
12
|
|
@@ -16,7 +19,7 @@ module Webdriver
|
|
16
19
|
|
17
20
|
options[:viewport_width], options[:viewport_height] = parse_viewport_sizes(options[:viewport_width], options[:viewport_height])
|
18
21
|
|
19
|
-
initialize_for_browser(user_agent_string)
|
22
|
+
initialize_for_browser(user_agent_string, opts[:accept_language_string])
|
20
23
|
end
|
21
24
|
|
22
25
|
def method_missing(*args, &block)
|
@@ -27,7 +30,7 @@ module Webdriver
|
|
27
30
|
end
|
28
31
|
|
29
32
|
def browser_options
|
30
|
-
options.except(:browser, :agent, :orientation, :user_agent_string, :viewport_width, :viewport_height)
|
33
|
+
options.except(:browser, :agent, :orientation, :user_agent_string, :accept_language_string, :viewport_width, :viewport_height, :safari_technology_preview)
|
31
34
|
end
|
32
35
|
|
33
36
|
private
|
@@ -41,19 +44,22 @@ module Webdriver
|
|
41
44
|
@stp = false unless @stp.is_a?(TrueClass)
|
42
45
|
end
|
43
46
|
|
44
|
-
def initialize_for_browser(user_agent_string)
|
47
|
+
def initialize_for_browser(user_agent_string, accept_language_string)
|
45
48
|
case options[:browser]
|
46
49
|
when :firefox
|
47
50
|
profile ||= Selenium::WebDriver::Firefox::Profile.new
|
48
51
|
profile['general.useragent.override'] = user_agent_string
|
52
|
+
profile['intl.accept_languages'] = accept_language_string if accept_language_string
|
49
53
|
|
50
54
|
options[:options] ||= Selenium::WebDriver::Firefox::Options.new
|
51
55
|
options[:options].profile = profile
|
52
56
|
when :chrome
|
53
57
|
options[:options] ||= Selenium::WebDriver::Chrome::Options.new
|
54
58
|
options[:options].add_argument "--user-agent=#{user_agent_string}"
|
59
|
+
options[:options].add_preference("intl.accept_languages", accept_language_string) if accept_language_string
|
55
60
|
when :safari
|
56
61
|
change_safari_user_agent_string(user_agent_string)
|
62
|
+
change_safari_language(accept_language_string) if accept_language_string
|
57
63
|
options
|
58
64
|
else
|
59
65
|
raise "WebDriver UserAgent currently only supports :chrome, :firefox and :safari."
|
@@ -67,23 +73,48 @@ module Webdriver
|
|
67
73
|
end
|
68
74
|
|
69
75
|
def change_safari_user_agent_string(user_agent_string)
|
76
|
+
ua = "\"\\\"#{user_agent_string}\\\"\"" # escape for shell quoting
|
77
|
+
|
78
|
+
safari_command_runner(ua, "CustomUserAgent")
|
79
|
+
end
|
80
|
+
|
81
|
+
def change_safari_language(accept_language_string)
|
82
|
+
parsed_safari_string = prepare_safari_string(accept_language_string)
|
83
|
+
|
84
|
+
safari_command_runner(parsed_safari_string, "AppleLanguages")
|
85
|
+
end
|
86
|
+
|
87
|
+
def safari_command_runner(setting, pref)
|
70
88
|
raise "Safari requires a Mac" unless OS.mac?
|
71
89
|
|
72
|
-
|
90
|
+
cmd = "defaults write com.apple.#{safari_version} #{pref} #{setting}"
|
91
|
+
|
92
|
+
output = `#{cmd}`
|
93
|
+
|
94
|
+
raise prepare_safari_error_message(cmd, output) unless $?.success?
|
95
|
+
end
|
96
|
+
|
97
|
+
def safari_version
|
73
98
|
if @stp
|
74
99
|
Selenium::WebDriver::Safari.technology_preview!
|
75
|
-
|
76
|
-
else
|
77
|
-
cmd = "defaults write com.apple.Safari CustomUserAgent \"#{ua}\""
|
100
|
+
return "SafariTechnologyPreview"
|
78
101
|
end
|
79
102
|
|
80
|
-
|
103
|
+
"Safari"
|
104
|
+
end
|
81
105
|
|
106
|
+
def prepare_safari_error_message(cmd, output)
|
82
107
|
error_message = "Unable to execute '#{cmd}'. "
|
83
108
|
error_message += "Error message reported: '#{output}'"
|
84
109
|
error_message += "Please execute the command manually and correct any errors."
|
85
110
|
|
86
|
-
|
111
|
+
error_message
|
112
|
+
end
|
113
|
+
|
114
|
+
def prepare_safari_string(accept_language_string)
|
115
|
+
["'(", accept_language_string.split(",").map{|l|
|
116
|
+
"\"#{l.gsub(/\s+/,'')}\""
|
117
|
+
}.join(", "), ")'"].join('')
|
87
118
|
end
|
88
119
|
|
89
120
|
# Require a Mac at version 12 (Sierra) or greater
|
@@ -3,14 +3,14 @@ require 'yaml'
|
|
3
3
|
module Webdriver
|
4
4
|
module UserAgent
|
5
5
|
module Devices
|
6
|
-
|
6
|
+
|
7
7
|
def devices
|
8
8
|
YAML.load_file devices_file
|
9
9
|
end
|
10
10
|
|
11
11
|
def resolution_for(device_name, orientation, user_width, user_height)
|
12
12
|
return [user_width.to_i, user_height.to_i] if ((user_width.to_i + user_height.to_i) > 1)
|
13
|
-
|
13
|
+
|
14
14
|
device = devices[device_name.downcase][orientation.downcase]
|
15
15
|
[device[:width],device[:height]]
|
16
16
|
end
|
@@ -23,7 +23,7 @@ module Webdriver
|
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
26
|
-
|
26
|
+
|
27
27
|
def random_user_agent
|
28
28
|
File.foreach(user_agents_file).each_with_index.reduce(nil) do |picked,pair|
|
29
29
|
rand < 1.0/(1+pair[1]) ? pair[0] : picked
|
@@ -20,8 +20,10 @@ module Webdriver
|
|
20
20
|
case
|
21
21
|
when opts[:safari_technology_preview].is_a?(TrueClass)
|
22
22
|
`defaults delete com.apple.SafariTechnologyPreview CustomUserAgent`
|
23
|
+
`defaults delete com.apple.SafariTechnologyPreview AppleLanguages`
|
23
24
|
else
|
24
25
|
`defaults delete com.apple.Safari CustomUserAgent`
|
26
|
+
`defaults delete com.apple.Safari AppleLanguages`
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
@@ -5,10 +5,11 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
5
5
|
require 'webdriver-user-agent'
|
6
6
|
require 'selenium-webdriver'
|
7
7
|
require 'watir'
|
8
|
+
require 'webdrivers'
|
8
9
|
|
9
|
-
CHROMEBROWSER_UICHROME_HEIGHT =
|
10
|
-
CHROMEBROWSER_UICHROME_HEIGHT_TALL =
|
11
|
-
CHROMEBROWSER_UI_MINIMUM_HEIGHT =
|
10
|
+
CHROMEBROWSER_UICHROME_HEIGHT = 123
|
11
|
+
CHROMEBROWSER_UICHROME_HEIGHT_TALL = 50
|
12
|
+
CHROMEBROWSER_UI_MINIMUM_HEIGHT = 149
|
12
13
|
FIREFOXBROWSER_UICHROME_HEIGHT = 74
|
13
14
|
SAFARIBROWSER_UICHROME_HEIGHT = 38
|
14
15
|
|
@@ -33,7 +34,7 @@ describe "webdriver user agent" do
|
|
33
34
|
|
34
35
|
it "can create a new webdriver driver using safari and iphone 6 plus, and landscape" do
|
35
36
|
@driver = Webdriver::UserAgent.driver(:browser => :safari, :agent => :iphone6plus, :orientation => :landscape)
|
36
|
-
expect(@driver.browser).to
|
37
|
+
expect("#{@driver.browser}").to match(/safari/i)
|
37
38
|
|
38
39
|
expect(@driver.execute_script('return navigator.userAgent')).to include 'iPhone'
|
39
40
|
expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(736)
|
@@ -139,12 +140,36 @@ describe "webdriver user agent" do
|
|
139
140
|
end
|
140
141
|
|
141
142
|
it "can create a new webdriver driver using firefox and user-specified user agent" do
|
142
|
-
|
143
|
-
|
144
|
-
|
143
|
+
@driver = Webdriver::UserAgent.driver(:user_agent_string => "Mozilla/4.0 (compatible; MSIE 5.5b1; Mac_PowerPC)")
|
144
|
+
expect(@driver.browser).to eq(:firefox)
|
145
|
+
expect(@driver.execute_script('return navigator.userAgent')).to include 'Mac_PowerPC'
|
145
146
|
|
146
|
-
|
147
|
-
|
147
|
+
@browser = Watir::Browser.new @driver
|
148
|
+
end
|
149
|
+
|
150
|
+
it "can create a new webdriver driver using firefox and user-specified language" do
|
151
|
+
@driver = Webdriver::UserAgent.driver(accept_language_string: "es-ES, es-MX;q=0.9, es;q=0.5, *;0.4")
|
152
|
+
expect(@driver.browser).to eq(:firefox)
|
153
|
+
expect(@driver.execute_script('return navigator.language')).to include 'es-ES'
|
154
|
+
|
155
|
+
@browser = Watir::Browser.new @driver
|
156
|
+
end
|
157
|
+
|
158
|
+
it "can create a new webdriver driver using firefox and user-specified language" do
|
159
|
+
@driver = Webdriver::UserAgent.driver(browser: :chrome, accept_language_string: "es-ES, es-MX;q=0.9, es;q=0.5, *;0.4")
|
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
|
164
|
+
end
|
165
|
+
|
166
|
+
it "can create a new webdriver driver using firefox and user-specified language" do
|
167
|
+
@driver = Webdriver::UserAgent.driver(browser: :safari, accept_language_string: "es-ES, es-MX;q=0.9, es;q=0.5, *;0.4", safari_technology_preview: true)
|
168
|
+
expect(@driver.browser).to match(/safari/i)
|
169
|
+
expect(@driver.execute_script('return navigator.language')).to include 'es-ES'
|
170
|
+
|
171
|
+
@browser = Watir::Browser.new @driver
|
172
|
+
end
|
148
173
|
|
149
174
|
it "can create a new webdriver driver using firefox and user-specified viewport sizes (string or int)" do
|
150
175
|
width = 800
|
@@ -153,7 +178,7 @@ describe "webdriver user agent" do
|
|
153
178
|
@driver = Webdriver::UserAgent.driver(:viewport_width => "#{width}", :viewport_height => height, :agent => :iphone6)
|
154
179
|
expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(800)
|
155
180
|
expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(600 - FIREFOXBROWSER_UICHROME_HEIGHT)
|
156
|
-
|
181
|
+
end
|
157
182
|
|
158
183
|
it "can create a new webdriver driver, handling for nonsense height and widths" do
|
159
184
|
@driver = Webdriver::UserAgent.driver(:viewport_width => "abc", :agent => :iphone8)
|
@@ -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.6"
|
16
16
|
gem.requirements << 'chromedriver, v2.20'
|
17
17
|
# chromedriver v2.19 causes
|
18
18
|
# Selenium::WebDriver::Error::NoSuchDriverError: no such session errors
|
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.add_dependency 'psych'
|
24
24
|
gem.add_development_dependency 'rspec'
|
25
25
|
gem.add_development_dependency 'watir'
|
26
|
+
gem.add_development_dependency 'webdrivers'
|
26
27
|
end
|
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.6'
|
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: 2019-02-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: selenium-webdriver
|
@@ -111,6 +111,20 @@ dependencies:
|
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: webdrivers
|
116
|
+
requirement: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
114
128
|
description: A helper gem to emulate populate device user agents and resolutions when
|
115
129
|
using webdriver
|
116
130
|
email:
|