Class: MonkeyTester::RandomWalker
- Inherits:
-
Object
- Object
- MonkeyTester::RandomWalker
- Includes:
- Capybara::DSL
- Defined in:
- lib/monkey_tester/random_walker.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ RandomWalker
constructor
A new instance of RandomWalker.
- #walk ⇒ Object
Constructor Details
#initialize(options) ⇒ RandomWalker
Returns a new instance of RandomWalker.
4 5 6 7 8 9 10 |
# File 'lib/monkey_tester/random_walker.rb', line 4 def initialize() @url = [:url] @scheme = URI.parse(@url).scheme @host = URI.parse(@url).host @login = [:login] @debug = [:debug] end |
Instance Method Details
#walk ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/monkey_tester/random_walker.rb', line 12 def walk visit @url while true begin login @login[:url] and next if page.current_url == @login[:url] puts [page.status_code, page.current_url, page.title].join("\t") next_link = all('a').reject{ |a| a[:href] !~ /^#{@scheme}:\/\/#{@host}/ && a[:href] =~ /:\/\// }.sample page.evaluate_script('window.history.back()') and next unless next_link puts [next_link, next_link[:href], next_link.text].join("\t") if @debug next_link.click rescue Capybara::Poltergeist::MouseEventFailed => e # just ignore rescue => e puts e puts e. end end end |