public
Description: Simple integration between selenium and rails.
Clone URL: git://github.com/techbelly/selenium_rails.git
Tidied up a little
techbelly (author)
Thu Jul 10 07:33:55 -0700 2008
commit  0efb5daf312865fd548ddf966ef4628361a23e34
tree    94f1fef62d6624ee34f6de64d07ee40279fae1fe
parent  172113161c67f0db0fe9c6f5bd7a1343b4f81dd0
...
4
5
6
7
 
8
9
10
...
4
5
6
 
7
8
9
10
0
@@ -4,7 +4,7 @@ module SeleniumRails
0
   class RailsApplication
0
     include WEBrick::HTMLUtils
0
     
0
- def self.standard
0
+ def self.default
0
      aut_options = {
0
      :port => 4001,
0
      :ip => "127.0.0.1",
...
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
...
55
56
57
 
58
59
60
61
62
 
63
64
 
65
66
67
0
@@ -55,16 +55,13 @@ module SeleniumRails
0
       command += "&session=#{session}" if session
0
       uri = URI.parse(command)
0
       begin
0
- puts "CALLING #{uri}"
0
         request = Net::HTTP::Get.new(uri.path+"?"+uri.query)
0
         res = Net::HTTP.start(uri.host,uri.port) { |http|
0
           http.read_timeout = 5
0
           http.request(request)
0
         }
0
- puts "SUCCESS #{res}"
0
         return true
0
       rescue
0
- puts "FAILED"
0
         return false
0
       end
0
     end
...
4
5
6
 
 
 
 
 
7
8
9
10
11
12
 
 
13
14
15
 
16
17
18
19
20
21
22
...
4
5
6
7
8
9
10
11
12
13
 
 
 
 
14
15
16
17
18
19
20
 
 
 
21
22
23
0
@@ -4,19 +4,20 @@ module SeleniumRails
0
 
0
   class Runner < Test::Unit::UI::Console::TestRunner
0
 
0
+ def self.selenium_session
0
+ # yuk, yuk, yuk
0
+ @@session
0
+ end
0
+
0
     def started(result)
0
       super(result)
0
- @seleniumRC = SeleniumRC.new
0
- @application = RailsApplication.standard
0
- @seleniumRC.start
0
- @application.start
0
+ @@session ||= SeleniumRails::Session.default.new
0
+ @@session.start
0
     end
0
   
0
     def finished(elapsed_time)
0
+ @@session.stop
0
       super(elapsed_time)
0
- @application.stop
0
- Test::Unit::TestCase.close_selenium_sessions
0
- @seleniumRC.stop
0
     end
0
   end
0
 
...
1
2
3
4
5
6
7
8
9
 
 
10
11
12
13
14
15
 
 
 
16
17
18
19
20
 
 
 
 
 
 
 
 
 
21
22
23
24
25
26
27
28
29
 
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
62
63
64
...
1
2
3
 
 
 
 
 
 
4
5
6
7
8
 
 
 
9
10
11
12
 
 
 
 
13
14
15
16
17
18
19
20
21
22
 
 
 
 
 
23
24
 
25
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
28
29
30
0
@@ -1,64 +1,30 @@
0
 module SeleniumRails
0
 module TestCase
0
   
0
- def self.included(base)
0
- base.extend(ClassMethods)
0
- end
0
-
0
- def selenium_session(session= nil)
0
- self.class.selenium_session(session)
0
+ def selenium_session
0
+ SeleniumRails::Runner.selenium_session
0
   end
0
   
0
    # Overrides standard "open" method with @selenium.open
0
- def open(addr)
0
- selenium_session.open(addr)
0
- end
0
+ def open(addr)
0
+ selenium_session.open(addr)
0
+ end
0
 
0
- # Overrides standard "type" method with @selenium.type
0
- def type(inputLocator, value)
0
- selenium_session.type(inputLocator, value)
0
- end
0
+ # Overrides standard "type" method with @selenium.type
0
+ def type(inputLocator, value)
0
+ selenium_session.type(inputLocator, value)
0
+ end
0
+
0
+ # Overrides standard "select" method with @selenium.select
0
+ def select(inputLocator, optionLocator)
0
+ selenium_session.select(inputLocator, optionLocator)
0
+ end
0
 
0
- # Overrides standard "select" method with @selenium.select
0
- def select(inputLocator, optionLocator)
0
- selenium_session.select(inputLocator, optionLocator)
0
- end
0
-
0
   def method_missing(method_name, *args)
0
     if args.empty?
0
- selenium_session.send(method_name)
0
+ selenium_session.send(method_name)
0
     else
0
- selenium_session.send(method_name, *args)
0
- end
0
- end
0
-
0
- module ClassMethods
0
- @@sessions = []
0
-
0
- def acceptance_test(name,&block)
0
- class_eval do
0
- define_method("test_"+name.underscore) do
0
- instance_eval &block
0
- end
0
- end
0
- end
0
-
0
- def new_selenium_session(session=nil)
0
- session ||= Selenium::SeleneseInterpreter.new("localhost", 4444, "*firefox", "http://localhost:4001", 10000);
0
- yield session if block_given?
0
- session.start
0
- @@sessions << session
0
- return session
0
- end
0
-
0
- def selenium_session(session = nil)
0
- @@sessions.last || new_selenium_session(session)
0
- end
0
-
0
- def close_selenium_sessions
0
- while (s = @@sessions.pop) do
0
- s.stop
0
- end
0
+ selenium_session.send(method_name, *args)
0
     end
0
   end
0
 end
...
1
2
3
4
5
6
7
8
...
1
2
 
 
 
3
4
5
0
@@ -1,8 +1,5 @@
0
 require 'rake/testtask'
0
 
0
-Rake.application.options.trace = true
0
-
0
-
0
 namespace :test do
0
   desc "Starts the java selenium proxy."
0
   task(:selenium_proxy) do

Comments

    No one has commented yet.