Skip to content

Commit

Permalink
ActionBuilder#move_by should send only Integer coordinates
Browse files Browse the repository at this point in the history
I'm not sure why, but if I send coordinates like this to mouseMoveTo:
`@driver.action.move_to(element, 330.1, 13).click.perform`
it click in one part of page, wrong part
But if i send
`@driver.action.move_to(element, 330, 13).click.perform`
it wors fine.

Maybe it somewhat  depends on http call, that performs - they looks like
```
"{"element":"0.14091974799732143-9","xoffset":330.1,"yoffset":13}"
"{"element":"0.23202931091340706-9","xoffset":330,"yoffset":13}"
``` and fraction part somwehow messed up requests.

Same thing apply to `ActionBuilder#move_to`

Also add specs for `move_to` `move_by` with floating point

Signed-off-by: Alex Rodionov <p0deje@gmail.com>
  • Loading branch information
ShockwaveNN authored and p0deje committed Apr 20, 2016
1 parent 40c2033 commit 2bb9c0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/common/action_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def double_click(element = nil)

def move_to(element, right_by = nil, down_by = nil)
if right_by && down_by
@actions << [:mouse, :move_to, [element, right_by, down_by]]
@actions << [:mouse, :move_to, [element, Integer(right_by), Integer(down_by)]]
else
@actions << [:mouse, :move_to, [element]]
end
Expand Down Expand Up @@ -281,7 +281,7 @@ def move_to(element, right_by = nil, down_by = nil)
#

def move_by(right_by, down_by)
@actions << [:mouse, :move_by, [right_by, down_by]]
@actions << [:mouse, :move_by, [Integer(right_by), Integer(down_by)]]
self
end

Expand Down
13 changes: 13 additions & 0 deletions rb/spec/unit/selenium/webdriver/action_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@
context_click(element).perform
end

it 'should move_to ignore floating point part of coordinate' do
expect(mouse).to receive(:move_to).with(element, -300, 400)

builder.move_to(element, -300.1, 400.1).perform
end

it 'should move_by ignore floating point part of coordinate' do
expect(mouse).to receive(:move_by).with(-300, 400)

builder.move_by(-300.1, 400.1).perform
end


it "should drag and drop" do
source = element
target = Selenium::WebDriver::Element.new(bridge, 'element2')
Expand Down

0 comments on commit 2bb9c0b

Please sign in to comment.