akephalos 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/TODO.txt CHANGED
@@ -1,8 +1,14 @@
1
- 0.0.4
1
+ 0.0.5
2
2
  =======================================================================================
3
3
  * DRb server should never shut down prematurely -- missing methods, 500 errors,
4
4
  even java errors (NPE error from bad javascript).
5
5
 
6
+ 0.0.4
7
+ =======================================================================================
8
+ - Update to jruby 1.5
9
+ - bin/akephalos for interactive mode
10
+ - use internally managed java threading instead of capybara's own wait methods
11
+
6
12
  0.0.3
7
13
  =======================================================================================
8
14
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/akephalos.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{akephalos}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bernerd Schaefer"]
12
- s.date = %q{2010-06-03}
12
+ s.date = %q{2010-06-15}
13
13
  s.default_executable = %q{akephalos}
14
14
  s.description = %q{}
15
15
  s.email = %q{bj.schaefer@gmail.com}
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "lib/akephalos.rb",
29
29
  "lib/akephalos/capybara.rb",
30
30
  "lib/akephalos/client.rb",
31
+ "lib/akephalos/console.rb",
31
32
  "lib/akephalos/cucumber.rb",
32
33
  "lib/akephalos/htmlunit.rb",
33
34
  "lib/akephalos/node.rb",
@@ -36,6 +37,7 @@ Gem::Specification.new do |s|
36
37
  "lib/akephalos/server.rb",
37
38
  "spec/driver/akephalos_driver_spec.rb",
38
39
  "spec/session/akephalos_session_spec.rb",
40
+ "spec/slow_page_loads_spec.rb",
39
41
  "spec/spec.opts",
40
42
  "spec/spec_helper.rb",
41
43
  "src/commons-codec-1.4.jar",
@@ -47,7 +49,7 @@ Gem::Specification.new do |s|
47
49
  "src/cssparser-0.9.5.jar",
48
50
  "src/htmlunit-2.6.jar",
49
51
  "src/htmlunit-core-js-2.6.jar",
50
- "src/jruby-complete-1.4.0.jar",
52
+ "src/jruby-complete-1.5.0.jar",
51
53
  "src/nekohtml-1.9.13.jar",
52
54
  "src/sac-1.3.jar",
53
55
  "src/serializer-2.7.1.jar",
@@ -63,6 +65,7 @@ Gem::Specification.new do |s|
63
65
  s.test_files = [
64
66
  "spec/driver/akephalos_driver_spec.rb",
65
67
  "spec/session/akephalos_session_spec.rb",
68
+ "spec/slow_page_loads_spec.rb",
66
69
  "spec/spec_helper.rb"
67
70
  ]
68
71
 
data/bin/akephalos CHANGED
@@ -1,13 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
2
  # vim:set filetype=ruby:
3
3
 
4
- raise "Usage: akephalos socket_file" unless ARGV[0]
5
- require 'pathname'
4
+ require "pathname"
5
+ require "optparse"
6
+
7
+ options = { :interactive => false }
8
+
9
+ parser = OptionParser.new do |opts|
10
+ opts.banner = "Usage: akephalos [--interactive] | [--server] <socket_file>"
11
+ opts.on("-s", "--server", "Run in server mode (default)")
12
+ opts.on("-i", "--interactive", "Run in interactive mode") { options[:interactive] = true }
13
+
14
+ opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
15
+ end
16
+ parser.parse!
6
17
 
7
18
  root = Pathname(__FILE__).expand_path.dirname.parent
8
19
  lib = root + 'lib'
9
- jruby = root + "src/jruby-complete-1.4.0.jar"
10
- server = 'akephalos/server'
20
+ jruby = root + "src/jruby-complete-1.5.0.jar"
21
+ jruby_cmd = %Q(java -Xmx2048M -jar #{jruby} -I#{lib})
22
+
23
+ if options[:interactive]
24
+ $:.unshift(lib)
25
+ require 'rubygems'
26
+ require 'akephalos'
27
+ require 'akephalos/console'
28
+ Akephalos::Console.start
29
+ else
30
+ unless socket_file = ARGV[0]
31
+ puts parser.help
32
+ exit
33
+ end
34
+
35
+ server = 'akephalos/server'
11
36
 
12
- command = %Q(java -Xmx2048M -jar #{jruby} -I#{lib} -r #{server} -e 'Akephalos::Server.start!(%s)')
13
- exec command % ARGV[0].inspect
37
+ command = %Q(#{jruby_cmd} -r#{server} -e 'Akephalos::Server.start!(%s)')
38
+ exec command % socket_file.inspect
39
+ end
@@ -144,7 +144,9 @@ class Capybara::Driver::Akephalos < Capybara::Driver::Base
144
144
  self.class.driver
145
145
  end
146
146
 
147
- def wait?; true end
147
+ def wait
148
+ false
149
+ end
148
150
 
149
151
  private
150
152
 
@@ -8,21 +8,56 @@ else
8
8
 
9
9
  module Akephalos
10
10
  class Client
11
+ attr_reader :page
12
+
11
13
  def initialize
12
14
  @_client = WebClient.new
15
+
16
+ @_client.setAjaxController(com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController.new)
17
+
18
+ listener = Class.new do
19
+ include com.gargoylesoftware.htmlunit.WebWindowListener
20
+
21
+ def initialize(client)
22
+ @client = client
23
+ end
24
+
25
+ def webWindowContentChanged(event)
26
+ @client.page = event.getNewPage
27
+ if latch = Thread.current[:latch]
28
+ latch.countDown
29
+ Thread.current[:latch] = nil
30
+ end
31
+ end
32
+ end
33
+
34
+ @_client.addWebWindowListener(listener.new(self))
13
35
  @_client.setCssErrorHandler(com.gargoylesoftware.htmlunit.SilentCssErrorHandler.new)
14
36
  end
15
37
 
16
38
  def visit(url)
17
- @page = Page.new(@_client.getPage(url))
39
+ self.class.wait_for_result do
40
+ @_client.getPage(url)
41
+ end
18
42
  end
19
43
 
20
- def page
21
- if @page != (page = @_client.getCurrentWindow.getEnclosedPage)
22
- @page = Page.new(page)
44
+ def page=(_page)
45
+ if @page != _page
46
+ @page = Page.new(_page)
23
47
  end
24
48
  @page
25
49
  end
50
+
51
+ def self.wait_for_result(timeout = 3)
52
+ latch = java.util.concurrent.CountDownLatch.new(1)
53
+ Thread.new do
54
+ Thread.current[:latch] = latch
55
+ yield
56
+ end.join
57
+ start = Time.now
58
+ latch.await(timeout, java.util.concurrent.TimeUnit::SECONDS)
59
+ end
60
+
26
61
  end
27
62
  end
28
63
  end
@@ -0,0 +1,27 @@
1
+ def session
2
+ Capybara.app_host = "http://localhost:8070"
3
+ @session ||= Capybara::Session.new(:Akephalos)
4
+ end
5
+ alias page session
6
+
7
+ module Akephalos
8
+ class Console
9
+
10
+ def self.start
11
+ require 'irb'
12
+
13
+ begin
14
+ require 'irb/completion'
15
+ rescue Exception
16
+ # No readline available, proceed anyway.
17
+ end
18
+
19
+ if ::File.exists? ".irbrc"
20
+ ENV['IRBRC'] = ".irbrc"
21
+ end
22
+
23
+ IRB.start
24
+ end
25
+
26
+ end
27
+ end
@@ -59,6 +59,8 @@ module Akephalos
59
59
 
60
60
  def click
61
61
  @_node.click
62
+ @_node.getPage.getEnclosingWindow.getJobManager.waitForJobs(1000)
63
+ @_node.getPage.getEnclosingWindow.getJobManager.waitForJobsStartingBefore(1000)
62
64
  end
63
65
 
64
66
  def find(selector)
@@ -1,3 +1,5 @@
1
+ require 'drb/drb'
2
+
1
3
  module Akephalos
2
4
  class RemoteClient
3
5
  @socket_file = "/tmp/akephalos.#{Process.pid}.sock"
@@ -9,18 +9,8 @@ class NameError::Message
9
9
  end
10
10
 
11
11
  [
12
- java.net.URL,
13
- java.util.List,
14
- com.gargoylesoftware.htmlunit.html.DomNode,
15
- com.gargoylesoftware.htmlunit.html.DomElement,
16
- com.gargoylesoftware.htmlunit.html.HtmlAnchor,
17
- com.gargoylesoftware.htmlunit.html.HtmlElement,
18
- com.gargoylesoftware.htmlunit.html.HtmlPage,
19
- org.w3c.dom.Node,
20
- org.w3c.dom.NamedNodeMap,
21
- com.gargoylesoftware.htmlunit.WebClient,
22
- com.gargoylesoftware.htmlunit.WebResponse,
23
- com.gargoylesoftware.htmlunit.WebRequestSettings
12
+ Akephalos::Page,
13
+ Akephalos::Node
24
14
  ].each { |klass| klass.send(:include, DRbUndumped) }
25
15
 
26
16
  module Akephalos
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ class SlowApp < TestApp
4
+ get '/slow_page' do
5
+ sleep 1
6
+ "<p>Loaded!</p>"
7
+ end
8
+
9
+ get '/really_slow_page' do
10
+ sleep 5
11
+ end
12
+
13
+ get '/slow_ajax_load' do
14
+ <<-HTML
15
+ <head>
16
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
17
+ <title>with_js</title>
18
+ <script src="/jquery.js" type="text/javascript" charset="utf-8"></script>
19
+ <script type="text/javascript">
20
+ $(function() {
21
+ $('#ajax_load').click(function() {
22
+ // $('body').html("<p>Loaded!</p>");
23
+ $('body').load('/slow_page');
24
+ return false;
25
+ });
26
+ });
27
+ </script>
28
+ </head>
29
+ <body>
30
+ <a href="#" id="ajax_load">Click me</a>
31
+ </body>
32
+ HTML
33
+ end
34
+ end
35
+
36
+ if $0 == __FILE__
37
+ if __FILE__ == $0
38
+ Rack::Handler::Mongrel.run SlowApp, :Port => 8070
39
+ end
40
+ end
41
+
42
+ describe Capybara::Session do
43
+ context 'with akephalos driver' do
44
+
45
+ before do
46
+ @session = Capybara::Session.new(:akephalos, SlowApp)
47
+ end
48
+
49
+ context "slow page load" do
50
+ it "should wait for the page to finish loading" do
51
+ @session.visit('/slow_page')
52
+ @session.current_url.should include('/slow_page')
53
+ end
54
+ end
55
+
56
+ context "slow ajax load" do
57
+ it "should wait for ajax to load" do
58
+ @session.visit('/slow_ajax_load')
59
+ @session.click_link('Click me')
60
+ @session.should have_xpath("//p[contains(.,'Loaded!')]")
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bernerd Schaefer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-03 00:00:00 -05:00
17
+ date: 2010-06-15 00:00:00 -05:00
18
18
  default_executable: akephalos
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -76,6 +76,7 @@ files:
76
76
  - lib/akephalos.rb
77
77
  - lib/akephalos/capybara.rb
78
78
  - lib/akephalos/client.rb
79
+ - lib/akephalos/console.rb
79
80
  - lib/akephalos/cucumber.rb
80
81
  - lib/akephalos/htmlunit.rb
81
82
  - lib/akephalos/node.rb
@@ -84,6 +85,7 @@ files:
84
85
  - lib/akephalos/server.rb
85
86
  - spec/driver/akephalos_driver_spec.rb
86
87
  - spec/session/akephalos_session_spec.rb
88
+ - spec/slow_page_loads_spec.rb
87
89
  - spec/spec.opts
88
90
  - spec/spec_helper.rb
89
91
  - src/commons-codec-1.4.jar
@@ -95,7 +97,7 @@ files:
95
97
  - src/cssparser-0.9.5.jar
96
98
  - src/htmlunit-2.6.jar
97
99
  - src/htmlunit-core-js-2.6.jar
98
- - src/jruby-complete-1.4.0.jar
100
+ - src/jruby-complete-1.5.0.jar
99
101
  - src/nekohtml-1.9.13.jar
100
102
  - src/sac-1.3.jar
101
103
  - src/serializer-2.7.1.jar
@@ -135,4 +137,5 @@ summary: ""
135
137
  test_files:
136
138
  - spec/driver/akephalos_driver_spec.rb
137
139
  - spec/session/akephalos_session_spec.rb
140
+ - spec/slow_page_loads_spec.rb
138
141
  - spec/spec_helper.rb