watir-scroll 0.3.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: ce4bc5bebb0484cddc169c4c7ffad221e3d1c27e
4
- data.tar.gz: 8e463985f87b471e4a4fa1b3637c1f5237ea1bef
3
+ metadata.gz: 5e8291e46790f58afdf548a985a2c7295aa969b3
4
+ data.tar.gz: 5c9539242ff3222ea90a5a41eaefd8f14090e9fd
5
5
  SHA512:
6
- metadata.gz: d8201882db22a17dffd6f1f5ee9b02da6fec269684d3074a4afd9f8fb791f2526e0c0557a2183f1a81ce75b5b07ee81af19657a53c8199fa50165c1155c0561c
7
- data.tar.gz: 3a3f7a8219ef77c52c5b87ecf625199624e217d049374bf2fedf714c9e8c0da30d7b51999953dc06d7f06ba23ae048c05a7d9c3d55a5c5f1c1f5ccdc86399eaa
6
+ metadata.gz: 61629d89d7a642a9b001c2c9c0343e7dc0cc2fd19a0a671b1eb12abecd0e1b1b2d389ed10f48dbce04a09ba25e57afc69e15267a56ca1d9de5d40b19ee68b579
7
+ data.tar.gz: 41f383d3058e8f9677d0b53f68f3708c8519a646db3f55deeaa73cdc33705f36f15243b0fc645fac3207722fb2649c9c3b6b586db06988502ff1d7541fc41c46
data/README.md CHANGED
@@ -31,6 +31,14 @@ 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.by 10, 10 # scrolls to left and down by 10 pixels
35
+ browser.scroll.by -10, -10 # scrolls to right and top by 10 pixels
36
+ ```
37
+
38
+ You can also chain the calls:
39
+
40
+ ```ruby
41
+ browser.scroll.to(:top).by(0, 100) # scrolls to the top of the page and 100 pixels down
34
42
  ```
35
43
 
36
44
  ### Scrolling To Elements
@@ -42,8 +50,17 @@ button = browser.button(text: 'Click')
42
50
  button.scroll.to # scrolls element to the top
43
51
  button.scroll.to :center # scrolls element to the center
44
52
  button.scroll.to :bottom # scrolls element to the bottom
53
+ button.scroll.by 10, 10 # scrolls to left and down by 10 pixels
54
+ button.scroll.by -10, -10 # scrolls to right and top by 10 pixels
45
55
  ```
46
56
 
57
+ You can also chain the calls:
58
+
59
+ ```ruby
60
+ button.scroll.to.by(0, 100) # scrolls to the button and 100 pixels down
61
+ ```
62
+
63
+
47
64
  ## Contributing
48
65
 
49
66
  1. Fork it
@@ -23,8 +23,19 @@ module Watir
23
23
  else
24
24
  raise ArgumentError, "Don't know how to scroll to: #{param}!"
25
25
  end
26
+ @browser.execute_script(*args)
26
27
 
27
- @browser.execute_script(*args)
28
+ self
29
+ end
30
+
31
+ #
32
+ # Scrolls by offset.
33
+ # @param [Fixnum] left Horizontal offset
34
+ # @param [Fixnum] top Vertical offset
35
+ #
36
+ def by(left, top)
37
+ @browser.execute_script('window.scrollBy(arguments[0], arguments[1]);', Integer(left), Integer(top))
38
+ self
28
39
  end
29
40
 
30
41
  end # Scroll
@@ -16,9 +16,10 @@ module Watir
16
16
  ['arguments[0].scrollIntoView();', @element]
17
17
  when :center
18
18
  script = <<-JS
19
+ var bodyRect = document.body.getBoundingClientRect();
19
20
  var elementRect = arguments[0].getBoundingClientRect();
20
- var top = elementRect.top - (window.innerHeight / 2);
21
- var left = elementRect.left - (window.innerWidth / 2);
21
+ var left = (elementRect.left - bodyRect.left) - (window.innerWidth / 2);
22
+ var top = (elementRect.top - bodyRect.top) - (window.innerHeight / 2);
22
23
  window.scrollTo(left, top);
23
24
  JS
24
25
  [script, @element]
@@ -27,8 +28,19 @@ module Watir
27
28
  else
28
29
  raise ArgumentError, "Don't know how to scroll element to: #{param}!"
29
30
  end
30
-
31
31
  @element.browser.execute_script(*args)
32
+
33
+ self
34
+ end
35
+
36
+ #
37
+ # Scrolls by offset.
38
+ # @param [Fixnum] left Horizontal offset
39
+ # @param [Fixnum] top Vertical offset
40
+ #
41
+ def by(left, top)
42
+ @element.execute_script('window.scrollBy(arguments[0], arguments[1]);', Integer(left), Integer(top))
43
+ self
32
44
  end
33
45
 
34
46
  end # Scroll
@@ -24,12 +24,18 @@ describe Watir::Browser do
24
24
  expect(visible?(@browser.button(text: 'Bottom'))).to eq(true)
25
25
  end
26
26
 
27
- it "scrolls to coordiantes" do
27
+ it "scrolls to coordinates" do
28
28
  button = @browser.button(text: 'Bottom')
29
29
  @browser.scroll.to [button.wd.location.x, button.wd.location.y]
30
30
  expect(visible?(button)).to eq(true)
31
31
  end
32
32
 
33
+ it "scrolls by offset" do
34
+ button = @browser.button(text: 'Bottom')
35
+ @browser.scroll.by(0, button.wd.location.y)
36
+ expect(visible?(button)).to eq(true)
37
+ end
38
+
33
39
  it "raises error when scroll point is not vaild" do
34
40
  expect { @browser.scroll.to(:blah) }.to raise_error(ArgumentError)
35
41
  end
@@ -23,6 +23,20 @@ describe Watir::Element do
23
23
  expect(visible?(@browser.button(text: 'Bottom'))).to eq(false)
24
24
  end
25
25
 
26
+ it "scrolls to element multiple times" do
27
+ 2.times do
28
+ @browser.button(text: 'Center').scroll.to(:center)
29
+ expect(visible?(@browser.button(text: 'Top'))).to eq(false)
30
+ end
31
+ end
32
+
33
+ it "scrolls by offset" do
34
+ @browser.button(text: 'Bottom').scroll.to.by(-10000, -10000) # simulate scrolling to top
35
+ expect(visible?(@browser.button(text: 'Top'))).to eq(true)
36
+ expect(visible?(@browser.button(text: 'Center'))).to eq(true)
37
+ expect(visible?(@browser.button(text: 'Bottom'))).to eq(false)
38
+ end
39
+
26
40
  it "raises error when scroll param is not vaild" do
27
41
  expect { @browser.button(text: 'Top').scroll.to(:blah) }.to raise_error(ArgumentError)
28
42
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "watir-scroll"
7
- spec.version = "0.3.0"
7
+ spec.version = "0.4.0"
8
8
  spec.authors = "Alex Rodionov"
9
9
  spec.email = "p0deje@gmail.com"
10
10
  spec.description = "Scrolling API for Watir"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir-scroll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rodionov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-17 00:00:00.000000000 Z
11
+ date: 2018-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: watir
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.4.5.1
126
+ rubygems_version: 2.6.13
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Scrolling API for Watir