Skip to content

Instantly share code, notes, and snippets.

@jasonmci
Last active December 21, 2015 01:08
Show Gist options
  • Save jasonmci/6225027 to your computer and use it in GitHub Desktop.
Save jasonmci/6225027 to your computer and use it in GitHub Desktop.
Use IRB to work on WatirWebdriver automation, page objects, and mixins: 1) Start irb, 2) require './path/to/cmdline_tools.rb' 3) use load methods and unload methods as you add more page objects and other methods. Don't keep re-running automated tests to troubleshoot a problem.
require 'watir-webdriver'
require 'rspec'
# TODO: Remove the global variable
def load_mixins
# keep an array of mixins loaded
$m_constants = mixins
end
def load_pages
# keep an array of pages loaded
$p_constants = pages
end
def unload_mixins
$m_constants.each do |item|
begin
Object.send(:remove_const, item)
rescue => e
puts e
end
end
end
def unload_pages
$p_constants.each do |item|
begin
Object.send(:remove_const, item)
rescue => e
puts e
end
end
end
# lazier methods
def unload_all
unload_mixins
unload_pages
end
def load_all
load_mixins
load_pages
end
def reload
unload_all
load_all
end
# camelizing a filename removes the extension and camelizes the remainder
def camelize(file)
File.basename(file, ".rb").split('_').map {|w| w.capitalize}.join
end
def mixins
Dir["./features/support/mixins/*.rb"].collect { |file|
load file
camelize(file)
}
end
def pages
Dir["./features/support/pages/*.rb"].collect {|file|
load file
camelize(file)
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment