Created
October 20, 2009 13:05
-
-
Save jarib/214235 to your computer and use it in GitHub Desktop.
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
require "rubygems" | |
require "java" | |
require "json" | |
require "rack" | |
require "thread" | |
Dir['build/*.jar'].each { |e| require e } | |
require "remote/common/lib/runtime/json-20080701.jar" | |
import org.openqa.selenium.chrome.ChromeDriver | |
# | |
# class ChromeDriver | |
# | |
# | |
# def close | |
# {:request => 'close'}.to_json | |
# end | |
# | |
# def quit | |
# "QUIT" | |
# end | |
# | |
# def get(url) | |
# {:request => 'url', :url => url}.to_json | |
# end | |
# | |
# def title | |
# {:request => 'getTitle'}.to_json | |
# end | |
# | |
# | |
# | |
# end | |
class ChromeCommandExecutor | |
CONTENT_TYPE = "application/json; charset=UTF-8" | |
HEADERS = {'Content-Type' => CONTENT_TYPE} | |
def initialize | |
# @driver = ChromeDriver.new | |
@queue = Queue.new | |
send_command :get, {:url => 'http://google.com'} | |
send_command_and_read_response :getTitle | |
end | |
def send_command(command_name, args = {}) | |
@queue << {:request => command_name}.merge(args) | |
end | |
def send_command_and_read_response(command_name, args = {}) | |
@read_response = true | |
send_command command_name, args | |
end | |
def call(env) | |
if @read_response | |
p :response => env['rack.input'].read | |
@read_response = false | |
end | |
command = @queue.pop.to_json | |
p :sending_command => command | |
[200, HEADERS, command] | |
end | |
end | |
executor = ChromeCommandExecutor.new | |
Thread.new do | |
Rack::Handler::Mongrel.run(executor, :Host => "0.0.0.0", :Port => 9700) | |
end | |
sleep 2 | |
$stdout.sync = true | |
d = ChromeDriver.new | |
# executor.send_command :get, {:url => 'http://google.com'} | |
# executor.send_command_and_read_response :getTitle | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment