watir-scroll 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cceab63479c924c0d51f2db30eb14965d9f4bd60
4
+ data.tar.gz: 06e0b59749583cf76f3de1cfe2dc0e0591b993c4
5
+ SHA512:
6
+ metadata.gz: 464e8bd295266dea9a9f78a4895e3d158819e6577285c7c9c511efc44052f771a0c750b3f3ee348613d4ee8455782c6e86f3483639c17815d3dbc884097128fc
7
+ data.tar.gz: 550afb45f418fc3f966d41bbf0e3884324da96c5f01ee1a91d35a6e0926de69f1934219fe91c5f646cc7e298d87ddbc9227fa5ad6946e863762605683bb8c418
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
+ sudo: false
1
2
  rvm:
2
- - 1.9.3
3
- - 2.0.0
3
+ - 2.2
4
4
  before_install:
5
- - "export DISPLAY=:99.0"
6
- - "sh -e /etc/init.d/xvfb start"
5
+ - export DISPLAY=:99
6
+ - sh -e /etc/init.d/xvfb start
7
+ - spec/support/travis.sh
8
+ - export PATH="$(pwd)/bin:$PATH"
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Alex Rodionov
1
+ Copyright (c) 2016 Alex Rodionov
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # watir-scroll [![Build Status](https://travis-ci.org/p0deje/watir-scroll.png?branch=master)](https://travis-ci.org/p0deje/watir-scroll) [![Gem Version](https://badge.fury.io/rb/watir-scroll.png)](http://badge.fury.io/rb/watir-scroll)
1
+ # watir-scroll [![Build Status](https://travis-ci.org/p0deje/watir-scroll.svg?branch=master)](https://travis-ci.org/p0deje/watir-scroll) [![Gem Version](https://badge.fury.io/rb/watir-scroll.svg)](http://badge.fury.io/rb/watir-scroll)
2
2
 
3
3
  Scrolling API for [watir-webdriver](http://github.com/watir/watir-webdriver).
4
4
 
@@ -24,14 +24,24 @@ $ gem install watir-scroll
24
24
 
25
25
  ## Usage
26
26
 
27
- ```ruby
28
- button = browser.button(:text => 'Click')
27
+ ### Scrolling on Browser Window Level
29
28
 
29
+ ```ruby
30
30
  browser.scroll.to :top # scrolls to the top of the page
31
31
  browser.scroll.to :center # scrolls to the center of the page
32
32
  browser.scroll.to :bottom # scrolls to the bottom of the page
33
33
  browser.scroll.to [10, 10] # scrolls to coordinates x and y
34
- browser.scroll.to button # scrolls to element
34
+ ```
35
+
36
+ ### Scrolling To Elements
37
+
38
+
39
+ ```ruby
40
+ button = browser.button(text: 'Click')
41
+
42
+ button.scroll.to # scrolls element to the top
43
+ button.scroll.to :center # scrolls element to the center
44
+ button.scroll.to :bottom # scrolls element to the bottom
35
45
  ```
36
46
 
37
47
  ## Contributing
data/Rakefile CHANGED
@@ -7,4 +7,3 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
7
7
  end
8
8
 
9
9
  task default: :spec
10
-
data/lib/watir-scroll.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "watir-webdriver"
2
2
  require "watir-scroll/browser"
3
- require "watir-scroll/scroll"
3
+ require "watir-scroll/browser/scroll"
4
+ require "watir-scroll/element"
5
+ require "watir-scroll/element/scroll"
4
6
  require "watir-scroll/version"
@@ -8,18 +8,16 @@ module Watir
8
8
 
9
9
  #
10
10
  # Scrolls to position.
11
- # @param [Symbol, Watir::Element, Array<Fixnum>] param
11
+ # @param [Symbol, Array<Fixnum>] param
12
12
  #
13
13
  def to(param)
14
14
  args = case param
15
15
  when :top, :start
16
16
  'window.scrollTo(0, 0);'
17
17
  when :center
18
- 'window.scrollTo(document.body.scrollWidth / 2, document.body.scrollHeight / 2);'
18
+ 'window.scrollTo(window.outerWidth / 2, window.outerHeight / 2);'
19
19
  when :bottom, :end
20
20
  'window.scrollTo(0, document.body.scrollHeight);'
21
- when Watir::Element
22
- ['arguments[0].scrollIntoView();', param]
23
21
  when Array
24
22
  ['window.scrollTo(arguments[0], arguments[1]);', Integer(param[0]), Integer(param[1])]
25
23
  else
@@ -0,0 +1,13 @@
1
+ module Watir
2
+ class Element
3
+
4
+ #
5
+ # Returns scrolling object.
6
+ # @return [Scroll]
7
+ #
8
+ def scroll
9
+ Scroll.new(self)
10
+ end
11
+
12
+ end # Element
13
+ end # Watir
@@ -0,0 +1,36 @@
1
+ module Watir
2
+ class Element
3
+ class Scroll
4
+
5
+ def initialize(element)
6
+ @element = element
7
+ end
8
+
9
+ #
10
+ # Scrolls to element.
11
+ # @param [Symbol] param
12
+ #
13
+ def to(param = :top)
14
+ args = case param
15
+ when :top, :start
16
+ ['arguments[0].scrollIntoView();', @element]
17
+ when :center
18
+ script = <<-JS
19
+ var elementRect = arguments[0].getBoundingClientRect();
20
+ var top = elementRect.top - (window.innerHeight / 2);
21
+ var left = elementRect.left - (window.innerWidth / 2);
22
+ window.scrollTo(left, top);
23
+ JS
24
+ [script, @element]
25
+ when :bottom, :end
26
+ ['arguments[0].scrollIntoView(false);', @element]
27
+ else
28
+ raise ArgumentError, "Don't know how to scroll element to: #{param}!"
29
+ end
30
+
31
+ @element.browser.execute_script(*args)
32
+ end
33
+
34
+ end # Scroll
35
+ end # Element
36
+ end # Watir
@@ -2,7 +2,7 @@ module Watir
2
2
  class Browser
3
3
  class Scroll
4
4
 
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
 
7
7
  end # Scroll
8
8
  end # Browser
data/spec/spec_helper.rb CHANGED
@@ -1,55 +1,24 @@
1
1
  require "watir-scroll"
2
2
 
3
- HTML = <<-HTML
4
- <html>
5
- <head>
6
- <script>
7
- function elementInViewport(el) {
8
- var top = el.offsetTop;
9
- var left = el.offsetLeft;
10
- var width = el.offsetWidth;
11
- var height = el.offsetHeight;
12
-
13
- while(el.offsetParent) {
14
- el = el.offsetParent;
15
- top += el.offsetTop;
16
- left += el.offsetLeft;
17
- }
18
-
19
- return (
20
- top < (window.pageYOffset + window.innerHeight) &&
21
- left < (window.pageXOffset + window.innerWidth) &&
22
- (top + height) > window.pageYOffset &&
23
- (left + width) > window.pageXOffset
24
- );
25
- }
26
- </script>
27
- </head>
28
- <body>
29
- <button>Top</button
30
- #{'<br />' * 300}
31
- <button>Bottom</button
32
- </body>
33
- </html>
34
- HTML
35
-
36
-
37
3
  RSpec.configure do |spec|
38
4
  spec.before(:all) do
39
- @browser = Watir::Browser.new
40
- @browser.goto "data:text/html,#{HTML}"
5
+ opts = {}
6
+ if ENV['TRAVIS']
7
+ Selenium::WebDriver::Chrome.path = "#{File.dirname(__FILE__)}/../bin/google-chrome"
8
+ opts[:args] = ['no-sandbox']
9
+ end
10
+ @browser = Watir::Browser.new(:chrome, opts)
41
11
  end
42
12
 
43
13
  spec.after(:all) do
44
14
  @browser.quit
45
15
  end
46
16
 
47
- spec.after(:each) do
48
- @browser.refresh
17
+ spec.before(:each) do
18
+ @browser.goto "file://#{File.dirname(__FILE__)}/support/test.html"
49
19
  end
50
20
 
51
-
52
21
  def visible?(el)
53
- @browser.execute_script('return elementInViewport(arguments[0]);', el)
22
+ @browser.execute_script('return isElementInViewport(arguments[0]);', el)
54
23
  end
55
24
  end
@@ -0,0 +1,32 @@
1
+ <html>
2
+ <head>
3
+ <script>
4
+ function isElementInViewport(el) {
5
+ var top = el.offsetTop;
6
+ var left = el.offsetLeft;
7
+ var width = el.offsetWidth;
8
+ var height = el.offsetHeight;
9
+
10
+ while (el.offsetParent) {
11
+ el = el.offsetParent;
12
+ top += el.offsetTop;
13
+ left += el.offsetLeft;
14
+ }
15
+
16
+ return (
17
+ top < (window.pageYOffset + window.innerHeight) &&
18
+ left < (window.pageXOffset + window.innerWidth) &&
19
+ (top + height) > window.pageYOffset &&
20
+ (left + width) > window.pageXOffset
21
+ );
22
+ }
23
+ </script>
24
+ </head>
25
+ <body>
26
+ <div style="height: 180%; position: relative;">
27
+ <button style="position: absolute;">Top</button>
28
+ <button style="position: absolute; top: 50%;">Center</button>
29
+ <button style="position: absolute; bottom: 0;">Bottom</button>
30
+ </div>
31
+ </body>
32
+ </html>
@@ -0,0 +1,15 @@
1
+ #!/bin/bash -ex
2
+
3
+ mkdir bin/
4
+
5
+ # https://omahaproxy.appspot.com
6
+ # https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Linux_x64/
7
+ CHROME_REVISION=386257
8
+ curl -L -O "http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/${CHROME_REVISION}/chrome-linux.zip"
9
+ unzip chrome-linux.zip
10
+ ln -s "$(pwd)/chrome-linux/chrome" "$(pwd)/bin/google-chrome"
11
+
12
+ CHROMEDRIVER_VERSION=$(curl -s http://chromedriver.storage.googleapis.com/LATEST_RELEASE)
13
+ curl -L -O "http://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip"
14
+ unzip chromedriver_linux64.zip
15
+ ln -s "$(pwd)/chromedriver" "$(pwd)/bin/chromedriver"
@@ -1,32 +1,29 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "watir-scoll" do
3
+ describe Watir::Browser do
4
4
  describe "#scroll.to" do
5
5
  it "scrolls to the top of the page" do
6
6
  @browser.scroll.to :bottom
7
7
  @browser.scroll.to :top
8
8
  expect(visible?(@browser.button(text: 'Top'))).to eq(true)
9
+ expect(visible?(@browser.button(text: 'Center'))).to eq(true)
9
10
  expect(visible?(@browser.button(text: 'Bottom'))).to eq(false)
10
11
  end
11
12
 
12
13
  it "scrolls to the center of the page" do
13
14
  @browser.scroll.to :center
14
15
  expect(visible?(@browser.button(text: 'Top'))).to eq(false)
16
+ expect(visible?(@browser.button(text: 'Center'))).to eq(true)
15
17
  expect(visible?(@browser.button(text: 'Bottom'))).to eq(false)
16
18
  end
17
19
 
18
20
  it "scrolls to the bottom of the page" do
19
21
  @browser.scroll.to :bottom
20
22
  expect(visible?(@browser.button(text: 'Top'))).to eq(false)
23
+ expect(visible?(@browser.button(text: 'Center'))).to eq(true)
21
24
  expect(visible?(@browser.button(text: 'Bottom'))).to eq(true)
22
25
  end
23
26
 
24
- it "scrolls to element" do
25
- button = @browser.button(text: 'Bottom')
26
- @browser.scroll.to button
27
- expect(visible?(button)).to eq(true)
28
- end
29
-
30
27
  it "scrolls to coordiantes" do
31
28
  button = @browser.button(text: 'Bottom')
32
29
  @browser.scroll.to [button.wd.location.x, button.wd.location.y]
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe Watir::Element do
4
+ describe "#scroll.to" do
5
+ it "scrolls to element (top)" do
6
+ @browser.button(text: 'Center').scroll.to
7
+ expect(visible?(@browser.button(text: 'Top'))).to eq(false)
8
+ expect(visible?(@browser.button(text: 'Center'))).to eq(true)
9
+ expect(visible?(@browser.button(text: 'Bottom'))).to eq(true)
10
+ end
11
+
12
+ it "scrolls to element (center)" do
13
+ @browser.button(text: 'Center').scroll.to :center
14
+ expect(visible?(@browser.button(text: 'Top'))).to eq(false)
15
+ expect(visible?(@browser.button(text: 'Center'))).to eq(true)
16
+ expect(visible?(@browser.button(text: 'Bottom'))).to eq(false)
17
+ end
18
+
19
+ it "scrolls to element (bottom)" do
20
+ @browser.button(text: 'Center').scroll.to :bottom
21
+ expect(visible?(@browser.button(text: 'Top'))).to eq(true)
22
+ expect(visible?(@browser.button(text: 'Center'))).to eq(true)
23
+ expect(visible?(@browser.button(text: 'Bottom'))).to eq(false)
24
+ end
25
+
26
+ it "raises error when scroll param is not vaild" do
27
+ expect { @browser.button(text: 'Top').scroll.to(:blah) }.to raise_error(ArgumentError)
28
+ end
29
+ end
30
+ end
data/watir-scroll.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "pry"
26
27
  end
metadata CHANGED
@@ -1,78 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir-scroll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alex Rodionov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-01 00:00:00.000000000 Z
11
+ date: 2016-09-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: watir-webdriver
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '1.3'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '1.3'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
76
81
  - !ruby/object:Gem::Version
77
82
  version: '0'
78
83
  description: Scrolling API for watir-webdriver
@@ -81,50 +86,51 @@ executables: []
81
86
  extensions: []
82
87
  extra_rdoc_files: []
83
88
  files:
84
- - .gitignore
85
- - .travis.yml
89
+ - ".gitignore"
90
+ - ".travis.yml"
86
91
  - Gemfile
87
92
  - LICENSE.txt
88
93
  - README.md
89
94
  - Rakefile
90
95
  - lib/watir-scroll.rb
91
96
  - lib/watir-scroll/browser.rb
92
- - lib/watir-scroll/scroll.rb
97
+ - lib/watir-scroll/browser/scroll.rb
98
+ - lib/watir-scroll/element.rb
99
+ - lib/watir-scroll/element/scroll.rb
93
100
  - lib/watir-scroll/version.rb
94
101
  - spec/spec_helper.rb
95
- - spec/watir-scroll_spec.rb
102
+ - spec/support/test.html
103
+ - spec/support/travis.sh
104
+ - spec/watir-scroll/browser_spec.rb
105
+ - spec/watir-scroll/element_spec.rb
96
106
  - watir-scroll.gemspec
97
107
  homepage: https://github.com/p0deje/watir-scroll
98
108
  licenses:
99
109
  - MIT
110
+ metadata: {}
100
111
  post_install_message:
101
112
  rdoc_options: []
102
113
  require_paths:
103
114
  - lib
104
115
  required_ruby_version: !ruby/object:Gem::Requirement
105
- none: false
106
116
  requirements:
107
- - - ! '>='
117
+ - - ">="
108
118
  - !ruby/object:Gem::Version
109
119
  version: '0'
110
- segments:
111
- - 0
112
- hash: 435878204713146797
113
120
  required_rubygems_version: !ruby/object:Gem::Requirement
114
- none: false
115
121
  requirements:
116
- - - ! '>='
122
+ - - ">="
117
123
  - !ruby/object:Gem::Version
118
124
  version: '0'
119
- segments:
120
- - 0
121
- hash: 435878204713146797
122
125
  requirements: []
123
126
  rubyforge_project:
124
- rubygems_version: 1.8.23
127
+ rubygems_version: 2.4.5.1
125
128
  signing_key:
126
- specification_version: 3
129
+ specification_version: 4
127
130
  summary: Scrolling API for watir-webdriver
128
131
  test_files:
129
132
  - spec/spec_helper.rb
130
- - spec/watir-scroll_spec.rb
133
+ - spec/support/test.html
134
+ - spec/support/travis.sh
135
+ - spec/watir-scroll/browser_spec.rb
136
+ - spec/watir-scroll/element_spec.rb