webdriver-user-agent 7.2 → 7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef6b7eca083c27f5dc45d9e81854697a175c706a
4
+ data.tar.gz: 5f29a865c65c990681a69e5902dcdbfa99bf42e9
5
+ SHA512:
6
+ metadata.gz: 88a77a7c2c8c2f5c67d3d9ba1418c0b6a8d65568e77482f59841f57d574392c47d70ee38224b40f04749c916834e1a0c16ed629ac9d6b840b54c1867d5aff527
7
+ data.tar.gz: 2f0e6a6de214e03ad8e6866e88ae40c4136adf9302e3d574e054e52afd432fb280f5cb02a544fed2989b6f443e3497057777173b07a27b55d00a89552955b879
@@ -1 +1 @@
1
- ruby-1.9.3-p429
1
+ ruby-2.2.1
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ === Version 7.3 / 2015-7-14 (Thanks samnissen)
2
+ * Enhancements
3
+ * Allow users to override the browser screensize
4
+ * Fixes
5
+ * Removed development puts commands
6
+ * Chrome no longer rejects using Javascript to rewize the window
7
+
1
8
  === Version 7.2 / 2014-12-12
2
9
  * Enhancements
3
10
  * Added iphone 5 and 6 variants (Thanks samnissen)
@@ -9,6 +9,9 @@ module Webdriver
9
9
  options[:browser] ||= :firefox
10
10
  options[:agent] ||= :iphone
11
11
  options[:orientation] ||= :portrait
12
+
13
+ options[:viewport_width], options[:viewport_height] = parse_viewport_sizes(options[:viewport_width], options[:viewport_height])
14
+
12
15
  initialize_for_browser(user_agent_string)
13
16
  end
14
17
 
@@ -20,7 +23,7 @@ module Webdriver
20
23
  end
21
24
 
22
25
  def browser_options
23
- options.except(:browser, :agent, :orientation, :user_agent_string)
26
+ options.except(:browser, :agent, :orientation, :user_agent_string, :viewport_width, :viewport_height)
24
27
  end
25
28
 
26
29
  private
@@ -42,6 +45,12 @@ module Webdriver
42
45
  end
43
46
 
44
47
  end
48
+
49
+ def parse_viewport_sizes(width, height)
50
+ return ["0","0"] unless "#{width}".to_i > 0 && "#{height}".to_i > 0
51
+
52
+ ["#{width}", "#{height}"]
53
+ end
45
54
  end
46
55
  end
47
56
  end
@@ -8,7 +8,9 @@ module Webdriver
8
8
  YAML.load_file devices_file
9
9
  end
10
10
 
11
- def resolution_for(device_name, orientation)
11
+ def resolution_for(device_name, orientation, user_width, user_height)
12
+ return [user_width.to_i, user_height.to_i] if ((user_width.to_i + user_height.to_i) > 1)
13
+
12
14
  device = devices[device_name.downcase][orientation.downcase]
13
15
  [device[:width],device[:height]]
14
16
  end
@@ -24,13 +24,14 @@ module Webdriver
24
24
  driver.close
25
25
  driver.switch_to.window driver.window_handles.first
26
26
  end
27
- driver.execute_script("window.innerWidth = #{width}; window.innerHeight = #{height};")
27
+ target_size = Selenium::WebDriver::Dimension.new(width.to_i, height.to_i)
28
+ driver.manage.window.size = target_size
28
29
  end
29
30
 
30
31
  def build_driver_using(options)
31
32
  driver = Selenium::WebDriver.for options.browser, options.browser_options
32
33
  unless options.agent == :random
33
- resize_inner_window(driver, *resolution_for(options.agent, options.orientation))
34
+ resize_inner_window(driver, *resolution_for(options.agent, options.orientation, options.viewport_width, options.viewport_height))
34
35
  end
35
36
  driver
36
37
  end
@@ -6,65 +6,78 @@ require 'webdriver-user-agent'
6
6
  require 'selenium-webdriver'
7
7
  require 'watir-webdriver'
8
8
 
9
+ CHROMEBROWSER_UICHROME_HEIGHT = 72
10
+ CHROMEBROWSER_UI_MINIMUM_HEIGHT = 200
11
+ FIREFOXBROWSER_UICHROME_HEIGHT = 79
12
+
9
13
  describe "webdriver user agent" do
10
14
  after :each do
11
15
  @driver.quit if @driver
12
16
  end
17
+
18
+ # window.innerWidth and window.innerHeight
19
+ # do not accurately provide
20
+ # browser widths and heights
21
+ # http://stackoverflow.com/a/8876069/1651458
13
22
 
14
23
  it "can create a new webdriver driver using firefox and iphone (portrait) by default" do
15
24
  @driver = Webdriver::UserAgent.driver
16
25
  expect(@driver.browser).to eq(:firefox)
17
26
  expect(@driver.execute_script('return navigator.userAgent')).to include 'iPhone'
18
- expect(@driver.execute_script('return window.innerWidth')).to eq(375)
19
- expect(@driver.execute_script('return window.innerHeight')).to eq(559)
27
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(375)
28
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(559 - FIREFOXBROWSER_UICHROME_HEIGHT)
20
29
  end
21
30
 
22
31
  it "can create a new webdriver driver using chrome and iphone 6 plus (landscape)" do
23
32
  @driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :iphone6plus, :orientation => :landscape)
24
33
  expect(@driver.browser).to eq(:chrome)
25
34
  expect(@driver.execute_script('return navigator.userAgent')).to include 'iPhone'
26
- expect(@driver.execute_script('return window.innerWidth')).to eq(736)
27
- expect(@driver.execute_script('return window.innerHeight')).to eq(414)
35
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(736)
36
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(414 - CHROMEBROWSER_UICHROME_HEIGHT)
28
37
  end
29
38
 
30
39
  it "can create a new webdriver driver using chrome and iPad (landscape)" do
31
40
  @driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :iPad, :orientation => :landscape)
32
41
  expect(@driver.browser).to eq(:chrome)
33
42
  expect(@driver.execute_script('return navigator.userAgent')).to include 'iPad'
34
- expect(@driver.execute_script('return window.innerWidth')).to eq(1024)
35
- expect(@driver.execute_script('return window.innerHeight')).to eq(704)
43
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(1024)
44
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(704 - CHROMEBROWSER_UICHROME_HEIGHT)
36
45
  end
37
46
 
38
47
  it "can create a new webdriver driver using firefox and android phone (landscape)" do
39
48
  @driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :android_phone, :orientation => :landscape)
40
49
  expect(@driver.browser).to eq(:chrome)
41
50
  expect(@driver.execute_script('return navigator.userAgent')).to include 'Android'
42
- expect(@driver.execute_script('return window.innerWidth')).to eq(480)
43
- expect(@driver.execute_script('return window.innerHeight')).to eq(196)
51
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(480)
52
+
53
+ # Chrome is apparently setting some kind of minimum height
54
+ # As seen on Chrome v42 on OS X Yosimite
55
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(CHROMEBROWSER_UI_MINIMUM_HEIGHT)
56
+
44
57
  end
45
58
 
46
- it "can create a new webdriver driver using firefox and android tablet (portrait)" do
59
+ it "can create a new webdriver driver using chrome and android tablet (portrait)" do
47
60
  @driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :android_tablet, :orientation => :portrait)
48
61
  expect(@driver.browser).to eq(:chrome)
49
62
  expect(@driver.execute_script('return navigator.userAgent')).to include 'Android'
50
- expect(@driver.execute_script('return window.innerWidth')).to eq(768)
51
- expect(@driver.execute_script('return window.innerHeight')).to eq(946)
63
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(768)
64
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(873 - CHROMEBROWSER_UICHROME_HEIGHT)
52
65
  end
53
66
 
