Skip to content

Commit

Permalink
click_button() on an image field now provides default x,y coordinates…
Browse files Browse the repository at this point in the history
… of 0,0
  • Loading branch information
trammel committed Nov 9, 2009
1 parent bc283d8 commit e1ec2df
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/webrat/core/elements/field.rb
Expand Up @@ -55,7 +55,7 @@ def self.field_class(element)
when "reset" then ResetField
when "submit" then ButtonField
when "button" then ButtonField
when "image" then ButtonField
when "image" then ImageField
else TextField
end
end
Expand Down Expand Up @@ -227,6 +227,28 @@ def click

end

class ImageField < ButtonField
def self.xpath_search
[".//input[@type = 'image']"]
end

def to_param
params = super
params = {} if params.nil?
if @clickedX && @clickedY
params["#{name}.x"] = @clickedX
params["#{name}.y"] = @clickedY
end
return params
end

def click x=0, y=0
@clickedX = x
@clickedY = y
super()
end
end

class HiddenField < Field #:nodoc:

def self.xpath_search
Expand Down
12 changes: 12 additions & 0 deletions spec/public/click_button_spec.rb
Expand Up @@ -491,4 +491,16 @@
webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""})
click_button "Login"
end

it "should provide a default x and y coordinate of 0,0 when clicking an image" do
with_html <<-HTML
<html>
<form method="get" action="/login">
<input type="image" name="login" value="Login" />
</form>
</html>
HTML
webrat_session.should_receive(:get).with("/login", "login" => "Login", "login.x" => 0, "login.y" => 0)
click_button("Login")
end
end

0 comments on commit e1ec2df

Please sign in to comment.