require 'rubygems' gem 'selenium-webdriver' require "selenium-webdriver" ############################### # Moves the element by the amounts given ############################### def hover_and_move_slow(type, stuff, move_x, move_y) @debug and print "In hover_and_move_slow: #{type}, #{stuff}, #{move_x}, #{move_y}\n" distance = [ 40, ((move_x + move_y)/4).abs].max e=@driver.find_element(type, stuff) @driver.action.click_and_hold(e).perform x = e.location.x y = e.location.y goal_x = x + move_x goal_y = y + move_y while( (goal_x - x).abs > 5 or (goal_y - y).abs > 5 ) diff_x = goal_x - x diff_y = goal_y - y while( diff_x.abs > distance ) diff_x = diff_x / 2; end while( diff_y.abs > distance ) diff_y = diff_y / 2; end @debug and print "In hover_and_move_slow: moving x #{diff_x} and y #{diff_y}, given current x #{x} and y #{y} with goals x #{goal_x} and y #{goal_y}\n" @driver.action.move_by(diff_x, diff_y).perform #@debug and sleep 2 e=@driver.find_element(type, stuff) x = e.location.x y = e.location.y end @debug and print "In hover_and_move_slow: exited main loop, current x #{x} and y #{y} with goals x #{goal_x} and y #{goal_y}\n" @driver.action.release.perform end if ARGV[1] == 'ffnative' profile = Selenium::WebDriver::Firefox::Profile.new # ENABLE NATIVE EVENTS profile.native_events = true caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile, :browser_name => "firefox", :javascript_enabled => true, :takes_screenshot => true, :css_selectors_enabled => true, # ENABLE NATIVE EVENTS :native_events => true) elsif ARGV[1] == 'ffnonative' profile = Selenium::WebDriver::Firefox::Profile.new # DISABLE NATIVE EVENTS profile.native_events = false caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile, :browser_name => "firefox", :javascript_enabled => true, :takes_screenshot => true, :css_selectors_enabled => true, # DISABLE NATIVE EVENTS :native_events => false) else print "pick one\n" exit 1 end @driver = Selenium::WebDriver.for( :remote, :url => "http://localhost:#{ARGV[0]}/wd/hub", :desired_capabilities => caps) @driver.manage.timeouts.implicit_wait = 5 # seconds @driver.navigate.to "http://users.digitalkingdom.org/~rlpowell/media/public/selenium-test/jqs.html" print "hit return when watching" File.open("/dev/tty", "r").gets @debug = true hover_and_move_slow(:xpath, "//li[contains(text(),'Item 2-7')]", 0, 250) @driver.navigate.to "http://users.digitalkingdom.org/~rlpowell/media/public/selenium-test/jqs.html" print "hit return when done" File.open("/dev/tty", "r").gets @driver.quit exit 1