54
67
  it "can create a new webdriver driver using firefox and random user agent" do
55
68
  @driver = Webdriver::UserAgent.driver(:agent => :random)
56
69
  expect(@driver.browser).to eq(:firefox)
57
70
  expect(@driver.execute_script('return navigator.userAgent')).not_to be_nil
58
- expect(@driver.execute_script('return window.innerWidth')).not_to eq(320)
59
- expect(@driver.execute_script('return window.innerHeight')).not_to eq(356)
71
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).not_to eq(320)
72
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).not_to eq(356 - FIREFOXBROWSER_UICHROME_HEIGHT)
60
73
  end
61
74
 
62
75
  it "can create a new webdriver driver using chrome and random user agent" do
63
76
  @driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :random)
64
77
  expect(@driver.browser).to eq(:chrome)
65
78
  expect(@driver.execute_script('return navigator.userAgent')).not_to be_nil
66
- expect(@driver.execute_script('return window.innerWidth')).not_to eq(320)
67
- expect(@driver.execute_script('return window.innerHeight')).not_to eq(356)
79
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).not_to eq(320)
80
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).not_to eq(356 - CHROMEBROWSER_UICHROME_HEIGHT)
68
81
  end
69
82
 
70
83
  it "can create a new webdriver driver using an existing firefox profile" do
@@ -73,19 +86,40 @@ describe "webdriver user agent" do
73
86
  @driver = Webdriver::UserAgent.driver(:browser => :firefox, :profile => profile)
74
87
  expect(@driver.browser).to eq(:firefox)
75
88
  expect(@driver.execute_script('return navigator.userAgent')).to include 'iPhone'
76
- expect(@driver.execute_script('return window.innerWidth')).to eq(375)
77
- expect(@driver.execute_script('return window.innerHeight')).to eq(559)
89
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(375)
90
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(559 - FIREFOXBROWSER_UICHROME_HEIGHT)
78
91
  expect(@driver.title).to eq('hello')
79
92
  end
80
93
 
81
94
  it "can create a new webdriver driver using firefox and user-specified user agent" do
82
95
  @driver = Webdriver::UserAgent.driver(:user_agent_string => "Mozilla/4.0 (compatible; MSIE 5.5b1; Mac_PowerPC)")
83
96
  expect(@driver.browser).to eq(:firefox)
84
- expect(@driver.execute_script('return navigator.userAgent')).not_to be_nil
97
+ expect(@driver.execute_script('return navigator.userAgent')).to include 'Mac_PowerPC'
85
98
 
86
99
  @browser = Watir::Browser.new @driver
87
100
  expect(@browser.url).to eq("about:blank")
88
101
  end
102
+
103
+ it "can create a new webdriver driver using firefox and user-specified viewport sizes (string or int)" do
104
+ width = 800
105
+ height = 600
106
+
107
+ @driver = Webdriver::UserAgent.driver(:viewport_width => "#{width}", :viewport_height => height, :agent => :iphone6)
108
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(800)
109
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(600 - FIREFOXBROWSER_UICHROME_HEIGHT)
110
+
111
+ @browser = Watir::Browser.new @driver
112
+ expect(@browser.url).to eq("about:blank")
113
+ end
114
+
115
+ it "can create a new webdriver driver, handling for nonsense height and widths" do
116
+ @driver = Webdriver::UserAgent.driver(:viewport_width => "abc", :agent => :iphone6)
117
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientWidth, window.innerWidth || 0)')).to eq(375)
118
+ expect(@driver.execute_script('return Math.max(document.documentElement.clientHeight, window.innerHeight || 0)')).to eq(559 - FIREFOXBROWSER_UICHROME_HEIGHT)
119
+
120
+ @browser = Watir::Browser.new @driver
121
+ expect(@browser.url).to eq("about:blank")
122
+ end
89
123
 
90
124
  it "can allow using selenium driver for watir browser" do
