Skip to content

Instantly share code, notes, and snippets.

@prolificcoder
Last active December 18, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prolificcoder/5794721 to your computer and use it in GitHub Desktop.
Save prolificcoder/5794721 to your computer and use it in GitHub Desktop.
Dynamic method names for cells in iOS. Refactoring welcome. With this code one could call menu_view.signin menu_view.login etc.. without actually defining the methods
class MenuView
# Process the cell names 1)convert to lowercase 2)remove spaces
# create a hash of cell names and cells, call super if correct cell
# isn't given other return the cell
# Notice that global $driver should be called explicitly
def method_missing(name, *args)
name = name.to_s
cells = $driver.find_eles_attr 'UIATableCell', 'name'
cell_names_downcase = cells.map { |cell| cell.downcase }
cell_names_strip = cell_names_downcase.map { |cell| cell.gsub(/\s/,'') }
h = Hash[cell_names_strip.zip cells]
return super :name unless h.has_key? name
$driver.find_element(:name, h[name])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment