watir-scroll 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ before_install:
5
+ - "export DISPLAY=:99.0"
6
+ - "sh -e /etc/init.d/xvfb start"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in watir-scroll.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alex Rodionov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
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)
2
+
3
+ Scrolling API for [watir-webdriver](http://github.com/watir/watir-webdriver).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'watir-scroll'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```shell
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```shell
22
+ $ gem install watir-scroll
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ button = browser.button(:text => 'Click')
29
+
30
+ browser.scroll.to :top # scrolls to the top of the page
31
+ browser.scroll.to :center # scrolls to the center of the page
32
+ browser.scroll.to :bottom # scrolls to the bottom of the page
33
+ browser.scroll.to [10, 10] # scrolls to coordinates x and y
34
+ browser.scroll.to button # scrolls to element
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |spec|
5
+ spec.rspec_opts = %w(--color)
6
+ spec.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task default: :spec
10
+
@@ -0,0 +1,4 @@
1
+ require "watir-webdriver"
2
+ require "watir-scroll/browser"
3
+ require "watir-scroll/scroll"
4
+ require "watir-scroll/version"
@@ -0,0 +1,13 @@
1
+ module Watir
2
+ class Browser
3
+
4
+ #
5
+ # Returns scrolling object.
6
+ # @return [Scroll]
7
+ #
8
+ def scroll
9
+ Scroll.new(self)
10
+ end
11
+
12
+ end # Browser
13
+ end # Watir
@@ -0,0 +1,34 @@
1
+ module Watir
2
+ class Browser
3
+ class Scroll
4
+
5
+ def initialize(browser)
6
+ @browser = browser
7
+ end
8
+
9
+ #
10
+ # Scrolls to position.
11
+ # @param [Symbol, Watir::Element, Array<Fixnum>] param
12
+ #
13
+ def to(param)
14
+ args = case param
15
+ when :top, :start
16
+ 'window.scrollTo(0, 0);'
17
+ when :center
18
+ 'window.scrollTo(document.body.scrollWidth / 2, document.body.scrollHeight / 2);'
19
+ when :bottom, :end
20
+ 'window.scrollTo(0, document.body.scrollHeight);'
21
+ when Watir::Element
22
+ ['arguments[0].scrollIntoView();', param]
23
+ when Array
24
+ ['window.scrollTo(arguments[0], arguments[1]);', Integer(param[0]), Integer(param[1])]
25
+ else
26
+ raise ArgumentError, "Don't know how to scroll to: #{param}!"
27
+ end
28
+
29
+ @browser.execute_script(*args)
30
+ end
31
+
32
+ end # Scroll
33
+ end # Browser
34
+ end # Watir
@@ -0,0 +1,9 @@
1
+ module Watir
2
+ class Browser
3
+ class Scroll
4
+
5
+ VERSION = "0.1.0"
6
+
7
+ end # Scroll
8
+ end # Browser
9
+ end # Watir
@@ -0,0 +1,55 @@
1
+ require "watir-scroll"
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
+ RSpec.configure do |spec|
38
+ spec.before(:all) do
39
+ @browser = Watir::Browser.new
40
+ @browser.goto "data:text/html,#{HTML}"
41
+ end
42
+
43
+ spec.after(:all) do
44
+ @browser.quit
45
+ end
46
+
47
+ spec.after(:each) do
48
+ @browser.refresh
49
+ end
50
+
51
+
52
+ def visible?(el)
53
+ @browser.execute_script('return elementInViewport(arguments[0]);', el)
54
+ end
55
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ describe "watir-scoll" do
4
+ describe "#scroll.to" do
5
+ it "scrolls to the top of the page" do
6
+ @browser.scroll.to :bottom
7
+ @browser.scroll.to :top
8
+ expect(visible?(@browser.button(text: 'Top'))).to eq(true)
9
+ expect(visible?(@browser.button(text: 'Bottom'))).to eq(false)
10
+ end
11
+
12
+ it "scrolls to the center of the page" do
13
+ @browser.scroll.to :center
14
+ expect(visible?(@browser.button(text: 'Top'))).to eq(false)
15
+ expect(visible?(@browser.button(text: 'Bottom'))).to eq(false)
16
+ end
17
+
18
+ it "scrolls to the bottom of the page" do
19
+ @browser.scroll.to :bottom
20
+ expect(visible?(@browser.button(text: 'Top'))).to eq(false)
21
+ expect(visible?(@browser.button(text: 'Bottom'))).to eq(true)
22
+ end
23
+
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
+ it "scrolls to coordiantes" do
31
+ button = @browser.button(text: 'Bottom')
32
+ @browser.scroll.to [button.wd.location.x, button.wd.location.y]
33
+ expect(visible?(button)).to eq(true)
34
+ end
35
+
36
+ it "raises error when scroll point is not vaild" do
37
+ expect { @browser.scroll.to(:blah) }.to raise_error(ArgumentError)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'watir-scroll/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "watir-scroll"
8
+ spec.version = Watir::Browser::Scroll::VERSION
9
+ spec.authors = "Alex Rodionov"
10
+ spec.email = "p0deje@gmail.com"
11
+ spec.description = "Scrolling API for watir-webdriver"
12
+ spec.summary = "Scrolling API for watir-webdriver"
13
+ spec.homepage = "https://github.com/p0deje/watir-scroll"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "watir-webdriver"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watir-scroll
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Rodionov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: watir-webdriver
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Scrolling API for watir-webdriver
79
+ email: p0deje@gmail.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - .gitignore
85
+ - .travis.yml
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - lib/watir-scroll.rb
91
+ - lib/watir-scroll/browser.rb
92
+ - lib/watir-scroll/scroll.rb
93
+ - lib/watir-scroll/version.rb
94
+ - spec/spec_helper.rb
95
+ - spec/watir-scroll_spec.rb
96
+ - watir-scroll.gemspec
97
+ homepage: https://github.com/p0deje/watir-scroll
98
+ licenses:
99
+ - MIT
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ segments:
111
+ - 0
112
+ hash: 435878204713146797
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ segments:
120
+ - 0
121
+ hash: 435878204713146797
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.23
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Scrolling API for watir-webdriver
128
+ test_files:
129
+ - spec/spec_helper.rb
130
+ - spec/watir-scroll_spec.rb