cohitre-caculo 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +1 -0
- data/README.txt +18 -13
- data/lib/caculo.rb +12 -2
- metadata +1 -1
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -5,29 +5,33 @@
|
|
5
5
|
|
6
6
|
== The Succinct Summary:
|
7
7
|
|
8
|
-
Caculo lets you simulate interaction with a browser via Ruby. It has the option to load a Javascript Library and call Javascript functions on the document. This allows for simple code that takes advantage of
|
8
|
+
Caculo lets you simulate interaction with a browser via Ruby. It has the option to load a Javascript Library and call Javascript functions on the document. This allows for simple code that takes advantage of existing libraries.
|
9
9
|
|
10
10
|
Caculo is inspired by the Watir/FireWatir/SafariWatir trio, However, by simplifying the way of communicating with the browser it tries to offer an integrated cross-browser solution. It also extends the Test/Unit framework to provide some abbreviations to common functions.
|
11
11
|
|
12
|
-
|
13
12
|
== The Polite Apology
|
14
13
|
|
15
14
|
I haven't really tested Caculo outside of my computer, so things may not work as expected out of the box.
|
16
15
|
|
17
16
|
== The Descriptive Example:
|
18
17
|
|
19
|
-
|
20
|
-
browser.libraries = [:jquery]
|
21
|
-
|
22
|
-
browser.visit( 'http://google.com' )
|
23
|
-
|
24
|
-
browser["input[@name='q']"].val! 'cohitre'
|
25
|
-
browser["form[@name='f']"].submit!
|
18
|
+
Here's a short example of how to use caculo to do a very fun google search.
|
26
19
|
|
27
|
-
|
28
|
-
|
20
|
+
require "rubygems"
|
21
|
+
require "caculo"
|
29
22
|
|
30
|
-
|
23
|
+
page = Caculo::Browser.open(:safari)
|
24
|
+
|
25
|
+
page.visit( "http://www.google.com" )
|
26
|
+
page.search("input[name=q]") { |obj| obj.val("cohitre") }
|
27
|
+
page.search("form[name=f]") { |form| form.submit }
|
28
|
+
|
29
|
+
sleep(1)
|
30
|
+
page.load_libraries!
|
31
|
+
sleep(1)
|
32
|
+
|
33
|
+
puts page.search("ol li:first a:first"){|f| f.text }
|
34
|
+
puts page.search("ol li:first a:first"){|f| f.attr("href") }
|
31
35
|
|
32
36
|
|
33
37
|
== The Required Requirements
|
@@ -43,7 +47,8 @@ $ sudo gem install rubyosa
|
|
43
47
|
|
44
48
|
== The Daunting Installation:
|
45
49
|
|
46
|
-
$ gem
|
50
|
+
$ gem sources -a http://gems.github.com
|
51
|
+
$ sudo gem install cohitre-caculo
|
47
52
|
|
48
53
|
|
49
54
|
== The Permissive License
|
data/lib/caculo.rb
CHANGED
@@ -50,9 +50,18 @@ module Caculo
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def load_libraries!
|
53
|
-
@libraries.each { |l| self
|
53
|
+
@libraries.each { |l| self << (l) }
|
54
54
|
end
|
55
55
|
|
56
|
+
def search string , &block
|
57
|
+
obj = JQueryObject.new( string )
|
58
|
+
obj = yield( obj ) if block_given?
|
59
|
+
sleep(0.1)
|
60
|
+
return self[obj]
|
61
|
+
end
|
62
|
+
|
63
|
+
alias / :search
|
64
|
+
|
56
65
|
def [] selector=nil
|
57
66
|
if selector.nil?
|
58
67
|
self << JQueryObject.new()
|
@@ -68,9 +77,10 @@ module Caculo
|
|
68
77
|
url = self << url
|
69
78
|
end
|
70
79
|
self << "window.document.location.href = #{url.to_js}"
|
71
|
-
|
80
|
+
sleep( 1.0 )
|
72
81
|
self.wait_until {|p| p.page_loaded? }
|
73
82
|
load_libraries!
|
83
|
+
sleep( 1.0 )
|
74
84
|
url
|
75
85
|
end
|
76
86
|
|