Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
MINOR: Rearrange getElement calls
Browse files Browse the repository at this point in the history
  • Loading branch information
lingo committed May 10, 2010
1 parent ba62864 commit 2f71ca2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
9 changes: 5 additions & 4 deletions lib/salad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,26 @@ def isChecked?(element)


# Portable getElement function.
# Usage: getElement('Item one', [:name, :id, :class, ...]) {|how,what| browser.button(how, what)}
def getElement(what, hows=nil, &createFn)
# Usage: getElement('button', 'Item one', [:name, :id, :class, ...])
def getElement(type, what, hows=nil, &createFn)
elt = nil
if hows == nil then
hows = [:id, :name, :value, :label, :index, :class]
end
method = @browser.method(type);
hows.each {|how|
self.debug(":how = #{how}")
if how == :index and not what.is_a?(Numeric) then next end
if how == :label then
self.debug("Trying label")
elt = self.byLabel(what) {|id| createFn.call(:id, id)}
elt = self.byLabel(what) {|id| method.call(:id, id)}
if elt and elt.exists? and elt.visible? then
return elt
end
next
end
self.debug("Try Create, using #{how} #{what}")
elt = createFn.call(how, what)
elt = method.call(how, what)
if elt and elt.exists? and elt.visible? then
break
end
Expand Down
2 changes: 1 addition & 1 deletion step_definitions/browser/checkboxes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@


def getCheckbox(field)
return @salad.getElement(field) {|how,what| @salad.browser.checkbox(how, what)}
return @salad.getElement('checkbox', field)
end
3 changes: 1 addition & 2 deletions step_definitions/browser/generalisations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def getElementTyped(what, methods, hows=nil, &action)
how = nil
type = nil
methods.each {|method_name|
method = @salad.browser.method(method_name)
elt = @salad.getElement(what, hows) {|how,what| method.call(how,what)}
elt = @salad.getElement(method_name, what, hows)
if elt and elt.exists? and elt.visible? then
type = method_name
break
Expand Down
17 changes: 6 additions & 11 deletions step_definitions/browser/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@
end

def getLink(browser, match)
link = browser.link(:id, match)
if not link.exists? then link = browser.link(:text, match) end
if not link.exists? then link = browser.link(:class, match) end
# Try the URL with both the baseURL prefix and without it
if not link.exists? then link = browser.link(:url, @baseURL + match) end
if not link.exists? then link = browser.link(:url, match) end
if not link.exists? then link = browser.link(:xpath, match) end
if not link.exists? then link = nil end

return link
end
link = @salad.getElement('link', match, [:text,:class,:url,:xpath])
if not (link and link.exists? and link.visible?)
match = @baseURL + match
link = @salad.getElement('link', match, [:text,:class,:url,:xpath])
end
return link
2 changes: 1 addition & 1 deletion step_definitions/browser/radio_buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@


def getRadioButton(what)
return @salad.getElement(what) {|how,what| @salad.browser.radio(how, what)}
return @salad.getElement('radio', what)
end
2 changes: 1 addition & 1 deletion step_definitions/browser/text_fields.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Given /put "(.*)" in(?:to)? the "(.*)" field/i do |text,type|
field = @salad.getElement(type) { |how,what| @salad.browser.text_field(how,what) }
# field = @salad.getElement('text_field', type)
field = getTextField(@salad.browser, type)
if field then
field.set(text)
Expand Down

0 comments on commit 2f71ca2

Please sign in to comment.