Created
November 29, 2011 20:02
-
-
Save dwt/1406218 to your computer and use it in GitHub Desktop.
Testing jquery-ui sortable with capybara
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run via: ruby -rubygems app.rb | |
require 'sinatra' | |
require 'haml' | |
disable :logging | |
get '/' do | |
title = "Drag'n'drop issue reduction" | |
haml :index | |
end | |
def drag_to(source, target) | |
builder = page.driver.browser.action | |
source = source.native | |
target = target.native | |
builder.click_and_hold source | |
builder.move_to target, 1, 11 | |
builder.move_to target | |
builder.release target | |
builder.perform | |
end | |
def trigger_selenium() | |
require 'capybara/dsl' | |
ENV['PATH'] += ':/Users/dwt/Applications/Network/Browser/Firefox.app/Contents/MacOS/' | |
Capybara.app_host = 'http://localhost:4567' | |
Capybara.run_server = false | |
Capybara.default_driver = :selenium | |
include Capybara | |
visit '/' | |
# Should work, but doesn't | |
# find('.first').drag_to(find('.third')) | |
# Does work, though not pretty | |
drag_to find('.first'), find('.third') | |
order = all('li').map { | each | each.text } | |
require 'test/unit' | |
include Test::Unit::Assertions | |
assert order == %w{Second Third First Fourth} | |
puts "Success, drag and drop worked" | |
end | |
Thread.abort_on_exception = true | |
Thread.new do | |
trigger_selenium() | |
exit | |
end | |
__END__ | |
@@ index | |
!!! 5 | |
%html | |
%head | |
:css | |
body { position: absolute; height: 100%; } | |
.top-spacer { height: 20%; } | |
.list { height: 100%; } | |
%script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js") | |
%script(src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js") | |
:javascript | |
$(function(){ | |
$('.list').sortable() | |
}) | |
%body | |
.top-spacer Top Spacer | |
%ul.list | |
%li.first First | |
%li.second Second | |
%li.third Third | |
%li.fourth Fourth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment