caius-culerity 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/culerity.gemspec +1 -1
- data/lib/culerity/remote_browser_proxy.rb +32 -1
- data/lib/culerity/remote_object_proxy.rb +6 -0
- data/spec/remote_browser_proxy_spec.rb +28 -0
- metadata +1 -1
data/VERSION.yml
CHANGED
data/culerity.gemspec
CHANGED
@@ -8,7 +8,38 @@ module Culerity
|
|
8
8
|
configure_browser browser_options
|
9
9
|
@remote_object_id = nil
|
10
10
|
end
|
11
|
-
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# Calls the block until it returns true or +time_to_wait+ is reached.
|
15
|
+
# +time_to_wait+ is 30 seconds by default
|
16
|
+
#
|
17
|
+
# Returns true upon success
|
18
|
+
# Raises Timeout::Error when +time_to_wait+ is reached.
|
19
|
+
#
|
20
|
+
def wait_until time_to_wait=30, &block
|
21
|
+
Timeout.timeout(time_to_wait) do
|
22
|
+
until block.call
|
23
|
+
sleep 0.1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Calls the block until it doesn't return true or +time_to_wait+ is reached.
|
31
|
+
# +time_to_wait+ is 30 seconds by default
|
32
|
+
#
|
33
|
+
# Returns true upon success
|
34
|
+
# Raises Timeout::Error when +time_to_wait+ is reached.
|
35
|
+
#
|
36
|
+
def wait_while time_to_wait=30, &block
|
37
|
+
Timeout.timeout(time_to_wait) do
|
38
|
+
while block.call
|
39
|
+
sleep 0.1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
true
|
12
43
|
end
|
13
44
|
|
14
45
|
private
|
@@ -13,8 +13,10 @@ module Culerity
|
|
13
13
|
@io = io
|
14
14
|
end
|
15
15
|
|
16
|
+
#
|
16
17
|
# Commonly used to get the HTML id attribute
|
17
18
|
# Use `object_id` to get the local objects' id.
|
19
|
+
#
|
18
20
|
def id
|
19
21
|
send_remote(:id)
|
20
22
|
end
|
@@ -23,6 +25,10 @@ module Culerity
|
|
23
25
|
send_remote(name, *args)
|
24
26
|
end
|
25
27
|
|
28
|
+
#
|
29
|
+
# Calls the passed method on the remote object with any arguments specified.
|
30
|
+
# Behaves the same as <code>Object#send</code>.
|
31
|
+
#
|
26
32
|
def send_remote(name, *args)
|
27
33
|
@io << "[#{remote_object_id}, \"#{name}\", #{args.map{|a| a.inspect}.join(', ')}]\n"
|
28
34
|
process_result @io.gets.to_s.strip
|
@@ -20,4 +20,32 @@ describe Culerity::RemoteBrowserProxy do
|
|
20
20
|
proxy = Culerity::RemoteBrowserProxy.new io, {:browser => :firefox}
|
21
21
|
end
|
22
22
|
|
23
|
+
it "should timeout if wait_until takes too long" do
|
24
|
+
io = stub 'io', :gets => "[:return, :okay]", :<< => nil
|
25
|
+
proxy = Culerity::RemoteBrowserProxy.new io
|
26
|
+
lambda {
|
27
|
+
proxy.wait_until(1) { false }
|
28
|
+
}.should raise_error(Timeout::Error)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return successfully when wait_until returns true" do
|
32
|
+
io = stub 'io', :gets => "[:return, :okay]", :<< => nil
|
33
|
+
proxy = Culerity::RemoteBrowserProxy.new io
|
34
|
+
proxy.wait_until(1) { true }.should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should timeout if wait_while takes too long" do
|
38
|
+
io = stub 'io', :gets => "[:return, :okay]", :<< => nil
|
39
|
+
proxy = Culerity::RemoteBrowserProxy.new io
|
40
|
+
lambda {
|
41
|
+
proxy.wait_while(1) { true }
|
42
|
+
}.should raise_error(Timeout::Error)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return successfully when wait_while returns !true" do
|
46
|
+
io = stub 'io', :gets => "[:return, :okay]", :<< => nil
|
47
|
+
proxy = Culerity::RemoteBrowserProxy.new io
|
48
|
+
proxy.wait_while(1) { false }.should == true
|
49
|
+
end
|
50
|
+
|
23
51
|
end
|