browser_scroll 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.hound.yml +69 -0
- data/.rspec +3 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/LICENSE.md +21 -0
- data/README.md +149 -0
- data/Rakefile +34 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/browser_scroll.gemspec +38 -0
- data/lib/browser_scroll.rb +9 -0
- data/lib/browser_scroll/browser.rb +7 -0
- data/lib/browser_scroll/browser/scroll.rb +54 -0
- data/lib/browser_scroll/element.rb +7 -0
- data/lib/browser_scroll/element/scroll.rb +53 -0
- data/lib/browser_scroll/version.rb +3 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38cb9aaf23ce8704f3cee01a99b8238a77832f52
|
4
|
+
data.tar.gz: c289be55e9752ef5743f3060bf9ad07a56da9f3c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 04ec07f1e89e280d350c1241649d26255f571fcee049aaa3da1b4c3963eb7caee86a2a9890855a43b22618d02958ce4b5db3998e21f2e39e44e227558efdb887
|
7
|
+
data.tar.gz: 58428ccb49862fb6e85ca033b80606180e866f7882681c3f664c6385abd859369e4069dc3663ec8f4d6295896ea35b4b22e710b5ef5079db88143916702bc251
|
data/.gitignore
ADDED
data/.hound.yml
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- browser_scroll.gemspec
|
4
|
+
- spec/**/*
|
5
|
+
|
6
|
+
# Removing need for frozen string literal comment.
|
7
|
+
Style/FrozenStringLiteralComment:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
# Removing the preference for string single quotes.
|
11
|
+
Style/StringLiterals:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
# Missing top-level module documentation comment.
|
15
|
+
Style/Documentation:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
# Prefer reduce over inject.
|
19
|
+
Style/CollectionMethods:
|
20
|
+
PreferredMethods:
|
21
|
+
reduce: 'inject'
|
22
|
+
|
23
|
+
# Use each_with_object instead of inject.
|
24
|
+
Style/EachWithObject:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
# Prefer fail over raise.
|
28
|
+
Style/SignalException:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
# This never works for validations.
|
32
|
+
Layout/AlignHash:
|
33
|
+
EnforcedLastArgumentHashStyle: ignore_implicit
|
34
|
+
|
35
|
+
# Align multi-line params with previous line.
|
36
|
+
Layout/AlignParameters:
|
37
|
+
EnforcedStyle: with_fixed_indentation
|
38
|
+
|
39
|
+
# Indent `when` clause one step from `case`.
|
40
|
+
Layout/CaseIndentation:
|
41
|
+
IndentOneStep: true
|
42
|
+
|
43
|
+
# Don't force bad var names for reduce/inject loops.
|
44
|
+
Style/SingleLineBlockParams:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
# For method chains, keep the dot with the method name.
|
48
|
+
Layout/DotPosition:
|
49
|
+
EnforcedStyle: leading
|
50
|
+
|
51
|
+
# Stop nesting so hard.
|
52
|
+
Metrics/BlockNesting:
|
53
|
+
Max: 2
|
54
|
+
|
55
|
+
# Encourage short methods.
|
56
|
+
Metrics/MethodLength:
|
57
|
+
Max: 15
|
58
|
+
|
59
|
+
# Encourage short (as possible) modules.
|
60
|
+
Metrics/ModuleLength:
|
61
|
+
Max: 110
|
62
|
+
|
63
|
+
# Encourage fewer parameters.
|
64
|
+
Metrics/ParameterLists:
|
65
|
+
Max: 4
|
66
|
+
|
67
|
+
# Remove execute permissions check.
|
68
|
+
Lint/ScriptPermission:
|
69
|
+
Enabled: false
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at jeff.nyman@yello.co. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jeff Nyman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
# BrowserScroll
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/browser_scroll.svg)](http://badge.fury.io/rb/browser_scroll)
|
4
|
+
[![License](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jeffnyman/browser_scroll/blob/master/LICENSE.md)
|
5
|
+
|
6
|
+
This gem provides a small API on top of the JavaScript functionality that allows scrolling within the browser.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
To get the latest stable release, add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'browser_scroll'
|
14
|
+
```
|
15
|
+
|
16
|
+
To get the latest code:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'browser_scroll', git: 'https://github.com/jeffnyman/browser_scroll'
|
20
|
+
```
|
21
|
+
|
22
|
+
After doing one of the above, execute the following command:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
You can also install BrowserScroll just as you would any other gem:
|
27
|
+
|
28
|
+
$ gem install browser_scroll
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
There are two means of scrolling: one is based on the browser window and the other is relative to an element within the browser window.
|
33
|
+
|
34
|
+
### Browser Scrolling
|
35
|
+
|
36
|
+
The API provides a simple means of scrolling to the top, middle, or bottom of the page.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
browser.scroll.to.top
|
40
|
+
browser.scroll.to.middle
|
41
|
+
browser.scroll.to.bottom
|
42
|
+
```
|
43
|
+
|
44
|
+
It is also scroll to specific x and y coordinates as such:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
browser.scroll.to [30, 30]
|
48
|
+
```
|
49
|
+
|
50
|
+
Finally, it is also possible to scroll by an offset. You can provide a horizontal and vertical offset.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
browser.scroll.by 30, 10
|
54
|
+
```
|
55
|
+
|
56
|
+
This would scroll to the left by 30 pixels and down by 10 pixels.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
browser.scroll.by -30, -10
|
60
|
+
```
|
61
|
+
|
62
|
+
Here the negative values means this would scroll to the right by 30 pixels and up by 10 pixels.
|
63
|
+
|
64
|
+
You can chain the API calls:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
browser.scroll.to.top.by(0, 30)
|
68
|
+
```
|
69
|
+
|
70
|
+
This would scroll to the top of the page and then 30 pixels down.
|
71
|
+
|
72
|
+
### Element Scrolling
|
73
|
+
|
74
|
+
Unlike scrolling in the browser itself, you can scroll relative to an element. Consider the following element:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
search = @browser.button(text: 'Search')
|
78
|
+
```
|
79
|
+
|
80
|
+
The API provides a simple means of scrolling to the top, middle, or bottom of a given element.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
search.scroll.to.top
|
84
|
+
search.scroll.to.middle
|
85
|
+
search.scroll.to.bottom
|
86
|
+
```
|
87
|
+
|
88
|
+
Note that this is not referring to the top, middle and bottom of the element. Rather, what this is doing is scrolling the element to the top of the browser, to the middle of the browser, or to the bottom of the browser. There is a shorthand for scrolling an element to the top of the browser:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
search.scroll_to
|
92
|
+
```
|
93
|
+
|
94
|
+
Unlike the browser, you won't scroll to the coordinates of the element but you can scroll the element itself by horizontal and vertical offsets.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
search.scroll.by 30, 10
|
98
|
+
```
|
99
|
+
|
100
|
+
This would scroll the element to the left by 30 pixels and down by 10 pixels.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
search.scroll.by -30, -10
|
104
|
+
```
|
105
|
+
|
106
|
+
Here the negative values means this would scroll the element to the right by 30 pixels and up by 10 pixels.
|
107
|
+
|
108
|
+
You can chain the API calls:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
search.scroll_to.by(0, 30)
|
112
|
+
```
|
113
|
+
|
114
|
+
Here this scrolls to the element and then 30 pixels down.
|
115
|
+
|
116
|
+
## Development
|
117
|
+
|
118
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec:all` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
119
|
+
|
120
|
+
The default `rake` command will run all tests as well as a RuboCop analysis.
|
121
|
+
|
122
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
123
|
+
|
124
|
+
## Contributing
|
125
|
+
|
126
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/jeffnyman/browser_scroll](https://github.com/jeffnyman/browser_scroll). The testing ecosystem of Ruby is very large and this project is intended to be a welcoming arena for collaboration on yet another test-supporting tool. As such, contributors are very much welcome but are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
127
|
+
|
128
|
+
The BrowserScroll gems follows [semantic versioning](http://semver.org).
|
129
|
+
|
130
|
+
To contribute to BrowserScroll:
|
131
|
+
|
132
|
+
1. [Fork the project](http://gun.io/blog/how-to-github-fork-branch-and-pull-request/).
|
133
|
+
2. Create your feature branch. (`git checkout -b my-new-feature`)
|
134
|
+
3. Commit your changes. (`git commit -am 'new feature'`)
|
135
|
+
4. Push the branch. (`git push origin my-new-feature`)
|
136
|
+
5. Create a new [pull request](https://help.github.com/articles/using-pull-requests).
|
137
|
+
|
138
|
+
## Author
|
139
|
+
|
140
|
+
* [Jeff Nyman](http://testerstories.com)
|
141
|
+
|
142
|
+
## Credits
|
143
|
+
|
144
|
+
This code is based upon the [watir-scroll](https://github.com/p0deje/watir-scroll) gem. I wanted to create a more chained API than one that relied on symbols. I also wanted to remove the notion that this is Watir specific. While that is currently the case, future expansion will be about being able to scroll in the browser independent of Watir.
|
145
|
+
|
146
|
+
## License
|
147
|
+
|
148
|
+
BrowserScroll is distributed under the [MIT](http://www.opensource.org/licenses/MIT) license.
|
149
|
+
See the [LICENSE](https://github.com/jeffnyman/browser_scroll/blob/master/LICENSE.md) file for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rdoc/task"
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
require "rubocop/rake_task"
|
7
|
+
|
8
|
+
RuboCop::RakeTask.new
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
|
12
|
+
namespace :spec do
|
13
|
+
desc 'Clean all generated reports'
|
14
|
+
task :clean do
|
15
|
+
system('rm -rf spec/reports')
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec::Core::RakeTask.new(all: :clean) do |config|
|
19
|
+
options = %w[--color]
|
20
|
+
options += %w[--format documentation]
|
21
|
+
options += %w[--format html --out spec/reports/unit-test-report.html]
|
22
|
+
|
23
|
+
config.rspec_opts = options
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Rake::RDocTask.new do |rdoc|
|
28
|
+
rdoc.rdoc_dir = 'doc'
|
29
|
+
rdoc.main = 'README.md'
|
30
|
+
rdoc.title = "Tapestry #{BrowserScroll::VERSION}"
|
31
|
+
rdoc.rdoc_files.include('README*', 'lib/**/*.rb')
|
32
|
+
end
|
33
|
+
|
34
|
+
task default: ['spec:all', :rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "browser_scroll"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "browser_scroll/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "browser_scroll"
|
8
|
+
spec.version = BrowserScroll::VERSION
|
9
|
+
spec.authors = ["Jeff Nyman"]
|
10
|
+
spec.email = ["jeffnyman@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provides API Around JavaScript Scrolling Functionality}
|
13
|
+
spec.description = %q{Provides API Around JavaScript Scrolling Functionality}
|
14
|
+
spec.homepage = "https://github.com/jeffnyman/browser_scroll"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "simplecov"
|
28
|
+
spec.add_development_dependency "rubocop"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
|
31
|
+
spec.add_runtime_dependency "watir", "~> 6.0"
|
32
|
+
|
33
|
+
spec.post_install_message = %{
|
34
|
+
(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
|
35
|
+
BrowserScroll #{BrowserScroll::VERSION} has been installed.
|
36
|
+
(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
|
37
|
+
}
|
38
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Watir
|
2
|
+
class Browser
|
3
|
+
class Scroll
|
4
|
+
def initialize(browser)
|
5
|
+
@browser = browser
|
6
|
+
end
|
7
|
+
|
8
|
+
def to(param = nil)
|
9
|
+
if !param.nil? && param.is_a?(Array)
|
10
|
+
unless param.is_a?(Array)
|
11
|
+
raise ArgumentError, "Unable to scroll to: #{param}."
|
12
|
+
end
|
13
|
+
|
14
|
+
execute(
|
15
|
+
'window.scrollTo(arguments[0], arguments[1]);',
|
16
|
+
Integer(param[0]), Integer(param[1])
|
17
|
+
)
|
18
|
+
end
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def top
|
23
|
+
execute('window.scrollTo(0, 0);')
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def bottom
|
28
|
+
execute('window.scrollTo(0, document.body.scrollHeight);')
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def middle
|
33
|
+
execute(
|
34
|
+
'window.scrollTo(window.outerWidth / 2, window.outerHeight / 2);'
|
35
|
+
)
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def by(left, top)
|
40
|
+
execute(
|
41
|
+
'window.scrollBy(arguments[0], arguments[1]);',
|
42
|
+
Integer(left), Integer(top)
|
43
|
+
)
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def execute(*args)
|
50
|
+
@browser.execute_script(*args)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Watir
|
2
|
+
class Element
|
3
|
+
class Scroll
|
4
|
+
def initialize(element)
|
5
|
+
@element = element
|
6
|
+
end
|
7
|
+
|
8
|
+
def to
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def scroll_to
|
13
|
+
top
|
14
|
+
end
|
15
|
+
|
16
|
+
def top
|
17
|
+
execute('arguments[0].scrollIntoView();', @element)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def bottom
|
22
|
+
execute('arguments[0].scrollIntoView(false);', @element)
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def middle
|
27
|
+
script = <<-JS
|
28
|
+
var bodyRect = document.body.getBoundingClientRect();
|
29
|
+
var elementRect = arguments[0].getBoundingClientRect();
|
30
|
+
var left = (elementRect.left - bodyRect.left) - (window.innerWidth / 2);
|
31
|
+
var top = (elementRect.top - bodyRect.top) - (window.innerHeight / 2);
|
32
|
+
window.scrollTo(left, top);
|
33
|
+
JS
|
34
|
+
execute(script, @element)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def by(left, top)
|
39
|
+
execute(
|
40
|
+
'window.scrollBy(arguments[0], arguments[1]);',
|
41
|
+
Integer(left), Integer(top)
|
42
|
+
)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def execute(*args)
|
49
|
+
@element.browser.execute_script(*args)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: browser_scroll
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Nyman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
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
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: watir
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '6.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '6.0'
|
111
|
+
description: Provides API Around JavaScript Scrolling Functionality
|
112
|
+
email:
|
113
|
+
- jeffnyman@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".hound.yml"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".travis.yml"
|
123
|
+
- CODE_OF_CONDUCT.md
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.md
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- browser_scroll.gemspec
|
131
|
+
- lib/browser_scroll.rb
|
132
|
+
- lib/browser_scroll/browser.rb
|
133
|
+
- lib/browser_scroll/browser/scroll.rb
|
134
|
+
- lib/browser_scroll/element.rb
|
135
|
+
- lib/browser_scroll/element/scroll.rb
|
136
|
+
- lib/browser_scroll/version.rb
|
137
|
+
homepage: https://github.com/jeffnyman/browser_scroll
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
141
|
+
post_install_message: "\n(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n
|
142
|
+
\ BrowserScroll 0.5.0 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::)
|
143
|
+
(::) (::) (::) (::)\n "
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.5.2.2
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Provides API Around JavaScript Scrolling Functionality
|
163
|
+
test_files: []
|