91
125
  @driver = Webdriver::UserAgent.driver(:browser => :firefox, :agent => :iphone, :orientation => :portrait)
@@ -93,7 +127,4 @@ describe "webdriver user agent" do
93
127
  expect(@browser.url).to eq("about:blank")
94
128
  end
95
129
 
96
-
97
-
98
-
99
- end
130
+ end
@@ -12,11 +12,11 @@ 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.2"
15
+ gem.version = "7.3"
16
16
  gem.add_dependency 'selenium-webdriver'
17
17
  gem.add_dependency 'facets'
18
18
  gem.add_dependency 'json'
19
+ gem.add_dependency 'psych'
19
20
  gem.add_development_dependency 'rspec'
20
21
  gem.add_development_dependency 'watir-webdriver'
21
-
22
22
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webdriver-user-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: '7.2'
5
- prerelease:
4
+ version: '7.3'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alister Scott
@@ -10,86 +9,90 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2014-12-12 00:00:00.000000000 Z
12
+ date: 2015-07-14 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: selenium-webdriver
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - ">="
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - ">="
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: facets
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - ">="
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - ">="
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: json
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - ">="
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: psych
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
61
68
  - !ruby/object:Gem::Version
62
69
  version: '0'
63
70
  - !ruby/object:Gem::Dependency
64
71
  name: rspec
65
72
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
73
  requirements:
68
- - - ! '>='
74
+ - - ">="
69
75
  - !ruby/object:Gem::Version
70
76
  version: '0'
71
77
  type: :development
72
78
  prerelease: false
73
79
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
80
  requirements:
76
- - - ! '>='
81
+ - - ">="
77
82
  - !ruby/object:Gem::Version
78
83
  version: '0'
79
84
  - !ruby/object:Gem::Dependency
80
85
  name: watir-webdriver
81
86
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
87
  requirements:
84
- - - ! '>='
88
+ - - ">="
85
89
  - !ruby/object:Gem::Version
86
90
  version: '0'
87
91
  type: :development
88
92
  prerelease: false
89
93
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
94
  requirements:
92
- - - ! '>='
95
+ - - ">="
93
96
  - !ruby/object:Gem::Version
94
97
  version: '0'
95
98
  description: A helper gem to emulate populate device user agents and resolutions when
@@ -101,10 +104,10 @@ executables: []
101
104
  extensions: []
102
105
  extra_rdoc_files: []
103
106
  files:
104
- - .gitignore
105
- - .rspec
106
- - .ruby-gemset
107
- - .ruby-version
107
+ - ".gitignore"
108
+ - ".rspec"
109
+ - ".ruby-gemset"
110
+ - ".ruby-version"
108
111
  - ChangeLog
109
112
  - Gemfile
110
113
  - HISTORY.md
@@ -122,27 +125,26 @@ files:
122
125
  - webdriver-user-agent.gemspec
123
126
  homepage: https://github.com/alisterscott/webdriver-user-agent
124
127
  licenses: []
128
+ metadata: {}
125
129
  post_install_message:
126
130
  rdoc_options: []
127
131
  require_paths:
128
132
  - lib
129
133
  required_ruby_version: !ruby/object:Gem::Requirement
130
- none: false
131
134
  requirements:
132
- - - ! '>='
135
+ - - ">="
133
136
  - !ruby/object:Gem::Version
134
137
  version: '0'
135
138
  required_rubygems_version: !ruby/object:Gem::Requirement
136
- none: false
137
139
  requirements:
138
- - - ! '>='
140
+ - - ">="
139
141
  - !ruby/object:Gem::Version
140
142
  version: '0'
141
143
  requirements: []
142
144
  rubyforge_project:
143
- rubygems_version: 1.8.25
145
+ rubygems_version: 2.4.6
144
146
  signing_key:
145
- specification_version: 3
147
+ specification_version: 4
146
148
  summary: A helper gem to emulate populate device user agents and resolutions when
147
149
  using webdriver
148
150
  test_files: